fix(editor): read-only undo, upload session check, restore and submit guards
This commit is contained in:
1 parent
5979cd59ec
commit
05c9b3e10b
20 files changed
+102
-33
No files matched your search
@@ -147,10 +147,12 @@ export async function registerAndUpload(
|
||||
export async function downloadAndHold(
|
||||
assetId: string,
|
||||
sha256: string,
|
||||
live: () => boolean,
|
||||
): Promise<Step<null>> {
|
||||
const client = getSupabaseClient()
|
||||
if (!client) return fail({ code: 'sheet', kind: 'unavailable' })
|
||||
const fetched = await fetchDrawing(client, { asset_id: assetId, sha256 })
|
||||
if (!live()) return fail({ code: 'stale' })
|
||||
if (!fetched.ok) return fail({ code: 'catalogue', failure: fetched.failure })
|
||||
const held = useEditorStore.getState().addDrawing(fetched.drawing)
|
||||
if (held.ok) return done(null)
|
||||
@@ -193,7 +195,7 @@ export async function uploadDrawing(
|
||||
const stored = await registerAndUpload(sheetId, drawing)
|
||||
if (!live()) return fail({ code: 'stale' })
|
||||
if (!stored.ok) return stored
|
||||
const held = await downloadAndHold(stored.value, drawing.sha256)
|
||||
const held = await downloadAndHold(stored.value, drawing.sha256, live)
|
||||
if (!live()) return fail({ code: 'stale' })
|
||||
return held.ok ? attachToView(viewId, stored.value) : held
|
||||
}
|
||||
@@ -31,7 +31,7 @@ function replacedPatch(
|
||||
documentText: text,
|
||||
previewState: next,
|
||||
handleVersion: state.handleVersion + 1,
|
||||
unsaved: !sameDocument(text, state.savedText),
|
||||
unsaved: state.staleBase || !sameDocument(text, state.savedText),
|
||||
undo: history.undo,
|
||||
redo: history.redo,
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ export async function submit(api: StoreApi, note?: string): Promise<SubmitOutcom
|
||||
}
|
||||
const reviewId = await submitSheetReview(requireClient(), args)
|
||||
if (api.get().session !== state.session) return blocked('session_changed')
|
||||
api.set({ submitting: false })
|
||||
api.set({ submitting: false, canEdit: false })
|
||||
return { ok: true, reviewId }
|
||||
} catch (error) {
|
||||
return failedSubmit(api, state.session, error)
|
||||
|
||||
@@ -174,7 +174,7 @@ function restoredPatch(
|
||||
next: PreviewState,
|
||||
attached: Attached,
|
||||
): Partial<EditorState> {
|
||||
const text = copyText(copy)
|
||||
const text = JSON.stringify(next.document)
|
||||
return {
|
||||
documentText: text,
|
||||
previewState: next,
|
||||
@@ -183,7 +183,7 @@ function restoredPatch(
|
||||
drawingFailures: { ...now.drawingFailures, ...attached.failures },
|
||||
savedRevision: copy.revision,
|
||||
staleBase: copy.revision < now.savedRevision,
|
||||
unsaved: !sameDocument(text, now.savedText),
|
||||
unsaved: copy.revision < now.savedRevision || !sameDocument(text, now.savedText),
|
||||
...emptyHistory(),
|
||||
...NO_RECOVERY,
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user