fix: Prevent local AppState reset during collaboration
This commit is contained in:
parent
fdd8552637
commit
5542e4528a
@ -46,12 +46,15 @@ class LocalFileManager extends FileManager {
|
|||||||
const saveDataStateToLocalStorage = (
|
const saveDataStateToLocalStorage = (
|
||||||
elements: readonly ExcalidrawElement[],
|
elements: readonly ExcalidrawElement[],
|
||||||
appState: AppState,
|
appState: AppState,
|
||||||
|
appStateOnly = false,
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
localStorage.setItem(
|
if (!appStateOnly) {
|
||||||
STORAGE_KEYS.LOCAL_STORAGE_ELEMENTS,
|
localStorage.setItem(
|
||||||
JSON.stringify(clearElementsForLocalStorage(elements)),
|
STORAGE_KEYS.LOCAL_STORAGE_ELEMENTS,
|
||||||
);
|
JSON.stringify(clearElementsForLocalStorage(elements)),
|
||||||
|
);
|
||||||
|
}
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
STORAGE_KEYS.LOCAL_STORAGE_APP_STATE,
|
STORAGE_KEYS.LOCAL_STORAGE_APP_STATE,
|
||||||
JSON.stringify(clearAppStateForLocalStorage(appState)),
|
JSON.stringify(clearAppStateForLocalStorage(appState)),
|
||||||
@ -72,8 +75,12 @@ export class LocalData {
|
|||||||
appState: AppState,
|
appState: AppState,
|
||||||
files: BinaryFiles,
|
files: BinaryFiles,
|
||||||
onFilesSaved: () => void,
|
onFilesSaved: () => void,
|
||||||
|
appStateOnly = false,
|
||||||
) => {
|
) => {
|
||||||
saveDataStateToLocalStorage(elements, appState);
|
saveDataStateToLocalStorage(elements, appState, appStateOnly);
|
||||||
|
if (appStateOnly) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await this.fileStorage.saveFiles({
|
await this.fileStorage.saveFiles({
|
||||||
elements,
|
elements,
|
||||||
@ -97,6 +104,14 @@ export class LocalData {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Saves the AppState, only if saving is paused. */
|
||||||
|
static saveAppState = (appState: AppState) => {
|
||||||
|
// we need to make the `isSavePaused` check synchronously (undebounced)
|
||||||
|
if (this.isSavePaused()) {
|
||||||
|
this._save([], appState, {}, () => {}, true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static flushSave = () => {
|
static flushSave = () => {
|
||||||
this._save.flush();
|
this._save.flush();
|
||||||
};
|
};
|
||||||
|
@ -189,7 +189,7 @@ const initializeScene = async (opts: {
|
|||||||
...restoreAppState(
|
...restoreAppState(
|
||||||
{
|
{
|
||||||
...scene?.appState,
|
...scene?.appState,
|
||||||
theme: localDataState?.appState?.theme || scene?.appState?.theme,
|
...localDataState?.appState,
|
||||||
},
|
},
|
||||||
excalidrawAPI.getAppState(),
|
excalidrawAPI.getAppState(),
|
||||||
),
|
),
|
||||||
@ -538,6 +538,8 @@ const ExcalidrawWrapper = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
LocalData.saveAppState(appState);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user