fix(app): rescue copy importable, trapping draft held, replace confirmed

The JSON rescue copy could not be restored in the app, a draft that traps
the engine left the tab on a reload screen and spent a recovery on every
read, and an unsaved or in-progress report could be lost by a reload
outside the editor or by New report / Import without warning.

Home import reads the copy (content-sniffed, 16 MiB cap, strict UTF-8)
through the core's draft.restore before any session change; a trapping
(draft, archive) pair is held in the resolution panel and only re-read
on Retry; ReplaceSessionDialog guards New report and Import; the
beforeunload guard is app-wide while unsaved. Supersedes BDR-055's
"never held" for `internal` only.
This commit is contained in:
bchanot committed 2026-10-17 12:58:57 +02:00
1 parent 9464651140
commit 9bd9acaf58
22 files changed
+1090 -68

No files matched your search

@@ -56,7 +56,13 @@ export default function HeldSessionPanel({
return (
<main className="p-4 sm:p-6 space-y-4 max-w-2xl">
<Notice tone="error">{t('session.held.notice')}</Notice>
<Notice tone="error">
{t(
held.some((item) => item.reason === 'engine_failure')
? 'session.held.notice_engine'
: 'session.held.notice',
)}
</Notice>
<ul className="space-y-3">
{held.map((item) => (
<li
@@ -0,0 +1,54 @@
import Button from '@/components/ui/Button'
import Dialog from '@/components/ui/Dialog'
import { CopyReportButton } from '@/components/report/CoreStoppedNotice'
import { isUnsaved, useReportStore } from '@/state/reportStore'
import { useT } from '@/i18n/useT'
export interface ReplaceSessionDialogProps {
open: boolean
onCancel: () => void
/** Leaves for the editor, where the bilan in progress is. */
onOpen: () => void
onConfirm: () => void
}
/**
* Asked before a new report or an import replaces the bilan in progress in this tab,
* saved or not: the practitioner cancels, goes back to it, or replaces it knowingly.
* An unsaved report (tab storage full) comes with its rescue copy.
*/
export default function ReplaceSessionDialog({
open,
onCancel,
onOpen,
onConfirm,
}: ReplaceSessionDialogProps) {
const t = useT()
const report = useReportStore((s) => s.report)
const unsaved = useReportStore(isUnsaved)
const body = report
? t('session.replace.body').replace(/\{animal\}/, () => report.animal.name)
: t('session.replace.body_unloaded')
return (
<Dialog open={open} onClose={onCancel} title={t('session.replace.title')} size="sm">
<p className="text-sm text-[var(--color-ink-muted)]">{body}</p>
{unsaved && (
<div className="mt-3 space-y-2">
<p className="text-sm">{t('session.replace.unsaved')}</p>
<CopyReportButton />
</div>
)}
<div className="mt-4 flex flex-wrap justify-end gap-2">
<Button type="button" variant="ghost" onClick={onCancel}>
{t('common.cancel')}
</Button>
<Button type="button" variant="secondary" onClick={onOpen}>
{t('session.replace.open')}
</Button>
<Button type="button" variant="danger" onClick={onConfirm}>
{t('session.replace.confirm')}
</Button>
</div>
</Dialog>
)
}