From fc5945c95cdb8173bd6aeb16d616366dfc57c06f Mon Sep 17 00:00:00 2001 From: Hakadao Date: Sun, 22 Oct 2023 15:51:07 +0800 Subject: [PATCH] fix: stop endless data request when scrolling to bottom without login --- src/contentScripts/views/Home/components/Following.vue | 10 ++++++++++ src/contentScripts/views/Home/components/ForYou.vue | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/src/contentScripts/views/Home/components/Following.vue b/src/contentScripts/views/Home/components/Following.vue index 076ded81..b8d21520 100644 --- a/src/contentScripts/views/Home/components/Following.vue +++ b/src/contentScripts/views/Home/components/Following.vue @@ -9,6 +9,7 @@ const needToLoginFirst = ref(false) const containerRef = ref() as Ref const offset = ref('') const updateBaseline = ref('') +const noMoreContent = ref(false) onMounted(async () => { for (let i = 0; i < 3; i++) @@ -28,6 +29,9 @@ onUnmounted(() => { }) async function getFollowedUsersVideos() { + if (noMoreContent.value) + return + isLoading.value = true try { const response = await browser.runtime.sendMessage({ @@ -37,6 +41,12 @@ async function getFollowedUsersVideos() { updateBaseline: updateBaseline.value, }) + if (response.code === -101) { + noMoreContent.value = true + needToLoginFirst.value = true + return + } + if (response.code === 0) { offset.value = response.data.offset updateBaseline.value = response.data.update_baseline diff --git a/src/contentScripts/views/Home/components/ForYou.vue b/src/contentScripts/views/Home/components/ForYou.vue index 807126ae..731a5988 100644 --- a/src/contentScripts/views/Home/components/ForYou.vue +++ b/src/contentScripts/views/Home/components/ForYou.vue @@ -11,6 +11,7 @@ const isLoading = ref(true) const needToLoginFirst = ref(false) const containerRef = ref() as Ref const refreshIdx = ref(1) +const noMoreContent = ref(false) watch(() => settings.value.recommendationMode, (newValue) => { videoList.length = 0 @@ -57,6 +58,9 @@ onUnmounted(() => { }) async function getRecommendVideos() { + if (noMoreContent.value) + return + isLoading.value = true try { const response = await browser.runtime.sendMessage({ @@ -64,6 +68,11 @@ async function getRecommendVideos() { refreshIdx: refreshIdx.value++, }) + if (!response.data) { + noMoreContent.value = true + return + } + if (response.code === 0) { const resData = [] as ForYouVideoModel[]