import { defineStore } from "pinia"; import { WordResponseDTO } from "~/netcode/events/dto/wordresponse.dto"; export const useWordStore = defineStore("word", { state: () => ({ words: {} as Record, }), actions: { async fetchWordList() { const config = useRuntimeConfig(); const data = await useFetch(config.public.endpoint + `/words/all`, { credentials: "include", }) if (data.data.value && !data.error.value) { for (const word of data.data.value) { this.words[word.id] = word } } return data }, async enableWord(id: number) { const config = useRuntimeConfig(); const data = await $fetch(config.public.endpoint + `/words/` + id + "/enable", { credentials: "include", method: "PUT" }) return data }, async disableWord(id: number) { const config = useRuntimeConfig(); const data = await $fetch(config.public.endpoint + `/words/` + id + "/disable", { credentials: "include", method: "PUT" }) return data } }, });