From 02a33e00b32e4754a75b585373973a65eccb3447 Mon Sep 17 00:00:00 2001 From: nyne Date: Sat, 4 Oct 2025 09:28:30 +0800 Subject: [PATCH] Fix home page --- frontend/src/pages/home_page.tsx | 33 +++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/frontend/src/pages/home_page.tsx b/frontend/src/pages/home_page.tsx index 93e0e04..8c54c0e 100644 --- a/frontend/src/pages/home_page.tsx +++ b/frontend/src/pages/home_page.tsx @@ -67,18 +67,25 @@ export default function HomePage() { ); } -let cachedPinnedResources: Resource[] | null = null; - function HomeHeader() { const [pinnedResources, setPinnedResources] = useState([]); const [statistic, setStatistic] = useState(null); const navigator = useNavigator(); + const appContext = useAppContext(); useEffect(() => { - if (cachedPinnedResources != null) { - setPinnedResources(cachedPinnedResources); + const pinned = appContext.get("pinned_resources"); + const stats = appContext.get("site_statistics"); + if (pinned) { + setPinnedResources(pinned); + } + if (stats) { + setStatistic(stats); + } + if (pinned && stats) { return; } + const prefetchData = app.getPreFetchData(); if (prefetchData && prefetchData.background) { navigator.setBackground( @@ -89,32 +96,36 @@ function HomeHeader() { let ok2 = false; if (prefetchData && prefetchData.statistics) { setStatistic(prefetchData.statistics); + appContext.set("site_statistics", prefetchData.statistics); ok1 = true; } if (prefetchData && prefetchData.pinned) { - cachedPinnedResources = prefetchData.pinned; - setPinnedResources(cachedPinnedResources!); + const r = prefetchData.pinned; + appContext.set("pinned_resources", r); + setPinnedResources(r!); ok2 = true; } if (ok1 && ok2) { return; } + const fetchPinnedResources = async () => { const res = await network.getPinnedResources(); if (res.success) { - cachedPinnedResources = res.data ?? []; + appContext.set("pinned_resources", res.data); setPinnedResources(res.data ?? []); } }; const fetchStatistics = async () => { const res = await network.getStatistic(); if (res.success) { + appContext.set("site_statistics", res.data); setStatistic(res.data!); } }; fetchPinnedResources(); fetchStatistics(); - }, [navigator]); + }, [appContext, navigator]); if (pinnedResources.length == 0 || statistic == null) { return <>; @@ -123,8 +134,8 @@ function HomeHeader() { return (
-
-
+
+

{app.appName}

{app.siteDescription}

@@ -156,7 +167,7 @@ function PinnedResourceItem({ resource }: { resource: Resource }) { cover )}