el.xwx.moe/store/modals.ts
2023-06-15 02:04:54 +03:30

49 lines
994 B
TypeScript

import {
AccountSettings,
CollectionIncludingMembers,
LinkIncludingShortenedCollectionAndTags,
} from "@/types/global";
import { create } from "zustand";
type Modal =
| {
modal: "ACCOUNT";
state: boolean;
active: AccountSettings;
defaultIndex?: number;
}
| {
modal: "LINK";
state: boolean;
method: "CREATE";
active?: LinkIncludingShortenedCollectionAndTags;
}
| {
modal: "LINK";
state: boolean;
method: "UPDATE";
active: LinkIncludingShortenedCollectionAndTags;
}
| {
modal: "COLLECTION";
state: boolean;
method: "CREATE" | "UPDATE";
active: CollectionIncludingMembers;
defaultIndex?: number;
}
| null;
type ModalsStore = {
modal: Modal;
setModal: (modal: Modal) => void;
};
const useLocalSettingsStore = create<ModalsStore>((set) => ({
modal: null,
setModal: (modal: Modal) => {
set({ modal });
},
}));
export default useLocalSettingsStore;