track modal close function on the prompt itself
parent
cba06b07b9
commit
60e4cb08c8
|
@ -30,8 +30,6 @@ const layoutStore = useLayoutStore();
|
|||
|
||||
const { currentPromptName } = storeToRefs(layoutStore);
|
||||
|
||||
const closeModal = ref<() => Promise<string>>();
|
||||
|
||||
const components = new Map<string, any>([
|
||||
["info", Info],
|
||||
["help", Help],
|
||||
|
@ -52,11 +50,6 @@ const components = new Map<string, any>([
|
|||
]);
|
||||
|
||||
watch(currentPromptName, (newValue) => {
|
||||
if (closeModal.value) {
|
||||
closeModal.value();
|
||||
closeModal.value = undefined;
|
||||
}
|
||||
|
||||
const modal = components.get(newValue!);
|
||||
if (!modal) return;
|
||||
|
||||
|
@ -67,7 +60,7 @@ watch(currentPromptName, (newValue) => {
|
|||
},
|
||||
});
|
||||
|
||||
closeModal.value = close;
|
||||
layoutStore.setCloseOnPrompt(close, newValue!);
|
||||
open();
|
||||
});
|
||||
|
||||
|
|
|
@ -29,6 +29,13 @@ export const useLayoutStore = defineStore("layout", {
|
|||
toggleShell() {
|
||||
this.showShell = !this.showShell;
|
||||
},
|
||||
setCloseOnPrompt(closeFunction: any, onPrompt: string) {
|
||||
let prompt = this.prompts.find((prompt) => prompt.prompt === onPrompt);
|
||||
if (prompt) {
|
||||
prompt.close = closeFunction;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
showHover(value: PopupProps | string) {
|
||||
if (typeof value !== "object") {
|
||||
this.prompts.push({
|
||||
|
@ -36,6 +43,7 @@ export const useLayoutStore = defineStore("layout", {
|
|||
confirm: null,
|
||||
action: undefined,
|
||||
props: null,
|
||||
close: null,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
@ -45,6 +53,7 @@ export const useLayoutStore = defineStore("layout", {
|
|||
confirm: value?.confirm,
|
||||
action: value?.action,
|
||||
props: value?.props,
|
||||
close: value?.close,
|
||||
});
|
||||
},
|
||||
showError() {
|
||||
|
@ -53,6 +62,7 @@ export const useLayoutStore = defineStore("layout", {
|
|||
confirm: null,
|
||||
action: undefined,
|
||||
props: null,
|
||||
close: null,
|
||||
});
|
||||
},
|
||||
showSuccess() {
|
||||
|
@ -61,10 +71,11 @@ export const useLayoutStore = defineStore("layout", {
|
|||
confirm: null,
|
||||
action: undefined,
|
||||
props: null,
|
||||
close: null,
|
||||
});
|
||||
},
|
||||
closeHovers() {
|
||||
this.prompts.shift();
|
||||
this.prompts.shift()?.close?.();
|
||||
},
|
||||
// easily reset state using `$reset`
|
||||
clearLayout() {
|
||||
|
|
|
@ -3,6 +3,7 @@ interface PopupProps {
|
|||
confirm?: any;
|
||||
action?: PopupAction;
|
||||
props?: any;
|
||||
close?: any;
|
||||
}
|
||||
|
||||
type PopupAction = (e: Event) => void;
|
||||
|
|
|
@ -753,8 +753,6 @@ const drop = async (event: DragEvent) => {
|
|||
};
|
||||
|
||||
const uploadInput = (event: Event) => {
|
||||
layoutStore.closeHovers();
|
||||
|
||||
let files = (event.currentTarget as HTMLInputElement)?.files;
|
||||
if (files === null) return;
|
||||
|
||||
|
|
Loading…
Reference in New Issue