feat: initial commit
This commit is contained in:
commit
54139cb971
14
.eslintrc.cjs
Normal file
14
.eslintrc.cjs
Normal file
@ -0,0 +1,14 @@
|
||||
module.exports = {
|
||||
env: { browser: true, es2020: true },
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:react-hooks/recommended',
|
||||
],
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
|
||||
plugins: ['react-refresh'],
|
||||
rules: {
|
||||
'react-refresh/only-export-components': 'warn',
|
||||
},
|
||||
}
|
25
.gitignore
vendored
Normal file
25
.gitignore
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
.vercel
|
13
index.html
Normal file
13
index.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>The latest 1000 photography and art images on nostr | nostr-slideshow</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
5689
package-lock.json
generated
Normal file
5689
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
31
package.json
Normal file
31
package.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "nostr-slideshow",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc && vite build",
|
||||
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nostr-dev-kit/ndk": "^0.7.7",
|
||||
"@nostr-dev-kit/ndk-react": "^0.0.1",
|
||||
"nostr-tools": "^1.12.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.0.37",
|
||||
"@types/react-dom": "^18.0.11",
|
||||
"@typescript-eslint/eslint-plugin": "^5.59.0",
|
||||
"@typescript-eslint/parser": "^5.59.0",
|
||||
"@vitejs/plugin-react": "^4.0.0",
|
||||
"eslint": "^8.38.0",
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"eslint-plugin-react-refresh": "^0.3.4",
|
||||
"typescript": "^5.0.2",
|
||||
"vite": "^4.3.9"
|
||||
}
|
||||
}
|
1
public/vite.svg
Normal file
1
public/vite.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
After Width: | Height: | Size: 1.5 KiB |
63
src/App.css
Normal file
63
src/App.css
Normal file
@ -0,0 +1,63 @@
|
||||
#root {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
body {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
@keyframes showImage {
|
||||
from {
|
||||
scale: 1.2;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
10% {
|
||||
scale: 1.2;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
30% {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
to {
|
||||
scale: 1;
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.author-info a {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.author-info {
|
||||
position: absolute;
|
||||
bottom: 2em;
|
||||
left: 2em;
|
||||
z-index: 200;
|
||||
}
|
||||
|
||||
.author-info img {
|
||||
border-radius: 8px;
|
||||
margin-bottom: 0.5em;
|
||||
display: block;
|
||||
transition: opacity 1s ease-in-out;
|
||||
}
|
||||
|
||||
.slide {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
background-position: center;
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
overflow: hidden;
|
||||
scale: 1;
|
||||
opacity: 0;
|
||||
animation-duration: 12s;
|
||||
animation-timing-function: ease-in;
|
||||
animation-name: showImage;
|
||||
}
|
186
src/App.tsx
Normal file
186
src/App.tsx
Normal file
@ -0,0 +1,186 @@
|
||||
import { useNDK } from "@nostr-dev-kit/ndk-react";
|
||||
import "./App.css";
|
||||
import { nip19 } from "nostr-tools";
|
||||
import React, { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { NDKFilter, NDKUser } from "@nostr-dev-kit/ndk";
|
||||
import AuthorProfile from "./AuthorProfile";
|
||||
import IconFullScreen from "./IconFullScreen";
|
||||
|
||||
type NostrImage = {
|
||||
url: string;
|
||||
author: NDKUser;
|
||||
};
|
||||
|
||||
const parseUrl = () => {
|
||||
let npub: string | undefined = undefined;
|
||||
let tags: string | undefined = undefined;
|
||||
if (window.location.pathname.startsWith("/npub")) {
|
||||
npub = window.location.pathname.replace("/", "");
|
||||
}
|
||||
if (window.location.hash.startsWith("#")) {
|
||||
tags = window.location.hash.replace("#", "");
|
||||
}
|
||||
return { npub, tags };
|
||||
};
|
||||
|
||||
const buildFilter = () => {
|
||||
const filter: NDKFilter = {
|
||||
kinds: [1],
|
||||
limit: 1000,
|
||||
};
|
||||
|
||||
const { npub, tags } = parseUrl();
|
||||
|
||||
if (npub) {
|
||||
filter.authors = [nip19.decode(npub).data as string];
|
||||
} else {
|
||||
if (tags) {
|
||||
filter["#t"] = tags.split(",");
|
||||
} else {
|
||||
// Default tags
|
||||
filter["#t"] = [
|
||||
"photography",
|
||||
"photostr",
|
||||
"artstr",
|
||||
"art",
|
||||
"catstr",
|
||||
"dogstr",
|
||||
"nature",
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return filter;
|
||||
};
|
||||
|
||||
function extractImageUrls(text: string): string[] {
|
||||
const urlRegex = /(https?:\/\/[^\s]+)/g;
|
||||
return text.match(urlRegex) || [];
|
||||
}
|
||||
|
||||
const isReply = (event: any) => {
|
||||
// ["e", "aab5a68f29d76a04ad79fe7e489087b802ee0f946689d73b0e15931dd40a7af3", "", "reply"]
|
||||
return (
|
||||
event.tags.filter((t: string[]) => t[0] === "e" && t[3] === "reply")
|
||||
.length > 0
|
||||
);
|
||||
};
|
||||
|
||||
const App = () => {
|
||||
const { ndk, getProfile } = useNDK();
|
||||
const [posts, setPosts] = useState<any[]>([]);
|
||||
const images = useRef<NostrImage[]>([]);
|
||||
const [activeImages, setActiveImages] = useState<NostrImage[]>([]);
|
||||
const upcommingImage = useRef<NostrImage>();
|
||||
|
||||
useEffect(() => {
|
||||
const postSubscription = ndk.subscribe(buildFilter());
|
||||
|
||||
postSubscription.on("event", (event) => {
|
||||
setPosts((oldPosts) => {
|
||||
if (
|
||||
!isReply(event) &&
|
||||
oldPosts.findIndex((p) => p.id === event.id) === -1
|
||||
) {
|
||||
return [...oldPosts, event];
|
||||
}
|
||||
return oldPosts;
|
||||
});
|
||||
});
|
||||
}, []);
|
||||
|
||||
const animateImages = () => {
|
||||
setActiveImages((oldImages) => {
|
||||
const newImages = [...oldImages];
|
||||
if (newImages.length > 2) {
|
||||
// always keep 2 images
|
||||
newImages.shift();
|
||||
}
|
||||
if (images.current.length > 0) {
|
||||
const randomImage =
|
||||
images.current[Math.floor(Math.random() * images.current.length)];
|
||||
newImages.push(randomImage);
|
||||
upcommingImage.current = randomImage;
|
||||
}
|
||||
return newImages;
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
images.current = posts.flatMap((p) => {
|
||||
return extractImageUrls(p.content)
|
||||
.filter(
|
||||
(url) =>
|
||||
url.endsWith(".jpg") ||
|
||||
url.endsWith(".png") ||
|
||||
url.endsWith(".jpeg") ||
|
||||
url.endsWith(".webp")
|
||||
)
|
||||
.map((url) => ({ url, author: p.author }));
|
||||
});
|
||||
}, [posts]);
|
||||
|
||||
useEffect(() => {
|
||||
setTimeout(() => {
|
||||
// Make sure we have an image to start with but only trigger once
|
||||
if (upcommingImage.current === undefined) animateImages();
|
||||
}, 500);
|
||||
|
||||
const intervalHandle = setInterval(() => animateImages(), 7000);
|
||||
return () => {
|
||||
clearInterval(intervalHandle);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const fullScreen = useMemo(
|
||||
() =>
|
||||
screen.width == window.innerWidth && screen.height == window.innerHeight,
|
||||
[activeImages] // Hack to force update
|
||||
);
|
||||
|
||||
const activeNpub = upcommingImage?.current?.author?.npub;
|
||||
const activeProfile = activeNpub && getProfile(activeNpub);
|
||||
|
||||
return (
|
||||
<>
|
||||
{!fullScreen && (
|
||||
<div
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: "2em",
|
||||
right: "2em",
|
||||
zIndex: 200,
|
||||
}}
|
||||
>
|
||||
<button
|
||||
onClick={() =>
|
||||
document?.getElementById("root")?.requestFullscreen()
|
||||
}
|
||||
>
|
||||
<IconFullScreen />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeProfile && (
|
||||
<AuthorProfile
|
||||
src={activeProfile.image}
|
||||
author={activeProfile.displayName || activeProfile.name}
|
||||
npub={activeNpub}
|
||||
></AuthorProfile>
|
||||
)}
|
||||
|
||||
{activeImages.map((image) => (
|
||||
<div
|
||||
key={image.url}
|
||||
className="slide"
|
||||
style={{
|
||||
backgroundImage: `url(${image.url})`,
|
||||
}}
|
||||
></div>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default App;
|
36
src/AuthorProfile.tsx
Normal file
36
src/AuthorProfile.tsx
Normal file
@ -0,0 +1,36 @@
|
||||
import { useState } from "react";
|
||||
import "./App.css";
|
||||
|
||||
type AvatarImageProps = {
|
||||
src?: string;
|
||||
author?: string;
|
||||
npub?: string;
|
||||
};
|
||||
|
||||
const AuthorProfile = ({ src, author, npub }: AvatarImageProps) => {
|
||||
const [imageLoaded, setImageLoaded] = useState(false);
|
||||
|
||||
return (
|
||||
<div className="author-info">
|
||||
<a href={`https://nostrapp.link/#${npub}`} target="_blank">
|
||||
<div>
|
||||
{src && (
|
||||
<img
|
||||
style={{
|
||||
opacity: imageLoaded ? 1 : 0,
|
||||
}}
|
||||
onLoad={() => setImageLoaded(true)}
|
||||
src={src}
|
||||
alt={author}
|
||||
width={64}
|
||||
height={64}
|
||||
></img>
|
||||
)}
|
||||
{author}
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AuthorProfile;
|
14
src/IconFullScreen.tsx
Normal file
14
src/IconFullScreen.tsx
Normal file
@ -0,0 +1,14 @@
|
||||
const IconFullScreen = () => {
|
||||
return (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
height="1em"
|
||||
viewBox="0 0 448 512"
|
||||
fill="white"
|
||||
>
|
||||
<path d="M32 32C14.3 32 0 46.3 0 64v96c0 17.7 14.3 32 32 32s32-14.3 32-32V96h64c17.7 0 32-14.3 32-32s-14.3-32-32-32H32zM64 352c0-17.7-14.3-32-32-32s-32 14.3-32 32v96c0 17.7 14.3 32 32 32h96c17.7 0 32-14.3 32-32s-14.3-32-32-32H64V352zM320 32c-17.7 0-32 14.3-32 32s14.3 32 32 32h64v64c0 17.7 14.3 32 32 32s32-14.3 32-32V64c0-17.7-14.3-32-32-32H320zM448 352c0-17.7-14.3-32-32-32s-32 14.3-32 32v64H320c-17.7 0-32 14.3-32 32s14.3 32 32 32h96c17.7 0 32-14.3 32-32V352z" />
|
||||
</svg>
|
||||
);
|
||||
};
|
||||
|
||||
export default IconFullScreen;
|
69
src/index.css
Normal file
69
src/index.css
Normal file
@ -0,0 +1,69 @@
|
||||
:root {
|
||||
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: dark;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #111111;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
place-items: center;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3.2em;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
background-color: #1a1a1a;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.25s;
|
||||
}
|
||||
button:hover {
|
||||
border-color: #646cff;
|
||||
}
|
||||
button:focus,
|
||||
button:focus-visible {
|
||||
outline: 4px auto -webkit-focus-ring-color;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
color: #213547;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
a:hover {
|
||||
color: #747bff;
|
||||
}
|
||||
button {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
}
|
13
src/main.tsx
Normal file
13
src/main.tsx
Normal file
@ -0,0 +1,13 @@
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom/client";
|
||||
import { NDKProvider } from "@nostr-dev-kit/ndk-react";
|
||||
import App from "./App";
|
||||
import "./index.css";
|
||||
|
||||
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
|
||||
<React.StrictMode>
|
||||
<NDKProvider>
|
||||
<App />
|
||||
</NDKProvider>
|
||||
</React.StrictMode>
|
||||
);
|
1
src/vite-env.d.ts
vendored
Normal file
1
src/vite-env.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
23
tsconfig.json
Normal file
23
tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"incremental": true,
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
10
tsconfig.node.json
Normal file
10
tsconfig.node.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"skipLibCheck": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
8
vercel.json
Normal file
8
vercel.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"routes": [
|
||||
{
|
||||
"src": "/[^.]+",
|
||||
"dest": "/"
|
||||
}
|
||||
]
|
||||
}
|
7
vite.config.ts
Normal file
7
vite.config.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
})
|
Loading…
Reference in New Issue
Block a user