Skip to content

Commit

Permalink
quickfix: flickering when toggling between projects and settings (and…
Browse files Browse the repository at this point in the history
… removed some unnecessary data fetches)
  • Loading branch information
geclos committed Jul 30, 2024
1 parent 7ac146b commit e25b69f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
10 changes: 3 additions & 7 deletions apps/web/src/app/(private)/page.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 (
<ProjectProvider project={project}>
<CommitProvider commit={commit} isHead={isHead}>
Expand All @@ -64,6 +71,7 @@ export default async function CommitLayout({
),
},
]}
sectionLinks={sectionLinks}
>
{children}
</AppLayout>
Expand Down
9 changes: 9 additions & 0 deletions apps/web/src/app/(private)/settings/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<AppLayout
navigationLinks={NAV_LINKS}
currentUser={session.user}
breadcrumbs={[{ name: session.workspace.name }, { name: 'Settings' }]}
sectionLinks={sectionLinks}
>
{children}
</AppLayout>
Expand Down
6 changes: 1 addition & 5 deletions apps/web/src/components/layouts/AppLayout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ReactNode } from 'react'

import { ROUTES } from '$/services/routes'
import { SessionUser } from '$ui/providers'

import AppHeader, { AppHeaderProps } from './Header'
Expand All @@ -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 (
<div className='flex flex-col h-screen'>
Expand Down

0 comments on commit e25b69f

Please sign in to comment.