2024-12-01 19:20:21 -05:00
|
|
|
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) => {
|
2024-12-01 23:59:26 -05:00
|
|
|
return (uuid: string): Sticker | undefined => {
|
2024-12-01 19:20:21 -05:00
|
|
|
return state.stickers.find((sticker: Sticker) => sticker.uuid === uuid)
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-12-01 23:59:26 -05:00
|
|
|
state: (): State => {
|
2024-12-01 19:20:21 -05:00
|
|
|
return {
|
|
|
|
|
stickers: [],
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (import.meta.hot) {
|
|
|
|
|
import.meta.hot.accept(acceptHMRUpdate(useStickersStore, import.meta.hot))
|
|
|
|
|
}
|