From a518846900617e6f5880bd0cfb8383b5db6f8efa Mon Sep 17 00:00:00 2001 From: Red J Adaya Date: Fri, 16 Aug 2024 02:17:49 +0800 Subject: [PATCH] only set save button to yellow when there are edits (#228) --- frontend/app/view/preview/preview.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/frontend/app/view/preview/preview.tsx b/frontend/app/view/preview/preview.tsx index 5211c3c3a..9f7edd691 100644 --- a/frontend/app/view/preview/preview.tsx +++ b/frontend/app/view/preview/preview.tsx @@ -49,7 +49,7 @@ export class PreviewModel implements ViewModel { fileMimeType: jotai.Atom>; fileMimeTypeLoadable: jotai.Atom>; fileContent: jotai.Atom>; - newFileContent: jotai.PrimitiveAtom; + newFileContent: jotai.PrimitiveAtom; showHiddenFiles: jotai.PrimitiveAtom; refreshVersion: jotai.PrimitiveAtom; @@ -111,11 +111,17 @@ export class PreviewModel implements ViewModel { }, ]; if (get(this.ceReadOnly) == false) { + let saveClassName = "secondary"; + if (get(this.newFileContent) !== null) { + saveClassName = "primary"; + } viewTextChildren.push( { elemtype: "textbutton", text: "Save", - className: "primary warning border-radius-4 vertical-padding-2 horizontal-padding-10", + className: clsx( + `${saveClassName} warning border-radius-4 vertical-padding-2 horizontal-padding-10` + ), onClick: this.handleFileSave.bind(this), }, { @@ -218,7 +224,7 @@ export class PreviewModel implements ViewModel { const fullFile = await get(this.fullFile); return util.base64ToString(fullFile?.data64); }); - this.newFileContent = jotai.atom(""); + this.newFileContent = jotai.atom(null) as jotai.PrimitiveAtom; this.handleBack = this.handleBack.bind(this); } @@ -245,6 +251,7 @@ export class PreviewModel implements ViewModel { const newFileContent = globalStore.get(this.newFileContent); try { services.FileService.SaveFile(fileName, util.stringToBase64(newFileContent)); + globalStore.set(this.newFileContent, null); } catch (error) { console.error("Error saving file:", error); }