init
This commit is contained in:
commit
d761a10bf7
102 changed files with 4761 additions and 0 deletions
39
lib/stores/modal.ts
Normal file
39
lib/stores/modal.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { browser } from '$app/environment';
|
||||
import Modal from '$lib/models/modal';
|
||||
import { toast } from '@zerodevx/svelte-toast';
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
interface ModalStore {
|
||||
visible: boolean;
|
||||
type?: Modal | null;
|
||||
data?: any;
|
||||
warn?: boolean | null;
|
||||
showModal: (type: Modal, data?: any) => void;
|
||||
hideModal: (noConfirm?: boolean | null) => void;
|
||||
disableWarn: () => void;
|
||||
}
|
||||
|
||||
export const modalStore = browser
|
||||
? writable({
|
||||
visible: false,
|
||||
type: null,
|
||||
data: null,
|
||||
warn: null,
|
||||
showModal: (type: Modal, data?: any) => {
|
||||
modalStore?.update((store) => ({ ...store, type, data, visible: true, warn: true }));
|
||||
},
|
||||
hideModal: (noConfirm) => {
|
||||
modalStore?.update((store) => {
|
||||
if (!noConfirm && store.type === Modal.EditWidget && store.warn) {
|
||||
toast.push('Click again to dismiss.');
|
||||
return { ...store, warn: false };
|
||||
}
|
||||
return { ...store, type: null, data: null, visible: false, warn: false };
|
||||
});
|
||||
},
|
||||
disableWarn: () => {
|
||||
modalStore?.update((store) => ({ ...store, warn: false }));
|
||||
},
|
||||
} as ModalStore)
|
||||
: null;
|
Loading…
Add table
Add a link
Reference in a new issue