cineclub-site/front/stores/loadingStore.ts

22 lines
514 B
TypeScript
Raw Normal View History

import { defineStore } from "pinia"
export const useLoadingStore = defineStore("loading", {
state: () => <{ [key: string]: "loading" | "done" | "error" }>{},
actions: {
markLoading(key: string) {
this.$patch({ [key]: "loading" })
},
markDone(key: string) {
this.$patch({ [key]: "done" })
},
markError(key: string) {
this.$patch({ [key]: "error" })
},
},
getters: {
isLoading: (state) => {
return (key: string) => state[key] === "loading"
},
},
})