diff --git a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/_components/DocumentsLayout/index.tsx b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/_components/DocumentsLayout/index.tsx index 8f741308c..215eb8fca 100644 --- a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/_components/DocumentsLayout/index.tsx +++ b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/_components/DocumentsLayout/index.tsx @@ -29,7 +29,7 @@ export default async function DocumentsLayout({ }) return ( - + {children} ) diff --git a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/_components/Sidebar/ClientFilesTree/index.tsx b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/_components/Sidebar/ClientFilesTree/index.tsx index f2fea97d4..36d78c81b 100644 --- a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/_components/Sidebar/ClientFilesTree/index.tsx +++ b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/_components/Sidebar/ClientFilesTree/index.tsx @@ -15,15 +15,15 @@ import { useRouter } from 'next/navigation' export default function ClientFilesTree({ documents: serverDocuments, - documentPath, + currentDocument, }: { documents: SidebarDocument[] - documentPath: string | undefined + currentDocument: SidebarDocument | undefined }) { const router = useRouter() const { commit, isHead } = useCurrentCommit() const { project } = useCurrentProject() - + const documentPath = currentDocument?.path const navigateToDocument = useCallback((documentUuid: string) => { router.push( ROUTES.projects @@ -32,9 +32,13 @@ export default function ClientFilesTree({ .documents.detail({ uuid: documentUuid }).root, ) }, []) - const { createFile, destroyFile, documents } = useDocumentVersions({ - fallbackData: serverDocuments, - }) + const { createFile, destroyFile, documents } = useDocumentVersions( + { currentDocument }, + { fallbackData: serverDocuments }, + ) + + console.log('DO_UUID', currentDocument?.documentUuid) + console.log('DO_PATH', currentDocument?.path) return ( diff --git a/apps/web/src/stores/documentVersions.ts b/apps/web/src/stores/documentVersions.ts index 7c4f322ad..432137b41 100644 --- a/apps/web/src/stores/documentVersions.ts +++ b/apps/web/src/stores/documentVersions.ts @@ -4,6 +4,7 @@ import { useCallback } from 'react' import { DocumentVersion } from '@latitude-data/core' import { + SidebarDocument, useCurrentCommit, useCurrentProject, useToast, @@ -16,7 +17,10 @@ import { useRouter } from 'next/navigation' import useSWR, { SWRConfiguration } from 'swr' import { useServerAction } from 'zsa-react' -export default function useDocumentVersions(opts?: SWRConfiguration) { +export default function useDocumentVersions( + { currentDocument }: { currentDocument: SidebarDocument | undefined }, + opts?: SWRConfiguration, +) { const { toast } = useToast() const router = useRouter() const { project } = useCurrentProject() @@ -98,11 +102,13 @@ export default function useDocumentVersions(opts?: SWRConfiguration) { } else { const prevDocuments = data || [] mutate(prevDocuments.filter((d) => d.documentUuid !== documentUuid)) - router.push( - ROUTES.projects - .detail({ id: project.id }) - .commits.detail({ uuid: commit.uuid }).documents.root, - ) + if (currentDocument?.documentUuid === documentUuid) { + router.push( + ROUTES.projects + .detail({ id: project.id }) + .commits.detail({ uuid: commit.uuid }).documents.root, + ) + } } }, [executeDestroyDocument, mutate, data], diff --git a/packages/core/src/repositories/documentVersionsRepository/index.ts b/packages/core/src/repositories/documentVersionsRepository/index.ts index b6ceccfdc..4920f2ff9 100644 --- a/packages/core/src/repositories/documentVersionsRepository/index.ts +++ b/packages/core/src/repositories/documentVersionsRepository/index.ts @@ -63,8 +63,8 @@ export class DocumentVersionsRepository extends Repository { .from(this.scope) .where( and( - eq(documentVersions.commitId, commit.id), - eq(documentVersions.documentUuid, documentUuid), + eq(this.scope.commitId, commit.id), + eq(this.scope.documentUuid, documentUuid), ), ) .limit(1)