Skip to content

Commit

Permalink
Show loading indicator on file storage operation
Browse files Browse the repository at this point in the history
  • Loading branch information
bischofmax committed Aug 29, 2024
1 parent 51cd9c7 commit 367fe81
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/hooks/useMultiplayerState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,19 @@ export function useMultiplayerState({
const [loading, setLoading] = useState(true);
const [isReadOnly, setIsReadOnly] = useState(false);

const setIsReadOnlyToTrue = (app?: TldrawApp) => {
setIsReadOnly(true);
if (app) app.setIsLoading(true);
};

// Bug in tl draw package leads to situation where app context readonly and prop readonly are not in sync.
// This function is a workaround to make sure that both are in sync.
const setIsReadOnlyToFalse = (app?: TldrawApp) => {
setIsReadOnly(false);
if (app) app.readOnly = false;
if (app) {
app.readOnly = false;
app.setIsLoading(false);
}
};

// Callbacks --------------
Expand Down Expand Up @@ -397,7 +405,7 @@ export function useMultiplayerState({
);

const onUndo = useCallback(async (app: TldrawApp) => {
setIsReadOnly(true);
setIsReadOnlyToTrue(app);
const assetsBeforeUndo = [...app.assets];
undoManager.undo();
const assetsAfterUndo = [...app.assets];
Expand All @@ -413,7 +421,7 @@ export function useMultiplayerState({
}, []);

const onRedo = useCallback(async (app: TldrawApp) => {
setIsReadOnly(true);
setIsReadOnlyToTrue(app);
const assetsBeforeRedo = [...app.assets];
undoManager.redo();
const assetsAfterRedo = [...app.assets];
Expand Down Expand Up @@ -569,7 +577,7 @@ export function useMultiplayerState({
const asset = app.assets.find((asset) => asset.id === id);
try {
if (asset) {
setIsReadOnly(true);
setIsReadOnlyToTrue(app);

await deleteAsset(asset);
}
Expand Down

0 comments on commit 367fe81

Please sign in to comment.