import {acceptHMRUpdate, defineStore} from 'pinia' import type {Sticker} from "@/stores/stickerStore"; export interface State { stickers: Sticker[]; } export const useStickersStore = defineStore('stickers', { actions: { async fetch(uuid: string) { if (this.getSticker(uuid)) { return; } // TODO: Check if we have it already and if it's stale. const response = await fetch( `/api/sticker/${uuid}`, ); const json = await response.json(); this.stickers.push(json); }, }, getters: { getSticker: (state: State) => { return (uuid: string): Sticker | null => { return state.stickers.find((sticker: Sticker) => sticker.uuid === uuid) }; }, }, state: () => { return { stickers: [], }; }, }) if (import.meta.hot) { import.meta.hot.accept(acceptHMRUpdate(useStickersStore, import.meta.hot)) }