Implemented Discard changes button

This commit is contained in:
patben8 committed 2026-10-01 10:54:27 +02:00
1 parent 681add852a
commit 28b705173e
17 files changed
+564 -43

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
import { api } from '../api'
import { askConfirm } from './confirm'
/**
* Ask before an action that throws away unsaved edits — opening a different
* library replaces the adapter that holds them. Resolves true when there is
* nothing to lose or the user agreed.
*
* Reads the state fresh rather than from a cached query: the two places that
* switch library (the sidebar header and the status bar) must not disagree, and
* the status bar's button used to skip the question entirely.
*/
export async function confirmDiscardUnsaved(): Promise<boolean> {
const dirty = await api
.state()
.then((s) => s.dirty)
.catch(() => false) // no library loaded: nothing to lose
if (!dirty) return true
return askConfirm({
title: 'Discard unsaved changes?',
body: 'You have unsaved changes. Opening a different library will discard them.',
confirmLabel: 'Discard and switch',
})
}