fix(app): editor store keeps an unanswered copy across mode changes, refuses unsaved submit
This commit is contained in:
1 parent
7f1d44065b
commit
b14509f221
7 files changed
+102
-4
No files matched your search
@@ -55,7 +55,8 @@ function conflictFrom(admin: OfficialSheetAdmin, state: EditorState): ConflictSt
|
||||
/** Reads the conflict; a failed read or an unparsable answer is the `unknown` variant. */
|
||||
export async function readConflict(api: StoreApi, session: number): Promise<void> {
|
||||
const state = api.get()
|
||||
api.set({ conflict: { status: 'reading' } })
|
||||
const reading: ConflictState = { status: 'reading' }
|
||||
api.set({ conflict: reading })
|
||||
let next: ConflictState
|
||||
try {
|
||||
const admin = await getOfficialSheetAdmin(requireClient(), state.sheetId ?? '')
|
||||
@@ -63,7 +64,10 @@ export async function readConflict(api: StoreApi, session: number): Promise<void
|
||||
} catch {
|
||||
next = { status: 'unknown' }
|
||||
}
|
||||
if (api.get().session === session) api.set({ conflict: next })
|
||||
// A dismissed dialog or a later save replaced the reading state: drop the late answer.
|
||||
if (api.get().session === session && api.get().conflict === reading) {
|
||||
api.set({ conflict: next })
|
||||
}
|
||||
}
|
||||
|
||||
interface Attempt {
|
||||
@@ -150,6 +154,7 @@ export async function submit(api: StoreApi, note?: string): Promise<SubmitOutcom
|
||||
const block = saveBlock(state)
|
||||
if (block) return blocked(block)
|
||||
if (state.staleBase) return blocked('stale_base')
|
||||
if (state.unsaved) return blocked('unsaved')
|
||||
api.set({ submitting: true })
|
||||
try {
|
||||
const args = {
|
||||
|
||||
Reference in new issue
Block a user