From be19adb4bc391acce4017f536885addb51e55017 Mon Sep 17 00:00:00 2001 From: Ou Date: Sat, 5 Oct 2024 21:34:17 +0800 Subject: [PATCH] refactor: router --- src/atoms.ts | 4 +- src/components/Header.tsx | 5 +- src/components/header.tsx | 49 ++++++++ src/components/section/Card.tsx | 4 +- src/components/section/Dnd.tsx | 13 +- src/components/section/Pure.tsx | 28 ----- src/components/section/card.tsx | 199 +++++++++++++++++++++++++++++++ src/components/section/dnd.tsx | 92 ++++++++++++++ src/components/section/index.tsx | 55 +++++++++ src/routeTree.gen.ts | 42 +++---- src/routes/__root.tsx | 12 +- src/routes/index.tsx | 56 ++------- src/routes/s.$section.tsx | 28 +++++ src/routes/setting.tsx | 13 -- 14 files changed, 470 insertions(+), 130 deletions(-) create mode 100644 src/components/header.tsx delete mode 100644 src/components/section/Pure.tsx create mode 100644 src/components/section/card.tsx create mode 100644 src/components/section/dnd.tsx create mode 100644 src/components/section/index.tsx create mode 100644 src/routes/s.$section.tsx delete mode 100644 src/routes/setting.tsx diff --git a/src/atoms.ts b/src/atoms.ts index b1e5767..c0c7185 100644 --- a/src/atoms.ts +++ b/src/atoms.ts @@ -7,7 +7,7 @@ export const focusSourcesAtom = atomWithLocalStorage("focusSources", return stored.filter(item => item in sources) }) -function initRefetchSource() { +function initRefetchSources() { let time = 0 // useOnReload // 没有放在 useOnReload 里面, 可以避免初始化后再修改 refetchSourceAtom,导致多次请求 API @@ -20,7 +20,7 @@ function initRefetchSource() { return Object.fromEntries(Object.keys(sources).map(k => [k, time])) as Record } -export const refetchSourceAtom = atom(initRefetchSource()) +export const refetchSourcesAtom = atom(initRefetchSources()) export const currentSectionIDAtom = atom("focus") diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 6d64242..68dbc0b 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -3,7 +3,7 @@ import { useCallback } from "react" import { useAtomValue, useSetAtom } from "jotai" import logo from "~/assets/react.svg" import { useDark } from "~/hooks/useDark" -import { currentSectionAtom, refetchSourceAtom } from "~/atoms" +import { currentSectionAtom, refetchSourcesAtom } from "~/atoms" function ThemeToggle() { const { toggleDark } = useDark() @@ -19,7 +19,7 @@ function ThemeToggle() { function RefreshButton() { const currentSection = useAtomValue(currentSectionAtom) - const setRefetchSource = useSetAtom(refetchSourceAtom) + const setRefetchSource = useSetAtom(refetchSourcesAtom) const refreshAll = useCallback(() => { const obj = Object.fromEntries(currentSection.sourceList.map(id => [id, Date.now()])) setRefetchSource(prev => ({ @@ -43,7 +43,6 @@ export function Header() {
-
) diff --git a/src/components/header.tsx b/src/components/header.tsx new file mode 100644 index 0000000..68dbc0b --- /dev/null +++ b/src/components/header.tsx @@ -0,0 +1,49 @@ +import { Link } from "@tanstack/react-router" +import { useCallback } from "react" +import { useAtomValue, useSetAtom } from "jotai" +import logo from "~/assets/react.svg" +import { useDark } from "~/hooks/useDark" +import { currentSectionAtom, refetchSourcesAtom } from "~/atoms" + +function ThemeToggle() { + const { toggleDark } = useDark() + return ( +