From eab4d5eb8b063e41509b6bd978ea9907a066c2c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Thu, 4 Jan 2024 20:55:15 -0500 Subject: [PATCH] feat(client-side): add function to update view count to clientside --- lib/client/science.ts | 3 +++ pages/story/[id]/[cidx]/index.vue | 2 ++ 2 files changed, 5 insertions(+) create mode 100644 lib/client/science.ts diff --git a/lib/client/science.ts b/lib/client/science.ts new file mode 100644 index 0000000..e630dba --- /dev/null +++ b/lib/client/science.ts @@ -0,0 +1,3 @@ +export const recordView = async (sid: number) => { + await useApiFetch(`/story/${sid}/set-viewed`); +}; diff --git a/pages/story/[id]/[cidx]/index.vue b/pages/story/[id]/[cidx]/index.vue index 14c5650..1a2bcc9 100644 --- a/pages/story/[id]/[cidx]/index.vue +++ b/pages/story/[id]/[cidx]/index.vue @@ -6,6 +6,7 @@ import storyInfo from "~/components/story/view/storyInfo.vue"; import chapterPicker from "~/components/story/view/chapterPicker.vue"; import { IUser } from "@models/user"; + import { recordView } from "@client/science"; const { useToken } = theme; const { token } = useToken(); @@ -24,6 +25,7 @@ useHead({ title: `"${story.value.title}" by ${story.value.author.username}${and.value}`, }); + await recordView(story.value._id!);