From 0aa0cc72a7bca9441ae0e1cea920d07fefaa5c61 Mon Sep 17 00:00:00 2001 From: tymur999 Date: Mon, 13 Apr 2026 01:26:21 -0500 Subject: [PATCH] articles canvas mode --- src/articles/ArticleContext.tsx | 44 ---------------------- src/articles/ArticlesList.tsx | 65 ++++++++++++++++++++++++++------- src/articles/Reader.tsx | 7 ++-- src/articles/list.sass | 6 +++ src/articles/reader.sass | 3 +- src/index.tsx | 7 +--- src/index/Canvas.tsx | 2 +- 7 files changed, 65 insertions(+), 69 deletions(-) delete mode 100644 src/articles/ArticleContext.tsx diff --git a/src/articles/ArticleContext.tsx b/src/articles/ArticleContext.tsx deleted file mode 100644 index b3e6ec7..0000000 --- a/src/articles/ArticleContext.tsx +++ /dev/null @@ -1,44 +0,0 @@ -import {createContext, PropsWithChildren, useContext, useEffect, useState} from "react"; -import {Reader} from "./Reader"; -import {Article, ARTICLES} from "./articles"; -import {useRouter} from "../router/RouterContext"; -import {Path} from "../router/router"; - -const articleContext = - createContext>>([undefined, function(){}]); - -export function useArticle() { - return useContext(articleContext); -} - -const ARTICLE_QUERY = "a"; -export default function ArticleProvider({ children }: PropsWithChildren) { - const [article, setArticle] = useState
(undefined); - const router = useRouter(); - - useEffect(() => { - const params = new URLSearchParams(location.search); - if(params.has(ARTICLE_QUERY)) { - const id = Number.parseInt(params.get(ARTICLE_QUERY)!); - setArticle(ARTICLES[id]); - } - }, [setArticle]); - - useEffect(() => { - if(!article) { - // query param - const params = new URLSearchParams(location.search); - if(params.has(ARTICLE_QUERY)) { - router.replacePage(location.pathname as Path); - } - } else { - const id = ARTICLES.indexOf(article); - router.replacePage(`${location.pathname}?${ARTICLE_QUERY}=${id}` as Path); - } - }, [article]); - - return - - {children} - ; -} \ No newline at end of file diff --git a/src/articles/ArticlesList.tsx b/src/articles/ArticlesList.tsx index 3698d1a..d4a1136 100644 --- a/src/articles/ArticlesList.tsx +++ b/src/articles/ArticlesList.tsx @@ -1,28 +1,67 @@ -import {useArticle} from "./ArticleContext"; import "./list.sass"; import {ReactComponent as BoxSvg} from "../img/blog-box.svg"; import {Article, ARTICLES} from "./articles"; import {motion} from "motion/react"; import {AnimateFade} from "../animations"; +import {Canvas} from "@react-three/fiber"; +import {Environment, Html, OrbitControls} from "@react-three/drei"; +import MilkyWay from "../img/2k_stars_milky_way.jpg"; +import {Sun} from "../index/Canvas"; +import {Bloom, EffectComposer, Vignette} from "@react-three/postprocessing"; +import {useEffect, useState} from "react"; +import {Reader} from "./Reader"; +import {useRouter} from "../router/RouterContext"; +import {Path} from "../router/router"; +const ARTICLE_QUERY = "a"; const main = AnimateFade(); export default function ArticlesList() { - return -
-
- { - ARTICLES.map(a => - - ) + const [article, setArticle] = useState
(null); + const router = useRouter(); + + useEffect(() => { + const params = new URLSearchParams(location.search); + if(params.has(ARTICLE_QUERY)) { + const id = Number.parseInt(params.get(ARTICLE_QUERY)!); + setArticle(ARTICLES[id] ?? null); + } + }, [setArticle]); + + useEffect(() => { + if(!article) { + // query param + const params = new URLSearchParams(location.search); + if(params.has(ARTICLE_QUERY)) { + router.replacePage(location.pathname as Path); } -
-
+ } else { + const id = ARTICLES.indexOf(article); + router.replacePage(`${location.pathname}?${ARTICLE_QUERY}=${id}` as Path); + } + }, [article]); + + + return + + + + + + + + + + { + ARTICLES.map(a => ) + } + + + } -function BlogBox(props: { article: Article }) { - const {article, article: {name, description, thumbnail, published} } = props; - const [, setReading] = useArticle(); +function BlogBox(props: { article: Article, setReading: (_: Article | null) => void }) { + const {article, setReading, article: {name, description, thumbnail, published} } = props; return (