From 03bf7b2a6784a6ad2c1ebc84509c40612217e1c9 Mon Sep 17 00:00:00 2001 From: "ar.azizan" Date: Thu, 5 Feb 2026 20:59:38 +0330 Subject: [PATCH] feat: enhance blog post layout and add scroll progress indicator - Adjusted padding for the blog post thumbnail section. - Introduced a custom hook for tracking scroll progress. - Added horizontal scroll progress indicators for both desktop and mobile views in the blog table of contents. --- app/blog/[slug]/page.tsx | 4 +-- components/blog-toc.tsx | 61 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/app/blog/[slug]/page.tsx b/app/blog/[slug]/page.tsx index 25395fe..7e937b5 100644 --- a/app/blog/[slug]/page.tsx +++ b/app/blog/[slug]/page.tsx @@ -68,8 +68,8 @@ export default async function BlogPostPage({ params }: BlogPostPageProps) { <> {/* تصویر شاخص تمام‌عرض بالای صفحه */} {thumbnailUrl && ( -
-
+
+
{altText} { + const { scrollY } = window; + const docHeight = document.documentElement.scrollHeight - window.innerHeight; + if (docHeight <= 0) { + setProgress(0); + return; + } + const value = Math.min(100, Math.max(0, (scrollY / docHeight) * 100)); + setProgress(value); + }, []); + + useEffect(() => { + update(); + window.addEventListener("scroll", update, { passive: true }); + window.addEventListener("resize", update); + return () => { + window.removeEventListener("scroll", update); + window.removeEventListener("resize", update); + }; + }, [update]); + + return progress; +} + interface TocGroup { heading: TocItem; children: TocItem[]; @@ -54,6 +81,7 @@ export function BlogToc({ items, className }: BlogTocProps) { const [activeId, setActiveId] = useState(items[0]?.id ?? null); const [mobileOpen, setMobileOpen] = useState(false); const [openSections, setOpenSections] = useState>(() => new Set()); + const scrollProgress = useScrollProgress(); const groups = useMemo(() => groupByLevel2(items), [items]); @@ -172,15 +200,25 @@ export function BlogToc({ items, className }: BlogTocProps) { return ( <> - {/* Desktop: sticky sidebar left */} + {/* Desktop: sticky sidebar with scroll progress bar */} - {/* Mobile: collapsible, sticky when scrolling */} + {/* Mobile: collapsible with horizontal scroll progress bar */} + + {/* Horizontal scroll progress indicator (mobile) */} +
+
+
فهرست مطالب