Explorar el Código

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

vanilla_orig
David Luzar hace 4 años
padre
commit
9c51ba6067
No account linked to committer's email address
Se han modificado 2 ficheros con 19 adiciones y 2 borrados
  1. 16
    1
      src/actions/actionExport.tsx
  2. 3
    1
      src/locales/en.json

+ 16
- 1
src/actions/actionExport.tsx Ver fichero

@@ -96,9 +96,24 @@ export const actionChangeShouldAddWatermark = register({
96 96
 export const actionSaveScene = register({
97 97
   name: "saveScene",
98 98
   perform: async (elements, appState, value) => {
99
+    const fileHandleExists = !!appState.fileHandle;
99 100
     try {
100 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 117
     } catch (error) {
103 118
       if (error?.name !== "AbortError") {
104 119
         console.error(error);

+ 3
- 1
src/locales/en.json Ver fichero

@@ -243,6 +243,8 @@
243 243
   "toast": {
244 244
     "copyStyles": "Copied styles.",
245 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…
Cancelar
Guardar