import { defineStore } from 'pinia' import { useUserStore } from "@/stores/userStore"; export const useStickerStore = defineStore('sticker', { actions: { async fetch(uuid: string) { // 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); this.sticker = json; }, async put(uuid: string) { const response = await fetch( `/api/sticker/${uuid}`, { body: JSON.stringify(this.sticker), method: 'PUT', }, ); const json = await response.json(); // Disable this for now so we don't clobber the new owner. // this.sticker = json; }, setOwner(user) { if (!this.sticker) { return; } // this.sticker.owner = user.username; does not work this.sticker = { ...this.sticker, owner: user.username, } this.put(this.sticker.uuid); const userStore = useUserStore(); userStore.addSticker(this.sticker); }, }, state: () => { return { // stickers: [], sticker: null, }; }, })