fix(store): banner on a refused archive write, rescue download kept alive

This commit is contained in:
bchanot committed 2026-10-14 23:18:33 +02:00
1 parent a37c50b9ee
commit c97b0e7c67
4 files changed
+29 -8

No files matched your search

+10 -5
View File
@@ -39,9 +39,11 @@ import {
* The per-tab draft is mirrored through the persistence adapter and restored
* once the sheet is known; the archive an import brought along is kept
* beside the report and written only when the session starts or ends.
* A session text this page has not read, or whose safety copy failed, is
* never removed or overwritten implicitly: restore holds it, and a new
* session (new report, import) is refused until the practitioner resolves it.
* A session text whose safety copy failed is never removed or overwritten
* implicitly: restore holds it, and a new session (new report, import) is
* refused until the practitioner resolves it. A new session reads any draft
* this page never opened first: an unreadable one is set aside, a readable
* one is replaced as it always was.
*/
export type { NewReportDraft }
@@ -265,10 +267,13 @@ export function createReportStore(
archives: ArchivePersistence,
) {
/** The archive mirror is explicit: these actions are the session's edges. */
// The archive of this session could not be written: the tab's copy lacks it (banner).
let archiveRefused = false
const withArchive = (patch: Patch, archive: ReportArchiveEnvelope | null) => {
// A refused write must not leave the replaced session's archive beside the new draft:
// the next restore would pair them. That archive belongs to the session being replaced.
if (!archives.save(archive)) archives.save(null)
archiveRefused = !archives.save(archive)
if (archiveRefused) archives.save(null)
return { ...patch, archive }
}
@@ -386,7 +391,7 @@ export function createReportStore(
// The mirror follows the report only: an unrelated change never writes or removes the draft.
store.subscribe((state, prev) => {
if (state.report === prev.report) return
const failed = !persistence.save(state.report)
const failed = !persistence.save(state.report) || archiveRefused
if (failed !== state.saveFailed) store.setState({ saveFailed: failed })
})
return store