From e0240f6217db7e3e7f2479411c4e0c8899c4c755 Mon Sep 17 00:00:00 2001 From: TerryM Date: Thu, 28 May 2026 16:07:08 +0800 Subject: [PATCH] feat: refine home section navigation --- src/App.tsx | 6 +++-- src/layouts/PublicLayout.tsx | 3 +-- src/pages/Home/index.tsx | 45 +++++++++++++++++--------------- src/pages/PostRedirect/index.tsx | 9 +++---- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 6d2ad9f..8b975b3 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,7 +3,6 @@ import { I18nProvider } from "./i18n"; import { PublicLayout } from "./layouts/PublicLayout"; import { Home } from "./pages/Home"; import { Browse } from "./pages/Browse"; -import { CategoryPage } from "./pages/Category"; import { SearchPage } from "./pages/Search"; import { PostRedirect } from "./pages/PostRedirect"; import { AboutPage } from "./pages/About"; @@ -27,7 +26,10 @@ export default function App() { }> } /> } /> - } /> + } + /> } /> } /> } /> diff --git a/src/layouts/PublicLayout.tsx b/src/layouts/PublicLayout.tsx index 6d81847..0d1e75c 100644 --- a/src/layouts/PublicLayout.tsx +++ b/src/layouts/PublicLayout.tsx @@ -267,8 +267,7 @@ export function PublicLayout() { const na = (which: PublicNavWhich) => navIsActive(pathname, search, hash, which); const isHome = pathname === "/"; - const footerInContentFlow = - pathname === "/browse" || pathname.startsWith("/category/"); + const footerInContentFlow = pathname === "/browse"; const goSearch = () => { const s = q.trim(); diff --git a/src/pages/Home/index.tsx b/src/pages/Home/index.tsx index 6e2b99d..bd2a9e4 100644 --- a/src/pages/Home/index.tsx +++ b/src/pages/Home/index.tsx @@ -1,5 +1,5 @@ import { ChevronRight } from "lucide-react"; -import { Link, useLocation } from "react-router-dom"; +import { useLocation } from "react-router-dom"; import { useEffect, useRef, useState } from "react"; import { getJSON, itemsOrEmpty, type Category } from "../../api"; import { CategoryIcon } from "../../components/CategoryIcon"; @@ -170,18 +170,23 @@ export function Home() { const id = hash.slice(1); if (!id) return; const frame = window.requestAnimationFrame(() => { - document.getElementById(id)?.scrollIntoView({ block: "start" }); + document.getElementById(id)?.scrollIntoView({ + block: id === "latest" ? "center" : "start", + }); }); return () => window.cancelAnimationFrame(frame); }, [hash, cats.length, rec.length, latest.length, popular.length]); const latestPlaceholderCount = Math.max(0, 5 - latest.length); const popularPlaceholderCount = Math.max(0, 5 - popular.length); - const recommendedDotCount = Math.max(1, Math.min(4, rec.length || 4)); - const activeRecommendedDot = Math.min( - recommendedDotCount - 1, - Math.round(recScroll.progress * (recommendedDotCount - 1)), - ); + const recommendedDotCount = rec.length; + const activeRecommendedDot = + recommendedDotCount > 0 + ? Math.min( + recommendedDotCount - 1, + Math.round(recScroll.progress * (recommendedDotCount - 1)), + ) + : 0; if (err) { return ( @@ -197,7 +202,7 @@ export function Home() { -
+
{page.map((c) => ( - {cleanCategoryDisplayName(c.name)}
- + ))} ))} @@ -271,10 +275,9 @@ export function Home() {
{figmaOrderedCategories.map((c) => ( - {cleanCategoryDisplayName(c.name)}
- + ))}
-
+
{rec.map((r, index) => ( -
+
))} @@ -354,7 +357,7 @@ export function Home() {
-
+
-