mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Implemented Discard changes button
This commit is contained in:
1 parent
681add852a
commit
28b705173e
17 files changed
+564
-43
No files matched your search
@@ -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',
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user