-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save documents in DB from sidebar and make sidebar resizable
- Loading branch information
1 parent
dda49f1
commit a3be7fa
Showing
36 changed files
with
1,099 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use server' | ||
|
||
import { | ||
CommitsRepository, | ||
destroyDocument, | ||
DocumentVersionsRepository, | ||
} from '@latitude-data/core' | ||
import { z } from 'zod' | ||
|
||
import { withProject } from '../procedures' | ||
|
||
export const destroyDocumentAction = withProject | ||
.createServerAction() | ||
.input(z.object({ documentUuid: z.string(), commitId: z.number() }), { | ||
type: 'json', | ||
}) | ||
.handler(async ({ input, ctx }) => { | ||
const commitsScope = new CommitsRepository(ctx.project.workspaceId) | ||
const commit = await commitsScope | ||
.getCommitById(input.commitId) | ||
.then((r) => r.unwrap()) | ||
const docsScope = new DocumentVersionsRepository(ctx.project.workspaceId) | ||
const document = await docsScope | ||
.getDocumentByUuid({ | ||
commit, | ||
documentUuid: input.documentUuid, | ||
}) | ||
.then((r) => r.unwrap()) | ||
const result = await destroyDocument({ | ||
document, | ||
commit, | ||
workspaceId: ctx.project.workspaceId, | ||
}) | ||
return result.unwrap() | ||
}) |
24 changes: 24 additions & 0 deletions
24
apps/web/src/actions/documents/getDocumentsAtCommitAction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use server' | ||
|
||
import { | ||
CommitsRepository, | ||
DocumentVersionsRepository, | ||
} from '@latitude-data/core' | ||
import { z } from 'zod' | ||
|
||
import { withProject } from '../procedures' | ||
|
||
export const getDocumentsAtCommitAction = withProject | ||
.createServerAction() | ||
.input(z.object({ commitId: z.number() })) | ||
.handler(async ({ input, ctx }) => { | ||
const commit = await new CommitsRepository(ctx.project.workspaceId) | ||
.getCommitById(input.commitId) | ||
.then((r) => r.unwrap()) | ||
const docsScope = new DocumentVersionsRepository(ctx.project.workspaceId) | ||
const result = await docsScope.getDocumentsAtCommit({ | ||
commit, | ||
}) | ||
|
||
return result.unwrap() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...private)/projects/[projectId]/versions/[commitUuid]/_components/DocumentsLayout/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { ReactNode } from 'react' | ||
|
||
import { DocumentVersion } from '@latitude-data/core' | ||
import { DocumentDetailWrapper } from '@latitude-data/web-ui' | ||
import { findCommit, findProject } from '$/app/(private)/_data-access' | ||
import { getCurrentUser } from '$/services/auth/getCurrentUser' | ||
|
||
import Sidebar from '../Sidebar' | ||
|
||
export default async function DocumentsLayout({ | ||
children, | ||
document, | ||
commitUuid, | ||
projectId, | ||
}: { | ||
children: ReactNode | ||
document?: DocumentVersion | ||
projectId: number | ||
commitUuid: string | ||
}) { | ||
const session = await getCurrentUser() | ||
const project = await findProject({ | ||
projectId, | ||
workspaceId: session.workspace.id, | ||
}) | ||
const commit = await findCommit({ | ||
project, | ||
uuid: commitUuid, | ||
}) | ||
return ( | ||
<DocumentDetailWrapper> | ||
<Sidebar commit={commit} documentPath={document?.path} /> | ||
{children} | ||
</DocumentDetailWrapper> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 11 additions & 21 deletions
32
...rc/app/(private)/projects/[projectId]/versions/[commitUuid]/_components/Sidebar/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,25 @@ | ||
import { Suspense } from 'react' | ||
|
||
import { | ||
Commit, | ||
DocumentVersionsRepository, | ||
findWorkspaceFromCommit, | ||
} from '@latitude-data/core' | ||
import { Commit, DocumentVersionsRepository } from '@latitude-data/core' | ||
import { DocumentSidebar } from '@latitude-data/web-ui' | ||
import { getCurrentUser } from '$/services/auth/getCurrentUser' | ||
|
||
import ClientFilesTree from './ClientFilesTree' | ||
|
||
export default async function Sidebar({ | ||
commit, | ||
documentUuid, | ||
documentPath, | ||
}: { | ||
commit: Commit | ||
documentPath?: string | ||
documentUuid?: string | ||
}) { | ||
const workspace = await findWorkspaceFromCommit(commit) | ||
const docsScope = new DocumentVersionsRepository(workspace!.id) | ||
const documents = await docsScope.getDocumentsAtCommit(commit) | ||
const { workspace } = await getCurrentUser() | ||
const docsScope = new DocumentVersionsRepository(workspace.id) | ||
const documents = await docsScope.getDocumentsAtCommit({ commit }) | ||
return ( | ||
<Suspense fallback={<div>Loading...</div>}> | ||
<DocumentSidebar> | ||
<ClientFilesTree | ||
documentPath={documentPath} | ||
documents={documents.unwrap()} | ||
documentUuid={documentUuid} | ||
/> | ||
</DocumentSidebar> | ||
</Suspense> | ||
<DocumentSidebar> | ||
<ClientFilesTree | ||
documentPath={documentPath} | ||
documents={documents.unwrap()} | ||
/> | ||
</DocumentSidebar> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
.../(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/layout.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import DocumentsLayout from '../_components/DocumentsLayout' | ||
|
||
export default async function DocumentsPage({ | ||
params, | ||
}: { | ||
params: { projectId: string; commitUuid: string; documentUuid: string } | ||
}) { | ||
const projectId = Number(params.projectId) | ||
const commintUuid = params.commitUuid | ||
return ( | ||
<DocumentsLayout projectId={projectId} commitUuid={commintUuid}> | ||
<div>List of documents</div> | ||
</DocumentsLayout> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.