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 52101f5 commit b2abde4
Show file tree
Hide file tree
Showing 75 changed files with 1,426 additions and 392 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
25 changes: 0 additions & 25 deletions apps/web/src/app/(private)/_components/DummyLogoutButton/index.tsx

This file was deleted.

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 ({ uuid, projectId }: FindCommitProps) => {
const result = await originalfindCommit({ 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>
)
}
15 changes: 11 additions & 4 deletions apps/web/src/app/(private)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import { ReactNode } from 'react'

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

export default async function PrivateLayout({
children,
}: {
children: ReactNode
}) {
}: Readonly<{ children: ReactNode }>) {
const data = await getSession()

if (!data.session) {
return redirect(ROUTES.auth.login)
}
return children

const session = await getCurrentUser()
return (
<SessionProvider currentUser={session.user} workspace={session.workspace}>
{children}
</SessionProvider>
)
}
42 changes: 25 additions & 17 deletions apps/web/src/app/(private)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import { FocusHeader, FocusLayout } from '@latitude-data/web-ui'
import DummyLogoutButton from '$/app/(private)/_components/DummyLogoutButton'
import { HEAD_COMMIT, NotFoundError, Project } from '@latitude-data/core'
import { findCommit, getFirstProject } from '$/app/(private)/_data-access'
import { getCurrentUser, SessionData } from '$/services/auth/getCurrentUser'
import { ROUTES } from '$/services/routes'
import { notFound, redirect } from 'next/navigation'

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

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>
)
export default async function AppRoot() {
let session: SessionData
let project: Project
let url

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

throw error
}

return redirect(url)
}

This file was deleted.

15 changes: 0 additions & 15 deletions apps/web/src/app/(private)/projects/[projectId]/layout.tsx

This file was deleted.

34 changes: 34 additions & 0 deletions apps/web/src/app/(private)/projects/[projectId]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { HEAD_COMMIT, NotFoundError, Project } from '@latitude-data/core'
import { findCommit, findProject } from '$/app/(private)/_data-access'
import { getCurrentUser, SessionData } from '$/services/auth/getCurrentUser'
import { ROUTES } from '$/services/routes'
import { notFound, redirect } from 'next/navigation'

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

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

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

return redirect(url)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { ReactNode } from 'react'

import {
Commit,
HEAD_COMMIT,
NotFoundError,
Project,
} from '@latitude-data/core'
import { CommitProvider, ProjectProvider } from '@latitude-data/web-ui'
import { AppLayout, BreadcrumpBadge } from '@latitude-data/web-ui/browser'
import { findCommit, findProject } from '$/app/(private)/_data-access'
import { NAV_LINKS } from '$/app/(private)/_lib/constants'
import { ProjectPageParams } from '$/app/(private)/projects/[projectId]/page'
import Sidebar from '$/components/Sidebar'
import { getCurrentUser, SessionData } from '$/services/auth/getCurrentUser'
import { notFound } from 'next/navigation'

export type CommitPageParams = {
children: ReactNode
params: ProjectPageParams['params'] & { commitUuid: string }
}

export default async function CommitLayout({
children,
params,
}: CommitPageParams) {
const isHead = params.commitUuid === HEAD_COMMIT
let session: SessionData
let project: Project
let commit: Commit
try {
session = await getCurrentUser()
project = await findProject({
projectId: params.projectId,
workspaceId: session.workspace.id,
})
commit = await findCommit({
uuid: params.commitUuid,
projectId: project.id,
})
} catch (error) {
if (error instanceof NotFoundError) {
return notFound()
}
throw error
}

return (
<ProjectProvider project={project}>
<CommitProvider commit={commit} isHead={isHead}>
<AppLayout
navigationLinks={NAV_LINKS}
currentUser={session.user}
breadcrumbs={[
{ name: session.workspace.name },
{ name: project.name },
{
name: (
<BreadcrumpBadge
uuid={commit.uuid}
title={commit.title}
isHead={isHead}
/>
),
},
]}
>
<main className='flex flex-row w-full'>
<div className='w-[280px]'>
<Sidebar commitUuid={commit.uuid} projectId={project.id} />
</div>
<div className='flex-1'>{children}</div>
</main>
</AppLayout>
</CommitProvider>
</ProjectProvider>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const dynamic = 'force-dynamic'

export default async function CommitRoot() {
return <div>Commits home</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import ProjectPage from '$/app/(private)/projects/[projectId]/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
8 changes: 2 additions & 6 deletions apps/web/src/app/(public)/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
Card,
CardContent,
FocusHeader,
FocusLayout,
} from '@latitude-data/web-ui'
import { Card, CardContent, FocusHeader } from '@latitude-data/web-ui'
import { FocusLayout } from '@latitude-data/web-ui/browser'
import AuthFooter from '$/app/(public)/_components/Footer'
import { isWorkspaceCreated } from '$/data-access'
import { ROUTES } from '$/services/routes'
Expand Down
8 changes: 2 additions & 6 deletions apps/web/src/app/(public)/setup/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
Card,
CardContent,
FocusHeader,
FocusLayout,
} from '@latitude-data/web-ui'
import { Card, CardContent, FocusHeader } from '@latitude-data/web-ui'
import { FocusLayout } from '@latitude-data/web-ui/browser'
import AuthFooter from '$/app/(public)/_components/Footer'

import SetupForm from './SetupForm'
Expand Down
Loading

0 comments on commit b2abde4

Please sign in to comment.