Browse Source

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

vanilla_orig
David Luzar 4 years ago
parent
commit
9c51ba6067
No account linked to committer's email address
2 changed files with 19 additions and 2 deletions
  1. 16
    1
      src/actions/actionExport.tsx
  2. 3
    1
      src/locales/en.json

+ 16
- 1
src/actions/actionExport.tsx View File

96
 export const actionSaveScene = register({
96
 export const actionSaveScene = register({
97
   name: "saveScene",
97
   name: "saveScene",
98
   perform: async (elements, appState, value) => {
98
   perform: async (elements, appState, value) => {
99
+    const fileHandleExists = !!appState.fileHandle;
99
     try {
100
     try {
100
       const { fileHandle } = await saveAsJSON(elements, appState);
101
       const { fileHandle } = await saveAsJSON(elements, appState);
101
-      return { commitToHistory: false, appState: { ...appState, fileHandle } };
102
+      return {
103
+        commitToHistory: false,
104
+        appState: {
105
+          ...appState,
106
+          fileHandle,
107
+          toastMessage: fileHandleExists
108
+            ? fileHandle.name
109
+              ? t("toast.fileSavedToFilename").replace(
110
+                  "{filename}",
111
+                  `"${fileHandle.name}"`,
112
+                )
113
+              : t("toast.fileSaved")
114
+            : null,
115
+        },
116
+      };
102
     } catch (error) {
117
     } catch (error) {
103
       if (error?.name !== "AbortError") {
118
       if (error?.name !== "AbortError") {
104
         console.error(error);
119
         console.error(error);

+ 3
- 1
src/locales/en.json View File

243
   "toast": {
243
   "toast": {
244
     "copyStyles": "Copied styles.",
244
     "copyStyles": "Copied styles.",
245
     "copyToClipboard": "Copied to clipboard.",
245
     "copyToClipboard": "Copied to clipboard.",
246
-    "copyToClipboardAsPng": "Copied to clipboard as PNG."
246
+    "copyToClipboardAsPng": "Copied to clipboard as PNG.",
247
+    "fileSaved": "File saved.",
248
+    "fileSavedToFilename": "Saved to {filename}"
247
   }
249
   }
248
 }
250
 }

Loading…
Cancel
Save