diff --git a/package.json b/package.json index f1cea7e..d48a1ae 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "devDependencies": { "@babel/core": "^7.23.9", "@babel/eslint-parser": "^7.23.10", - "@bakaso/fkclient": "^1.6.0", + "@bakaso/fkclient": "^1.6.1", "@types/node": "^20.11.16", "@vue/cli-plugin-babel": "^5.0.8", "@vue/cli-plugin-eslint": "^5.0.8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c79783d..27bf880 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,8 +12,8 @@ devDependencies: specifier: ^7.23.10 version: 7.23.10(@babel/core@7.23.9)(eslint@8.56.0) '@bakaso/fkclient': - specifier: ^1.6.0 - version: 1.6.0 + specifier: ^1.6.1 + version: 1.6.1 '@types/node': specifier: ^20.11.16 version: 20.11.16 @@ -1485,8 +1485,8 @@ packages: to-fast-properties: 2.0.0 dev: true - /@bakaso/fkclient@1.6.0: - resolution: {integrity: sha512-s2iu0u9OuB+rCGntxdRUJEATOl0q1E/Zj62uuoBHKH0xjvDshZ8OW9CAzp5rmNUQFzAVIWZoDqwMzqpLM3uJTg==} + /@bakaso/fkclient@1.6.1: + resolution: {integrity: sha512-E+OUnG+C5qv/aI8hzHJZ8VH3JZn2B00mNiRr+em6ZVaAaFx71/GHbVvBAby/qhz2QQ4qZiQZWCrHs0atYs/Tdw==} dev: true /@eslint-community/eslint-utils@4.4.0(eslint@8.56.0): diff --git a/src/hooks/useAPIHandlers.js b/src/hooks/useAPIHandlers.ts similarity index 81% rename from src/hooks/useAPIHandlers.js rename to src/hooks/useAPIHandlers.ts index 5b87b0f..b37deab 100644 --- a/src/hooks/useAPIHandlers.js +++ b/src/hooks/useAPIHandlers.ts @@ -1,8 +1,10 @@ import { getProps } from "@/utils" import { useStore } from "vuex" import { useToast } from "vue-toast-notification" +import type { Post, Thread } from "@/store" +import type FKClient from "@bakaso/fkclient" -export default function useAPIHandlers(API) { +export default function useAPIHandlers(API: FKClient) { const store = useStore() const toast = useToast() @@ -23,12 +25,12 @@ export default function useAPIHandlers(API) { store.commit("updateThreadList", { ...getProps(what, ["boardName", "count", "page"]), - payload: data.map(thread => thread.id), + payload: data.map((thread: Thread) => thread.id), }) store.commit("updateThreads", data) - for (let thread of data) { + for (const thread of data) { store.commit("updatePostList", { threadId: thread.id, payload: [thread.head.id], @@ -64,13 +66,13 @@ export default function useAPIHandlers(API) { // Feed store.commit("updateFeed", { ...getProps(what, ["boardName", "count", "page"]), - payload: data.map(post => post.id), + payload: data.map((post: Post) => post.id), }) } else { // Thread store.commit("updatePostList", { ...getProps(what, ["threadId", "count", "page"]), - payload: data.map(post => post.id), + payload: data.map((post: Post) => post.id), }) } @@ -88,6 +90,10 @@ export default function useAPIHandlers(API) { API.addInMessageListener( ({ event, error }) => "created" === event && !error, ({ type, data }) => { + if (!type) { + return + } + const action = ({ board: "pushBoard", post: "pushPost", @@ -101,7 +107,13 @@ export default function useAPIHandlers(API) { API.addInMessageListener( ({ event }) => "deleted" === event, ({ type, data }) => { + if (!type) { + return + } + const action = ({ + // TODO: Handle board deletion + board: undefined, post: "unregisterPost", thread: "unregisterThread", })[type] @@ -113,7 +125,7 @@ export default function useAPIHandlers(API) { API.addInMessageListener( ({ error }) => Boolean(error), ({ error }) => { - const text = error.description || `Error ${error.message} occured` || "Unexpected error occured" + const text = error!.description || `Error ${error!.message} occured` || "Unexpected error occured" toast.error(text, { position: "top-right" }) } ) diff --git a/src/store/index.ts b/src/store/index.ts index f16892d..42784fd 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -4,14 +4,14 @@ type Board = { name: string } -type Thread = { +export type Thread = { id: number boardName: Board["name"] head: Post posts: number } -type Post = { +export type Post = { id: number threadId: Thread["id"] }