Skip to content

Commit

Permalink
Merge pull request #915 from betagouv/main
Browse files Browse the repository at this point in the history
MEP [TRELLO-2590] Fix autosave, it was messing with attachements (#914)
  • Loading branch information
charlescd authored Sep 19, 2024
2 parents 696965c + d010f88 commit 6f72251
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions website/src/components_feature/reportFlow/Details/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<Animate autoScrollTo={false}>
Expand Down Expand Up @@ -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}
/>
Expand Down

0 comments on commit 6f72251

Please sign in to comment.