diff --git a/src/components/sections/ToolGridSection.tsx b/src/components/sections/ToolGridSection.tsx index 0c1cf8b..f0e5a75 100644 --- a/src/components/sections/ToolGridSection.tsx +++ b/src/components/sections/ToolGridSection.tsx @@ -486,13 +486,34 @@ export function ToolGridSection({ return () => window.removeEventListener('hashchange', syncFromHash); }, [categorizedTools]); - // Handle Category Selection with URL Hash reflection + const isMountedRef = useRef(false); + + // Smoothly scroll window to top whenever active category or workspace changes + useEffect(() => { + if (!isMountedRef.current) { + isMountedRef.current = true; + return; + } + if (typeof window !== 'undefined') { + window.scrollTo({ top: 0, behavior: 'smooth' }); + const rafId = requestAnimationFrame(() => { + window.scrollTo({ top: 0, behavior: 'smooth' }); + }); + return () => cancelAnimationFrame(rafId); + } + }, [selectedCategory]); + + // Handle Category Selection with URL Hash reflection and guaranteed scroll to top const handleSelectCategory = (catId: string) => { setSelectedCategory(catId); if (searchQuery) setSearchQuery(''); if (typeof window !== 'undefined') { const newHash = catId === 'all' ? '' : `#category-${catId}`; window.history.replaceState(null, '', newHash || window.location.pathname); + window.scrollTo({ top: 0, behavior: 'smooth' }); + requestAnimationFrame(() => { + window.scrollTo({ top: 0, behavior: 'smooth' }); + }); } };