feat: show toast when saving to existing file (#2988)

This commit is contained in:
David Luzar 2021-02-07 22:01:22 +01:00 committed by GitHub
parent bf50c9cae7
commit 9c51ba6067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -96,9 +96,24 @@ export const actionChangeShouldAddWatermark = register({
export const actionSaveScene = register({
name: "saveScene",
perform: async (elements, appState, value) => {
const fileHandleExists = !!appState.fileHandle;
try {
const { fileHandle } = await saveAsJSON(elements, appState);
return { commitToHistory: false, appState: { ...appState, fileHandle } };
return {
commitToHistory: false,
appState: {
...appState,
fileHandle,
toastMessage: fileHandleExists
? fileHandle.name
? t("toast.fileSavedToFilename").replace(
"{filename}",
`"${fileHandle.name}"`,
)
: t("toast.fileSaved")
: null,
},
};
} catch (error) {
if (error?.name !== "AbortError") {
console.error(error);

View File

@ -243,6 +243,8 @@
"toast": {
"copyStyles": "Copied styles.",
"copyToClipboard": "Copied to clipboard.",
"copyToClipboardAsPng": "Copied to clipboard as PNG."
"copyToClipboardAsPng": "Copied to clipboard as PNG.",
"fileSaved": "File saved.",
"fileSavedToFilename": "Saved to {filename}"
}
}