prevent autosave from prompting on failure & granularize error messages

This commit is contained in:
dwelle
2021-04-04 15:13:56 +02:00
parent 6442a45bd4
commit 0b32757085
4 changed files with 24 additions and 7 deletions
+19 -6
View File
@@ -924,7 +924,7 @@ class App extends React.Component<AppProps, AppState> {
?.classList.toggle("theme--dark", this.state.theme === "dark");
if (this.state.autosave && this.state.fileHandle && supported) {
this.saveLocalSceneDebounced(
this.autosaveLocalSceneDebounced(
this.scene.getElementsIncludingDeleted(),
this.state,
);
@@ -1062,18 +1062,31 @@ class App extends React.Component<AppProps, AppState> {
});
}, SCROLL_TIMEOUT);
private saveLocalSceneDebounced = debounce(
private autosaveLocalSceneDebounced = debounce(
async (elements: readonly ExcalidrawElement[], state: AppState) => {
if (this.state.autosave && this.state.fileHandle && supported) {
try {
await saveAsJSON(elements, state);
await saveAsJSON(
elements,
state,
// only if fileHandle valid
true,
);
} catch (error) {
// shouldn't (almost) ever happen, so let's log it
console.error(error);
this.setState({
autosave: false,
errorMessage: t("toast.autosaveFailed"),
toastMessage:
error.name === "NotAllowedError"
? t("toast.autosaveFailed_notAllowed")
: error.name === "NotFoundError"
? t("toast.autosaveFailed_notFound")
: t("toast.autosaveFailed"),
});
// shouldn't happen, so let's log it
if (!["NotAllowedError", "NotFoundError"].includes(error.name)) {
console.error(error);
}
}
}
},