Skip to content

Commit

Permalink
fix: Removes UI blinking while loading the document
Browse files Browse the repository at this point in the history
  • Loading branch information
bk201- committed Dec 3, 2024
1 parent 711689a commit 89041e1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/webviews/Document/DocumentPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const DocumentPanel = () => {
const state = useDocumentState();
const dispatcher = useDocumentDispatcher();

const isInit = state.isInit;
const isReady = state.isReady;
const isReadOnly = state.mode === 'view';
const inProgress = state.isSaving || state.isRefreshing;
const hasDocumentInDB = state.documentId !== '';
Expand Down Expand Up @@ -179,7 +179,7 @@ export const DocumentPanel = () => {
void dispatcher?.notifyDirty?.(state.isDirty);
}, [dispatcher, state.isDirty]);

if (!isInit || !state.currentDocumentContent) {
if (!isReady || !state.currentDocumentContent) {
return (
<section className={classes.container}>
<ProgressBar />
Expand Down
8 changes: 4 additions & 4 deletions src/webviews/Document/DocumentToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export type DocumentToolbarProps = {
export const DocumentToolbar = (props: DocumentToolbarProps) => {
const state = useDocumentState();

const isInit = state.isInit;
const isReady = state.isReady;
const inProgress = state.isSaving || state.isRefreshing;
const hasDocumentInDB = state.documentId !== '';
const isReadOnly = isInit && state.mode === 'view'; // If the document is not initialized, it is considered as not state
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';
Expand All @@ -33,7 +33,7 @@ export const DocumentToolbar = (props: DocumentToolbarProps) => {
return (
<>
<Toolbar size={'small'}>
{isInit && !isReadOnly && (
{isReady && !isReadOnly && (
<Tooltip
content={`Save document to the database (${onSaveHotkeyTitle})`}
relationship="description"
Expand All @@ -50,7 +50,7 @@ export const DocumentToolbar = (props: DocumentToolbarProps) => {
</ToolbarButton>
</Tooltip>
)}
{isInit && isReadOnly && (
{isReady && isReadOnly && (
<Tooltip
content={`Open document for editing (${onEditHotkeyTitle})`}
relationship="description"
Expand Down
6 changes: 3 additions & 3 deletions src/webviews/Document/state/DocumentState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export type DocumentState = {
isDirty: boolean; // Document has been modified
isSaving: boolean; // Document is being saved
isRefreshing: boolean; // Document is being refreshed
isInit: boolean; // Document is being initialized
isReady: boolean; // Document is being initialized

currentDocumentContent: string; // Current content of the document
error: string | undefined; // Error message
Expand All @@ -83,7 +83,7 @@ export const defaultState: DocumentState = {
isDirty: false,
isSaving: false,
isRefreshing: false,
isInit: false,
isReady: false,
currentDocumentContent: '',
error: undefined,
};
Expand All @@ -108,7 +108,7 @@ export function dispatch(state: DocumentState, action: DispatchAction): Document
documentId: action.documentId,
dbName: action.databaseId,
collectionName: action.containerId,
isInit: true,
isReady: true,
};
case 'setDocument':
return {
Expand Down

0 comments on commit 89041e1

Please sign in to comment.