feat(common): improve confirmation modal api

This commit is contained in:
2026-01-30 23:14:51 +01:00
parent 9deeb42cfd
commit 776783237b
7 changed files with 27 additions and 30 deletions

View File

@@ -10,8 +10,8 @@ export const useConfirmationModal = defineStore("confirmationModal", {
isOpen: false,
text: "",
onConfirm: null as (() => void) | null,
onClosed: null as (() => void) | null,
onCancel: null as (() => void) | null,
onClosed: null as ((choice: "confirm" | "cancel") => void) | null,
offsetY: MODAL_MAX_Y_OFFSET,
buttonsYOffset: 0,
modalButtonsYOffset: BUTTONS_MAX_Y_OFFSET,
@@ -24,7 +24,8 @@ export const useConfirmationModal = defineStore("confirmationModal", {
text: string;
onCancel?: () => void;
onConfirm?: () => void;
onClosed?: () => void;
onClosed?: (choice: "confirm" | "cancel") => void;
timeout?: number;
}) {
gsap.killTweensOf(this);
this.text = options.text;
@@ -58,10 +59,17 @@ export const useConfirmationModal = defineStore("confirmationModal", {
this,
{ modalButtonsYOffset: BUTTONS_MAX_Y_OFFSET },
{ modalButtonsYOffset: 0, duration: BUTTONS_TIME, ease: "none" },
);
)
.call(() => {
if (options.timeout) {
setTimeout(() => {
this.close("cancel");
}, options.timeout);
}
});
},
close() {
close(choice: "confirm" | "cancel") {
if (!this.isVisible || this.isClosing) return;
this.isClosing = true;
@@ -89,6 +97,7 @@ export const useConfirmationModal = defineStore("confirmationModal", {
.call(() => {
const closedCallback = this.onClosed;
// TODO: this.$reset() ?
this.isVisible = false;
this.isClosing = false;
this.isOpen = false;
@@ -96,7 +105,7 @@ export const useConfirmationModal = defineStore("confirmationModal", {
this.onConfirm = null;
this.onClosed = null;
closedCallback?.();
closedCallback?.(choice);
});
},
},