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