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)
This commit is contained in:
吳元皓 2025-06-23 00:20:02 +08:00
parent 846c27293d
commit 5f37fb5049
2 changed files with 22 additions and 12 deletions

View File

@ -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;
});
</script>
<template>
<div
@ -183,7 +198,12 @@ const aiSummary = async () => {
</div>
</div>
</div>
<button><StarIcon /></button>
<button
@click="starArticle"
:class="'duration-300 transition-all' + {staredStatus && 'fill-blue-500 text-blue-500'"
>
<StarIcon />
</button>
</div>
</div>
</template>

View File

@ -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 {