From 5f37fb5049b7fda790b1ff5b454abaddba1eb8e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B3=E5=85=83=E7=9A=93?= Date: Mon, 23 Jun 2025 00:20:02 +0800 Subject: [PATCH 1/3] Update news view to check if the user has faved a news article or not & the star button finally do something for the two weeks that is there. Also done SOME user auth logic (aka revert bac kthe changes) --- components/app/windows/newsView.vue | 22 +++++++++++++++++++++- components/blurPageBeforeLogin.vue | 12 +----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/components/app/windows/newsView.vue b/components/app/windows/newsView.vue index fe9b454..5e37e3b 100644 --- a/components/app/windows/newsView.vue +++ b/components/app/windows/newsView.vue @@ -31,6 +31,7 @@ const isGenerating = ref(false); const summaryText = ref(""); const { locale } = useI18n(); const likeart = ref([]); +const staredStatus = ref(false); // Translating logic const translateText = ref(false); const translatedBefore = ref(false); @@ -105,6 +106,20 @@ const aiSummary = async () => { isGenerating.value = false; } }; + +const starArticle = async () => { + const req = await fetch(`/user/${slug}/fav`); + const res = await req.json(); + if (req.status === success) { + staredStatus.value = req.starred; + } +}; + +onMounted(async () => { + const req = await fetch(`/user/${slug}/star`); + const res = await req.json(); + staredStatus.value = req; +}); diff --git a/components/blurPageBeforeLogin.vue b/components/blurPageBeforeLogin.vue index 1155a7e..e89aa44 100644 --- a/components/blurPageBeforeLogin.vue +++ b/components/blurPageBeforeLogin.vue @@ -7,16 +7,6 @@ const error = ref(false); const errorMsg = ref(""); const emit = defineEmits(["windowopener", "error", "loadValue"]); -/** - * return { - userAccount: fetchViaSQL[0].username, - firstName: fetchViaSQL[0].firstName, - requested_action: "CONTINUE", - current_spot: "KEEP_LOGIN", - email: fetchViaSQL[0].email, - avatarURL: fetchViaSQL[0].avatarurl, - }; - */ try { // 喔 我沒有加 await :( 難怪有問題 const { data, error: sendError } = await useFetch( @@ -25,7 +15,7 @@ try { if (sendError.value) { error.value = true; } - if (data.requested_action === "KEEP_LOGIN") { + if (data.requested_action === "CONTINUE") { if (data.userAccount && data.userAccount.length !== 0) { allowed.value = true; } else { From 87d5620e34f16d35bbed66b039a48bd45a1155f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B3=E5=85=83=E7=9A=93?= Date: Mon, 23 Jun 2025 00:55:49 +0800 Subject: [PATCH 2/3] =?UTF-8?q?Forgot=20useFetch=20uses=20.value=20?= =?UTF-8?q?=F0=9F=A4=A6=E2=80=8D=E2=99=82=EF=B8=8F=F0=9F=92=80=F0=9F=99=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/blurPageBeforeLogin.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/blurPageBeforeLogin.vue b/components/blurPageBeforeLogin.vue index e89aa44..c6e092b 100644 --- a/components/blurPageBeforeLogin.vue +++ b/components/blurPageBeforeLogin.vue @@ -15,8 +15,8 @@ try { if (sendError.value) { error.value = true; } - if (data.requested_action === "CONTINUE") { - if (data.userAccount && data.userAccount.length !== 0) { + if (data.value.requested_action === "CONTINUE") { + if (data.value.userAccount && data.value.userAccount.length !== 0) { allowed.value = true; } else { allowed.value = false; From bf4e6956768a666bd6d349fdb936225060cb450e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B3=E5=85=83=E7=9A=93?= Date: Mon, 23 Jun 2025 01:10:24 +0800 Subject: [PATCH 3/3] =?UTF-8?q?What=20is=20this=3F=20undefined:undefined?= =?UTF-8?q?=3F=20A=20recipe=20for=20debugging=20hell.=20(I=20used=20GitHub?= =?UTF-8?q?=20Copilot=20for=20this=20debugging=20session.),=20Also=20chang?= =?UTF-8?q?es=20some=20broken=20stuff=20like=20const=20res=20=3D=20req.jso?= =?UTF-8?q?n()=20req.status=20=3D=3D=3D=20"success",=20what=20even=20is=20?= =?UTF-8?q?that=20=F0=9F=99=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/app/windows/newsView.vue | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/components/app/windows/newsView.vue b/components/app/windows/newsView.vue index 5e37e3b..1fbb11a 100644 --- a/components/app/windows/newsView.vue +++ b/components/app/windows/newsView.vue @@ -108,17 +108,18 @@ const aiSummary = async () => { }; const starArticle = async () => { - const req = await fetch(`/user/${slug}/fav`); + const buildUrl = `/user/${slug}/fav`; + const req = await fetch(buildUrl); const res = await req.json(); - if (req.status === success) { - staredStatus.value = req.starred; + if (res.status === "success") { + staredStatus.value = res.starred; } }; onMounted(async () => { const req = await fetch(`/user/${slug}/star`); const res = await req.json(); - staredStatus.value = req; + staredStatus.value = res; });