Unify UI workflows and streamline fleet management
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export interface Confirmation {
|
||||
title: string;
|
||||
message: string;
|
||||
confirmLabel?: string;
|
||||
danger?: boolean;
|
||||
}
|
||||
export const confirmation = writable<Confirmation | null>(null);
|
||||
let resolvePending: ((accepted: boolean) => void) | null = null;
|
||||
|
||||
/** Resolve only from a deliberate confirm/cancel action; never default to acceptance. */
|
||||
export function confirmAction(options: Confirmation): Promise<boolean> {
|
||||
resolvePending?.(false);
|
||||
return new Promise(resolve => {
|
||||
resolvePending = resolve;
|
||||
confirmation.set(options);
|
||||
});
|
||||
}
|
||||
export function resolveConfirmation(accepted: boolean): void {
|
||||
const resolve = resolvePending;
|
||||
resolvePending = null;
|
||||
confirmation.set(null);
|
||||
resolve?.(accepted);
|
||||
}
|
||||
Reference in New Issue
Block a user