From e25b69f6ea2be2c71cb3b41d85331b5adb1ff29d Mon Sep 17 00:00:00 2001 From: Gerard Clos Date: Tue, 30 Jul 2024 14:19:56 +0200 Subject: [PATCH] quickfix: flickering when toggling between projects and settings (and removed some unnecessary data fetches) --- apps/web/src/app/(private)/page.tsx | 10 +++------- .../[projectId]/versions/[commitUuid]/layout.tsx | 8 ++++++++ apps/web/src/app/(private)/settings/layout.tsx | 9 +++++++++ apps/web/src/components/layouts/AppLayout/index.tsx | 6 +----- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/apps/web/src/app/(private)/page.tsx b/apps/web/src/app/(private)/page.tsx index 82b2a42ac..35c7983a5 100644 --- a/apps/web/src/app/(private)/page.tsx +++ b/apps/web/src/app/(private)/page.tsx @@ -1,5 +1,5 @@ -import { HEAD_COMMIT, NotFoundError, Project } from '@latitude-data/core' -import { findCommit, getFirstProject } from '$/app/(private)/_data-access' +import { NotFoundError, Project } from '@latitude-data/core' +import { getFirstProject } from '$/app/(private)/_data-access' import { getCurrentUser, SessionData } from '$/services/auth/getCurrentUser' import { ROUTES } from '$/services/routes' import { notFound, redirect } from 'next/navigation' @@ -17,13 +17,9 @@ export default async function AppRoot() { session = await getCurrentUser() project = await getFirstProject({ workspaceId: session.workspace.id }) - await findCommit({ uuid: HEAD_COMMIT, project }) - url = PROJECT_ROUTE({ id: project.id }).commits.latest } catch (error) { - if (error instanceof NotFoundError) { - return notFound() - } + if (error instanceof NotFoundError) return notFound() throw error } diff --git a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/layout.tsx b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/layout.tsx index c63ff7a2e..cab5681b9 100644 --- a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/layout.tsx +++ b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/layout.tsx @@ -14,6 +14,7 @@ import { NAV_LINKS } from '$/app/(private)/_lib/constants' import { ProjectPageParams } from '$/app/(private)/projects/[projectId]/page' import { AppLayout } from '$/components/layouts' import { getCurrentUser, SessionData } from '$/services/auth/getCurrentUser' +import { ROUTES } from '$/services/routes' import { notFound } from 'next/navigation' export type CommitPageParams = { @@ -45,6 +46,12 @@ export default async function CommitLayout({ throw error } + const url = ROUTES.projects.detail({ id: project.id }).commits.latest + const sectionLinks = [ + { label: 'Projects', href: url }, + { label: 'Settings', href: ROUTES.settings.root }, + ] + return ( @@ -64,6 +71,7 @@ export default async function CommitLayout({ ), }, ]} + sectionLinks={sectionLinks} > {children} diff --git a/apps/web/src/app/(private)/settings/layout.tsx b/apps/web/src/app/(private)/settings/layout.tsx index a42991c7c..f81e946fb 100644 --- a/apps/web/src/app/(private)/settings/layout.tsx +++ b/apps/web/src/app/(private)/settings/layout.tsx @@ -2,16 +2,25 @@ import { ReactNode } from 'react' import { AppLayout } from '$/components/layouts' import { getCurrentUser } from '$/services/auth/getCurrentUser' +import { ROUTES } from '$/services/routes' +import { getFirstProject } from '../_data-access' import { NAV_LINKS } from '../_lib/constants' export default async function Layout({ children }: { children: ReactNode }) { const session = await getCurrentUser() + const project = await getFirstProject({ workspaceId: session.workspace.id }) + const url = ROUTES.projects.detail({ id: project.id }).commits.latest + const sectionLinks = [ + { label: 'Projects', href: url }, + { label: 'Settings', href: ROUTES.settings.root }, + ] return ( {children} diff --git a/apps/web/src/components/layouts/AppLayout/index.tsx b/apps/web/src/components/layouts/AppLayout/index.tsx index 8808c88bc..1ecabdc09 100644 --- a/apps/web/src/components/layouts/AppLayout/index.tsx +++ b/apps/web/src/components/layouts/AppLayout/index.tsx @@ -1,6 +1,5 @@ import { ReactNode } from 'react' -import { ROUTES } from '$/services/routes' import { SessionUser } from '$ui/providers' import AppHeader, { AppHeaderProps } from './Header' @@ -15,10 +14,7 @@ export default function AppLayout({ currentUser, breadcrumbs, navigationLinks, - sectionLinks = [ - { label: 'Projects', href: ROUTES.projects.root }, - { label: 'Settings', href: ROUTES.settings.root }, - ], + sectionLinks, }: AppLayoutProps) { return (