From 9c51ba6067b4890e00e0119b1211f214c10fbf08 Mon Sep 17 00:00:00 2001 From: David Luzar Date: Sun, 7 Feb 2021 22:01:22 +0100 Subject: [PATCH] feat: show toast when saving to existing file (#2988) --- src/actions/actionExport.tsx | 17 ++++++++++++++++- src/locales/en.json | 4 +++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/actions/actionExport.tsx b/src/actions/actionExport.tsx index e341d98f..b24c5e3d 100644 --- a/src/actions/actionExport.tsx +++ b/src/actions/actionExport.tsx @@ -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); diff --git a/src/locales/en.json b/src/locales/en.json index 0a7949af..e69a2a5f 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -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}" } }