From d010f88e18999e71d64c0dbbee249aaf8abf0dbd Mon Sep 17 00:00:00 2001 From: Charles Dufour Date: Thu, 19 Sep 2024 18:30:53 +0200 Subject: [PATCH] [TRELLO-2590] Fix autosave, it was messing with attachements (#914) --- .../reportFlow/Details/Details.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/website/src/components_feature/reportFlow/Details/Details.tsx b/website/src/components_feature/reportFlow/Details/Details.tsx index 323f311a..e129e9a7 100644 --- a/website/src/components_feature/reportFlow/Details/Details.tsx +++ b/website/src/components_feature/reportFlow/Details/Details.tsx @@ -160,6 +160,15 @@ export const DetailsInner = ({ return () => clearInterval(interval) // Clean up the interval }, [validateFields]) + const [shouldSave, setShouldSave] = useState(false) + + useEffect(() => { + if (shouldSave && saveFiles) { + saveFiles(uploadedFiles) + setShouldSave(false) + } + }, [shouldSave, saveFiles, uploadedFiles]) + return ( <> @@ -241,11 +250,11 @@ export const DetailsInner = ({ fileOrigin={FileOrigin.Consumer} onRemoveFile={f => { setUploadedFiles(files => files?.filter(_ => _.id !== f.id)) - saveFiles((uploadedFiles ?? []).filter(_ => _.id !== f.id)) + setShouldSave(true) }} onNewFile={f => { setUploadedFiles(_ => [...(_ ?? []), f]) - saveFiles([...(uploadedFiles ?? []), f]) + setShouldSave(true) }} tooManyFilesError={showTooManyFilesError} />