diff --git a/app.vue b/app.vue index 41705f0..00c8942 100644 --- a/app.vue +++ b/app.vue @@ -1,11 +1,20 @@ - + diff --git a/pages/login.vue b/pages/login.vue index 5566a7a..ccdba11 100644 --- a/pages/login.vue +++ b/pages/login.vue @@ -1,3 +1,3 @@ \ No newline at end of file diff --git a/pages/words.vue b/pages/words.vue new file mode 100644 index 0000000..d635d30 --- /dev/null +++ b/pages/words.vue @@ -0,0 +1,33 @@ + + + + + \ No newline at end of file diff --git a/service/user.service.ts b/service/user.service.ts new file mode 100644 index 0000000..97fffea --- /dev/null +++ b/service/user.service.ts @@ -0,0 +1,15 @@ +import { UserResponseDTO } from "~/netcode/events/dto/userresponse.dto"; + +export async function fetchUser(id: string) { + const config = useRuntimeConfig(); + const data = await useFetch(config.public.endpoint + `/users/` + id, { + credentials: "include", + }).then(_d => { + if (_d.data.value) { + _d.data.value = new UserResponseDTO(_d.data.value) + } + return _d + }) + + return data +} diff --git a/store/user.store.ts b/store/user.store.ts new file mode 100644 index 0000000..82ca0fc --- /dev/null +++ b/store/user.store.ts @@ -0,0 +1,40 @@ +import { defineStore } from "pinia"; +import { UserResponseDTO } from "~/netcode/events/dto/userresponse.dto"; + +export const useUserStore = defineStore("user", { + state: () => ({ + users: {} as Record, + self: null as UserResponseDTO | null, + has_contacted: false + }), + actions: { + async fetchUser(id: string) { + if (id in this.users) { + return this.users[id] + } + const config = useRuntimeConfig(); + const data = await useFetch(config.public.endpoint + `/users/` + id, { + credentials: "include", + immediate: true + }) + if (data.data.value) { + this.users[data.data.value.id] = data.data.value + } + return data.data.value + }, + async whoami() { + const config = useRuntimeConfig(); + const req = await useFetch(config.public.endpoint + "/whoami", { + credentials: "include", + server: false, + immediate: true, + onResponse: (data) => { + this.self = data.response._data + this.has_contacted = true + }, + lazy: true + }) + return req; + } + }, +}); \ No newline at end of file diff --git a/store/word.store.ts b/store/word.store.ts new file mode 100644 index 0000000..34bb2e6 --- /dev/null +++ b/store/word.store.ts @@ -0,0 +1,39 @@ +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 + } + }, +}); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index a746f2a..6301ea1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,4 +1,9 @@ { // https://nuxt.com/docs/guide/concepts/typescript - "extends": "./.nuxt/tsconfig.json" -} + "extends": "./.nuxt/tsconfig.json", + "compilerOptions": { + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "strictPropertyInitialization": false, + } +} \ No newline at end of file