diff --git a/src/hooks/useDocumentRoot.ts b/src/hooks/useDocumentRoot.ts index 8427f9f1..1208c2a3 100644 --- a/src/hooks/useDocumentRoot.ts +++ b/src/hooks/useDocumentRoot.ts @@ -7,26 +7,27 @@ import DocumentRoot, { TypeMeta } from '../models/DocumentRoot'; export const useDocumentRoot = (id: string | undefined, meta: TypeMeta) => { const defaultRootDocId = useId(); const defaultDocId = useId(); + const store = rootStore.documentRootStore; const [dummyDocumentRoot] = React.useState>( new DocumentRoot( { id: id || defaultRootDocId, access: Access.RW }, meta, - rootStore.documentRootStore, + store, true ) ); /** initial load */ React.useEffect(() => { - const rootDoc = rootStore.documentRootStore.find(dummyDocumentRoot.id); + const rootDoc = store.find(dummyDocumentRoot.id); if ( rootDoc || - rootStore.documentRootStore.apiStateFor(`load-${dummyDocumentRoot.id}`) === ApiState.LOADING + store.apiStateFor(`load-${dummyDocumentRoot.id}`) === ApiState.LOADING ) { return; } if (dummyDocumentRoot.isDummy) { - rootStore.documentRootStore.addDocumentRoot(dummyDocumentRoot); + store.addDocumentRoot(dummyDocumentRoot); /** add default document when there are no mainDocs */ if (dummyDocumentRoot.mainDocuments.length === 0) { const now = new Date().toISOString(); @@ -50,11 +51,11 @@ export const useDocumentRoot = (id: string | undefine /** * load the documentRoot and it's documents from the api. */ - rootStore.documentRootStore + store .load(id, meta) .then((docRoot) => { if (!docRoot) { - return rootStore.documentRootStore.create(id, meta, {}).then((docRoot) => { + return store.create(id, meta, {}).then((docRoot) => { return docRoot; }); } @@ -77,5 +78,5 @@ export const useDocumentRoot = (id: string | undefine }); }, [meta, id]); - return dummyDocumentRoot.id; + return store.find(dummyDocumentRoot.id); }; diff --git a/src/stores/DocumentStore.ts b/src/stores/DocumentStore.ts index 51e24db1..9e5c5d64 100644 --- a/src/stores/DocumentStore.ts +++ b/src/stores/DocumentStore.ts @@ -78,7 +78,6 @@ class DocumentStore extends iStore { return; } const model = this.createModel(data); - console.log('add model', data, model); this.removeFromStore(model.id); this.documents.push(model); diff --git a/src/theme/CodeEditor/WithScript/ScriptContext.tsx b/src/theme/CodeEditor/WithScript/ScriptContext.tsx index 40be4c0e..50de2ea4 100644 --- a/src/theme/CodeEditor/WithScript/ScriptContext.tsx +++ b/src/theme/CodeEditor/WithScript/ScriptContext.tsx @@ -38,9 +38,7 @@ export class ScriptMeta extends TypeMeta { const ScriptContext = observer((props: InitState & { children: React.ReactNode }) => { const [meta] = React.useState(new ScriptMeta(props)); - const documentRootId = useDocumentRoot(props.id, meta); - const documentRootStore = useStore('documentRootStore'); - const documentRoot = documentRootStore.find(documentRootId); + const documentRoot = useDocumentRoot(props.id, meta); if (!documentRoot || !documentRoot.firstMainDocument) { return
Load
;