From ce1ede8b3df3a13dc12ac89d8106cbfc8ee1efc7 Mon Sep 17 00:00:00 2001 From: acaldas Date: Tue, 2 Jul 2024 14:29:21 +0100 Subject: [PATCH] feat: split file creation and operations push --- src/hooks/useDocumentDriveServer.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/hooks/useDocumentDriveServer.ts b/src/hooks/useDocumentDriveServer.ts index cfafdd08..2e064e6b 100644 --- a/src/hooks/useDocumentDriveServer.ts +++ b/src/hooks/useDocumentDriveServer.ts @@ -149,13 +149,29 @@ export function useDocumentDriveServer( throw new Error('User is not allowed to create files'); } const document = await loadFile(file, getDocumentModel); - return addDocument( + + // first create the file with the initial state of document + const initialDocument: Document = { + ...document.initialState, + initialState: document.initialState, + operations: { + global: [], + local: [], + }, + clipboard: [], + }; + const fileNode = await addDocument( drive, name || (typeof file === 'string' ? document.name : file.name), document.documentType, parentFolder, - document, + initialDocument, ); + + // then add all the operations + for (const operations of Object.values(document.operations)) { + await addOperations(drive, fileNode.id, operations); + } } async function updateFile(