Skip to content

Commit

Permalink
Create first project when setup is done + app layout header
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgutgon committed Jul 18, 2024
1 parent 393a84f commit b510b7c
Show file tree
Hide file tree
Showing 64 changed files with 1,426 additions and 241 deletions.
2 changes: 1 addition & 1 deletion apps/web/src/actions/procedures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createServerActionProcedure } from 'zsa'
* Docs: https://zsa.vercel.app/docs/procedures
*/
export const authProcedure = createServerActionProcedure().handler(async () => {
const data = (await getCurrentUser()).unwrap()
const data = await getCurrentUser()
return { session: data.session!, workspace: data.workspace, user: data.user }
})

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use client'

import { useCallback } from 'react'

import { HEAD_COMMIT } from '@latitude-data/core/browser'
import { Badge, Icons, Text, Tooltip } from '@latitude-data/web-ui'

export default function BreadcrumpCommit({
uuid: fullUuid,
title,
isLatest,
}: {
uuid: string
title?: string | null
isLatest: boolean
}) {
const [uuid] = isLatest ? [HEAD_COMMIT] : fullUuid.split('-')
const onCopy = useCallback(() => {
navigator.clipboard.writeText(fullUuid)
}, [fullUuid])
return (
<div className='flex flex-row items-center space-x-2'>
<Text.H5M>{title ?? 'Untitled'}</Text.H5M>
<Tooltip
side='right'
align='center'
trigger={
<div
onClick={onCopy}
className='cursor-pointer flex flex-row items-center gap-x-1'
>
<Badge variant={isLatest ? 'accent' : 'secondary'}>{uuid}</Badge>
<Icons.clipboard className='w-4 h-4 text-muted-foreground' />
</div>
}
>
<Text.H6 color='white'>Click to copy: {fullUuid}</Text.H6>
</Tooltip>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use client'

import { useEffect } from 'react'

export default function ClientPushNavigation({
url,
}: {
url: string | undefined
}) {
useEffect(() => {
if (!url) return

window.history.replaceState(
{ ...window.history.state, as: url, url },
'',
url,
)
}, [url])

return null
}
46 changes: 46 additions & 0 deletions apps/web/src/app/(private)/_components/CommitDetailPage/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { type Commit, type Project } from '@latitude-data/core'
import { CommitDetail } from '@latitude-data/web-ui'
import BreadcrumpCommit from '$/app/(private)/_components/CommitDetailPage/BreadcrumpBadge'
import ClientPushNavigation from '$/app/(private)/_components/CommitDetailPage/ClientPushNavigation'
import { NAV_LINKS } from '$/app/(private)/_lib/constants'
import { SessionData } from '$/services/auth/getCurrentUser'

type Props = {
session: SessionData
project: Project
commit: Commit
isLatest?: boolean
url?: string
}
export default function CommitDetailPage({
session,
project,
commit,
url,
isLatest = true,
}: Props) {
return (
<>
<ClientPushNavigation url={url} />
<CommitDetail
appLayout={{
navigationLinks: NAV_LINKS,
currentUser: session.user,
breadcrumbs: [
{ name: session.workspace.name },
{ name: project.name },
{
name: (
<BreadcrumpCommit
uuid={commit.uuid}
title={commit.title}
isLatest={isLatest}
/>
),
},
],
}}
/>
</>
)
}
36 changes: 36 additions & 0 deletions apps/web/src/app/(private)/_data-access/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { cache } from 'react'

import {
findCommit as originalfindCommit,
findProject as originalFindProject,
getFirstProject as originalGetFirstProject,
type FindCommitProps,
type FindProjectProps,
} from '@latitude-data/core'

export const getFirstProject = cache(
async ({ workspaceId }: { workspaceId: number }) => {
const result = await originalGetFirstProject({ workspaceId })
const project = result.unwrap()

return project
},
)

export const findProject = cache(
async ({ projectId, workspaceId }: FindProjectProps) => {
const result = await originalFindProject({ projectId, workspaceId })
const project = result.unwrap()

return project
},
)

export const findCommit = cache(
async ({ isLatest, uuid, projectId }: FindCommitProps) => {
const result = await originalfindCommit({ isLatest, uuid, projectId })
const commit = result.unwrap()

return commit
},
)
12 changes: 12 additions & 0 deletions apps/web/src/app/(private)/_lib/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {
LATITUDE_CHANGELOG_URL,
LATITUDE_DOCS_URL,
LATITUDE_HELP_URL,
} from '@latitude-data/core/browser'

export const NAV_LINKS = [
{ label: 'Feedback', href: '' },
{ label: 'Docs', href: LATITUDE_DOCS_URL },
{ label: 'Help', href: LATITUDE_HELP_URL },
{ label: 'Changelog', href: LATITUDE_CHANGELOG_URL },
]
34 changes: 34 additions & 0 deletions apps/web/src/app/(private)/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use client'

import { useEffect } from 'react'

import {
AppLayout,
ErrorComponent,
useSession,
} from '@latitude-data/web-ui/browser'
import { NAV_LINKS } from '$/app/(private)/_lib/constants'

export default function Error({
error,
}: {
error: Error & { digest?: string }
reset: () => void // Re-render of page
}) {
const session = useSession()
useEffect(() => {
console.error(error)
}, [error])
return (
<AppLayout
currentUser={session.currentUser}
breadcrumbs={[{ name: session.workspace.name }, { name: 'Error' }]}
navigationLinks={NAV_LINKS}
>
<ErrorComponent
type='red'
message='Something went wrong. Please, try again and if the error persists contact us.'
/>
</AppLayout>
)
}
24 changes: 7 additions & 17 deletions apps/web/src/app/(private)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
import { ReactNode } from 'react'

import Sidebar from '$/components/Sidebar'
import { getSession } from '$/services/auth/getSession'
import { ROUTES } from '$/services/routes'
import { redirect } from 'next/navigation'
import { SessionProvider } from '@latitude-data/web-ui/browser'
import { getCurrentUser } from '$/services/auth/getCurrentUser'

export default async function PrivateLayout({
children,
}: {
children: ReactNode
}) {
const data = await getSession()
if (!data.session) {
return redirect(ROUTES.auth.login)
}
}: Readonly<{ children: ReactNode }>) {
const session = await getCurrentUser()
return (
<main className='flex flex-row w-full'>
<div className='w-[280px]'>
<Sidebar />
</div>
<div className='flex-1'>{children}</div>
</main>
<SessionProvider currentUser={session.user} workspace={session.workspace}>
{children}
</SessionProvider>
)
}
47 changes: 32 additions & 15 deletions apps/web/src/app/(private)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
import { FocusHeader, FocusLayout } from '@latitude-data/web-ui'
import DummyLogoutButton from '$/app/(private)/_components/DummyLogoutButton'
import { Commit, NotFoundError, Project } from '@latitude-data/core'
import CommitDetailPage from '$/app/(private)/_components/CommitDetailPage'
import { findCommit, getFirstProject } from '$/app/(private)/_data-access'
import { getCurrentUser, SessionData } from '$/services/auth/getCurrentUser'
import { ROUTES } from '$/services/routes'
import { notFound } from 'next/navigation'

export const dynamic = 'force-dynamic'
const PROJECT_ROUTE = ROUTES.projects.detail

export default async function AppRoot() {
let session: SessionData
let project: Project
let commit: Commit
let url

try {
session = await getCurrentUser()
project = await getFirstProject({ workspaceId: session.workspace.id })
commit = await findCommit({ isLatest: true, projectId: project.id })
url = PROJECT_ROUTE({ id: project.id }).commits.latest
} catch (error) {
if (error instanceof NotFoundError) {
return notFound()
}

throw error
}

export default async function Home() {
return (
<FocusLayout
header={
<FocusHeader
title='Inside the APP 💪'
description="Your're in let's kick those random AI's butts!"
/>
}
>
<div className='flex items-center justify-center'>
<DummyLogoutButton />
</div>
</FocusLayout>
<CommitDetailPage
session={session}
project={project}
commit={commit}
url={url}
/>
)
}
43 changes: 43 additions & 0 deletions apps/web/src/app/(private)/projects/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Commit, NotFoundError, Project } from '@latitude-data/core'
import CommitDetailPage from '$/app/(private)/_components/CommitDetailPage'
import { findCommit, findProject } from '$/app/(private)/_data-access'
import { getCurrentUser, SessionData } from '$/services/auth/getCurrentUser'
import { ROUTES } from '$/services/routes'
import { notFound } from 'next/navigation'

export const dynamic = 'force-dynamic'
const PROJECT_ROUTE = ROUTES.projects.detail

export type ProjectPageParams = {
params: { id: string }
}
export default async function ProjectPage({ params }: ProjectPageParams) {
let session: SessionData
let project: Project
let commit: Commit
let url

try {
session = await getCurrentUser()
project = await findProject({
projectId: params.id,
workspaceId: session.workspace.id,
})
commit = await findCommit({ isLatest: true, projectId: project.id })
url = PROJECT_ROUTE({ id: +project.id }).commits.latest
} catch (error) {
if (error instanceof NotFoundError) {
return notFound()
}
throw error
}

return (
<CommitDetailPage
session={session}
project={project}
commit={commit}
url={url}
/>
)
}
49 changes: 49 additions & 0 deletions apps/web/src/app/(private)/projects/[id]/versions/[uuid]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {
Commit,
HEAD_COMMIT,
NotFoundError,
Project,
} from '@latitude-data/core'
import CommitDetailPage from '$/app/(private)/_components/CommitDetailPage'
import { findCommit, findProject } from '$/app/(private)/_data-access'
import { ProjectPageParams } from '$/app/(private)/projects/[id]/page'
import { getCurrentUser, SessionData } from '$/services/auth/getCurrentUser'
import { notFound } from 'next/navigation'

export const dynamic = 'force-dynamic'

export type CommitPageParams = {
params: ProjectPageParams['params'] & { uuid: string }
}
export default async function CommitRoot({ params }: CommitPageParams) {
const isLatest = params.uuid === HEAD_COMMIT
let session: SessionData
let project: Project
let commit: Commit
try {
session = await getCurrentUser()
project = await findProject({
projectId: params.id,
workspaceId: session.workspace.id,
})
commit = await findCommit({
isLatest,
uuid: params.uuid,
projectId: project.id,
})
} catch (error) {
if (error instanceof NotFoundError) {
return notFound()
}
throw error
}

return (
<CommitDetailPage
isLatest={isLatest}
session={session}
project={project}
commit={commit}
/>
)
}
5 changes: 5 additions & 0 deletions apps/web/src/app/(private)/projects/[id]/versions/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import ProjectPage from '$/app/(private)/projects/[id]/page'

export const dynamic = 'force-dynamic'

export default ProjectPage
5 changes: 5 additions & 0 deletions apps/web/src/app/(private)/projects/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import AppRoot from '$/app/(private)/page'

export const dynamic = 'force-dynamic'

export default AppRoot
Loading

0 comments on commit b510b7c

Please sign in to comment.