Connect, collaborate, and grow with a community of TypeScript developers
Adding prefetching for the tabs in profile section (#910)
Amanuel Odicho710b2112637e
diff --git a/apps/web/src/app/[locale]/[username]/_components/dashboard/index.tsx b/apps/web/src/app/[locale]/[username]/_components/dashboard/index.tsxindex cbe4bdf7..60c4c867 100644--- a/apps/web/src/app/[locale]/[username]/_components/dashboard/index.tsx+++ b/apps/web/src/app/[locale]/[username]/_components/dashboard/index.tsx@@ -15,7 +15,7 @@ import { getRelativeTime } from '~/utils/relativeTime';import { stripProtocolAndWWW } from '~/utils/stringUtils';import UserHeader from './user-header';-import { useMemo } from 'react';+import { useEffect, useMemo } from 'react';import { usePathname, useRouter } from 'next/navigation';interface Props {@@ -31,6 +31,16 @@ type Tab = 'bookmarks' | 'in-progress' | 'overview' | 'shared-solutions';export function Dashboard({ user, isOwnProfile, children }: Props) {const router = useRouter();+ const tabs = useMemo(+ () => [+ { name: 'overview', route: `/@${user.name}` },+ { name: 'in-progress', route: `/@${user.name}/in-progress` },+ { name: 'shared-solutions', route: `/@${user.name}/shared-solutions` },+ { name: 'bookmarks', route: `/@${user.name}/bookmarks` },+ ],+ [user.name],+ );+const filteredProfileLinks =user.userLinks.length > 0 ? user.userLinks.filter((item) => item.url !== '') : [];@@ -53,6 +63,15 @@ export function Dashboard({ user, isOwnProfile, children }: Props) {return 'overview';}, [pathname]);+ useEffect(() => {+ // prefetch every route except for the one we're currently in+ tabs.forEach((tab) => {+ if (selectedTab !== tab.name) {+ router.prefetch(tab.route);+ }+ });+ }, [router, selectedTab, tabs]);+return (<div className="container">{/* // TODO: GFI: make each page a subroute, put settings & profile into same layout */}