diff --git a/src/webviews/Document/DocumentPanel.tsx b/src/webviews/Document/DocumentPanel.tsx index 49e56487..b129b98e 100644 --- a/src/webviews/Document/DocumentPanel.tsx +++ b/src/webviews/Document/DocumentPanel.tsx @@ -95,9 +95,10 @@ export const DocumentPanel = () => { const state = useDocumentState(); const dispatcher = useDocumentDispatcher(); + const isReady = state.isReady; const isReadOnly = state.mode === 'view'; const inProgress = state.isSaving || state.isRefreshing; - const hasDocumentInDB = state.documentId !== undefined; + const hasDocumentInDB = state.documentId !== ''; const onSave = async () => { // Save document to the database @@ -178,6 +179,14 @@ export const DocumentPanel = () => { void dispatcher?.notifyDirty?.(state.isDirty); }, [dispatcher, state.isDirty]); + if (!isReady || !state.currentDocumentContent) { + return ( +
+ +
+ ); + } + return (
diff --git a/src/webviews/Document/DocumentToolbar.tsx b/src/webviews/Document/DocumentToolbar.tsx index 72dafb49..977b1a03 100644 --- a/src/webviews/Document/DocumentToolbar.tsx +++ b/src/webviews/Document/DocumentToolbar.tsx @@ -20,9 +20,10 @@ export type DocumentToolbarProps = { export const DocumentToolbar = (props: DocumentToolbarProps) => { const state = useDocumentState(); + const isReady = state.isReady; const inProgress = state.isSaving || state.isRefreshing; - const hasDocumentInDB = state.documentId !== undefined; - const isReadOnly = state.mode === 'view'; + const hasDocumentInDB = state.documentId !== ''; + const isReadOnly = isReady && state.mode === 'view'; // If the document is not initialized, it is considered as not state const isMac = navigator.platform.toLowerCase().includes('mac'); const onSaveHotkeyTitle = isMac ? '\u2318 S' : 'Ctrl+S'; @@ -32,7 +33,7 @@ export const DocumentToolbar = (props: DocumentToolbarProps) => { return ( <> - {!isReadOnly && ( + {isReady && !isReadOnly && ( { )} - {isReadOnly && ( + {isReady && isReadOnly && (