feat(editor): repair out-of-frame annotations when attaching a drawing
This commit is contained in:
1 parent
4ab85adeb0
commit
3776a33b79
22 files changed
+1277
-19
No files matched your search
@@ -6,11 +6,13 @@ import {
|
||||
type Step,
|
||||
type UploadError,
|
||||
} from './drawingUpload'
|
||||
import type { RepairOffer } from './repair'
|
||||
|
||||
export type UploadUi =
|
||||
| { phase: 'idle' }
|
||||
| { phase: 'working' }
|
||||
| { phase: 'cleaning'; candidate: Candidate }
|
||||
| { phase: 'repair'; offer: RepairOffer }
|
||||
| { phase: 'failed'; error: UploadError }
|
||||
| { phase: 'done' }
|
||||
|
||||
@@ -21,6 +23,10 @@ export interface DrawingUpload {
|
||||
/** « Nettoyer et utiliser cette version ». */
|
||||
confirmCleaning: () => Promise<void>
|
||||
cancelCleaning: () => void
|
||||
/** The repair dialog applied: the drawing is attached with the repaired annotations. */
|
||||
finishRepair: () => void
|
||||
/** « Annuler »: the document stays as it is, the drawing stays uploaded and held. */
|
||||
cancelRepair: () => void
|
||||
}
|
||||
|
||||
/** The upload of one view's drawing as a small state machine for its section. */
|
||||
@@ -29,6 +35,8 @@ export function useDrawingUpload(viewId: string): DrawingUpload {
|
||||
const settle = (result: Step<unknown>) => {
|
||||
if (result.ok) setUi({ phase: 'done' })
|
||||
else if (result.error.code === 'stale') setUi({ phase: 'idle' })
|
||||
else if (result.error.code === 'repair')
|
||||
setUi({ phase: 'repair', offer: result.error.offer })
|
||||
else setUi({ phase: 'failed', error: result.error })
|
||||
}
|
||||
const send = async (candidate: Candidate) => {
|
||||
@@ -49,5 +57,11 @@ export function useDrawingUpload(viewId: string): DrawingUpload {
|
||||
if (ui.phase === 'cleaning') await send(ui.candidate)
|
||||
},
|
||||
cancelCleaning: () => setUi({ phase: 'idle' }),
|
||||
finishRepair: () => setUi({ phase: 'done' }),
|
||||
cancelRepair: () => {
|
||||
if (ui.phase !== 'repair') return
|
||||
const { refusal } = ui.offer
|
||||
setUi({ phase: 'failed', error: { code: 'frame', refusal } })
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user