mirror of
https://github.com/BewlyBewly/BewlyBewly.git
synced 2025-04-14 13:15:29 +00:00
refactor: improve components load method, and improve provide app
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import type { Ref } from 'vue'
|
||||
import type { DataItem as MomentItem, MomentResult } from '~/models/moment/moment'
|
||||
import emitter from '~/utils/mitt'
|
||||
|
||||
const videoList = reactive<MomentItem[]>([])
|
||||
const isLoading = ref<boolean>(false)
|
||||
@@ -10,28 +9,49 @@ const containerRef = ref<HTMLElement>() as Ref<HTMLElement>
|
||||
const offset = ref<string>('')
|
||||
const updateBaseline = ref<string>('')
|
||||
const noMoreContent = ref<boolean>(false)
|
||||
const noMoreContentWarning = ref<boolean>(false)
|
||||
const { handleReachBottom, handlePageRefresh } = useBewlyApp()
|
||||
|
||||
function initPageAction() {
|
||||
handleReachBottom.value = async () => {
|
||||
if (isLoading.value)
|
||||
return
|
||||
if (noMoreContent.value) {
|
||||
noMoreContentWarning.value = true
|
||||
return
|
||||
}
|
||||
for (let i = 0; i < 3; i++)
|
||||
await getFollowedUsersVideos()
|
||||
}
|
||||
handlePageRefresh.value = async () => {
|
||||
videoList.length = 0
|
||||
offset.value = ''
|
||||
noMoreContent.value = false
|
||||
noMoreContentWarning.value = false
|
||||
for (let i = 0; i < 3; i++)
|
||||
await getFollowedUsersVideos()
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
for (let i = 0; i < 3; i++)
|
||||
await getFollowedUsersVideos()
|
||||
|
||||
emitter.off('reachBottom')
|
||||
emitter.on('reachBottom', async () => {
|
||||
if (!isLoading.value) {
|
||||
for (let i = 0; i < 3; i++)
|
||||
await getFollowedUsersVideos()
|
||||
}
|
||||
})
|
||||
initPageAction()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
emitter.off('reachBottom')
|
||||
onActivated(() => {
|
||||
initPageAction()
|
||||
})
|
||||
|
||||
async function getFollowedUsersVideos() {
|
||||
if (noMoreContent.value)
|
||||
return
|
||||
|
||||
if (offset.value === '0') {
|
||||
noMoreContent.value = true
|
||||
return
|
||||
}
|
||||
|
||||
isLoading.value = true
|
||||
try {
|
||||
const response: MomentResult = await browser.runtime.sendMessage({
|
||||
@@ -116,6 +136,9 @@ function jumpToLoginPage() {
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<!-- no more content -->
|
||||
<Empty v-if="noMoreContentWarning" class="pb-4" :description="$t('common.no_more_content')" />
|
||||
|
||||
<Transition name="fade">
|
||||
<Loading v-if="isLoading" />
|
||||
</Transition>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
import type { Ref } from 'vue'
|
||||
import type { AppForYouResult, Item as AppVideoItem } from '~/models/video/appForYou'
|
||||
import type { Item as VideoItem, forYouResult } from '~/models/video/forYou'
|
||||
import emitter from '~/utils/mitt'
|
||||
import { accessKey, settings } from '~/logic'
|
||||
import { LanguageType } from '~/enums/appEnums'
|
||||
import { TVAppKey } from '~/utils/authProvider'
|
||||
@@ -14,6 +13,33 @@ const needToLoginFirst = ref<boolean>(false)
|
||||
const containerRef = ref<HTMLElement>() as Ref<HTMLElement>
|
||||
const refreshIdx = ref<number>(1)
|
||||
const noMoreContent = ref<boolean>(false)
|
||||
const { handleReachBottom, handlePageRefresh } = useBewlyApp()
|
||||
|
||||
function initPageAction() {
|
||||
handleReachBottom.value = async () => {
|
||||
if (!isLoading.value) {
|
||||
if (settings.value.recommendationMode === 'web') {
|
||||
getRecommendVideos()
|
||||
}
|
||||
else {
|
||||
for (let i = 0; i < 3; i++)
|
||||
await getAppRecommendVideos()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handlePageRefresh.value = async () => {
|
||||
videoList.length = 0
|
||||
appVideoList.length = 0
|
||||
if (settings.value.recommendationMode === 'web') {
|
||||
await getRecommendVideos()
|
||||
}
|
||||
else {
|
||||
for (let i = 0; i < 3; i++)
|
||||
await getAppRecommendVideos()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => settings.value.recommendationMode, (newValue) => {
|
||||
videoList.length = 0
|
||||
@@ -41,22 +67,11 @@ onMounted(async () => {
|
||||
}
|
||||
}, 200)
|
||||
|
||||
emitter.off('reachBottom')
|
||||
emitter.on('reachBottom', async () => {
|
||||
if (!isLoading.value) {
|
||||
if (settings.value.recommendationMode === 'web') {
|
||||
getRecommendVideos()
|
||||
}
|
||||
else {
|
||||
for (let i = 0; i < 3; i++)
|
||||
await getAppRecommendVideos()
|
||||
}
|
||||
}
|
||||
})
|
||||
initPageAction()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
emitter.off('reachBottom')
|
||||
onActivated(() => {
|
||||
initPageAction()
|
||||
})
|
||||
|
||||
async function getRecommendVideos() {
|
||||
|
||||
@@ -7,8 +7,7 @@ import { settings } from '~/logic'
|
||||
import emitter from '~/utils/mitt'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const handleBackToTop = inject('handleBackToTop') as (targetScrollTop: number) => void
|
||||
const { handleBackToTop, handlePageRefresh } = useBewlyApp()
|
||||
|
||||
const rankingTypes = computed((): RankingType[] => {
|
||||
return [
|
||||
@@ -46,6 +45,16 @@ const videoList = reactive<RankingVideoItem[]>([])
|
||||
const PgcList = reactive<RankingPgcItem[]>([])
|
||||
const shouldMoveAsideUp = ref<boolean>(false)
|
||||
|
||||
function initPageAction() {
|
||||
handlePageRefresh.value = async () => {
|
||||
videoList.length = 0
|
||||
PgcList.length = 0
|
||||
if (isLoading.value)
|
||||
return
|
||||
getRankingVideos()
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => activatedRankingType.value.id, () => {
|
||||
handleBackToTop(settings.value.useSearchPageModeOnHomePage ? 510 : 0)
|
||||
|
||||
@@ -72,6 +81,11 @@ onMounted(() => {
|
||||
})
|
||||
|
||||
getRankingVideos()
|
||||
initPageAction()
|
||||
})
|
||||
|
||||
onActivated(() => {
|
||||
initPageAction()
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import type { Ref } from 'vue'
|
||||
import type { DataItem as MomentItem, MomentResult } from '~/models/moment/moment'
|
||||
import emitter from '~/utils/mitt'
|
||||
|
||||
const momentList = reactive<MomentItem[]>([])
|
||||
const isLoading = ref<boolean>(false)
|
||||
@@ -10,28 +9,52 @@ const containerRef = ref<HTMLElement>() as Ref<HTMLElement>
|
||||
const offset = ref<string>('')
|
||||
const updateBaseline = ref<string>('')
|
||||
const noMoreContent = ref<boolean>(false)
|
||||
const noMoreContentWarning = ref<boolean>(false)
|
||||
const { handleReachBottom, handlePageRefresh } = useBewlyApp()
|
||||
|
||||
function initPageAction() {
|
||||
handleReachBottom.value = async () => {
|
||||
if (isLoading.value)
|
||||
return
|
||||
if (noMoreContent.value) {
|
||||
noMoreContentWarning.value = true
|
||||
return
|
||||
}
|
||||
for (let i = 0; i < 3; i++)
|
||||
await getFollowedUsersVideos()
|
||||
}
|
||||
handlePageRefresh.value = async () => {
|
||||
offset.value = ''
|
||||
momentList.length = 0
|
||||
noMoreContent.value = false
|
||||
noMoreContentWarning.value = false
|
||||
if (isLoading.value)
|
||||
return
|
||||
for (let i = 0; i < 3; i++)
|
||||
await getFollowedUsersVideos()
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
for (let i = 0; i < 3; i++)
|
||||
await getFollowedUsersVideos()
|
||||
|
||||
emitter.off('reachBottom')
|
||||
emitter.on('reachBottom', async () => {
|
||||
if (!isLoading.value) {
|
||||
for (let i = 0; i < 3; i++)
|
||||
await getFollowedUsersVideos()
|
||||
}
|
||||
})
|
||||
initPageAction()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
emitter.off('reachBottom')
|
||||
onActivated(() => {
|
||||
initPageAction()
|
||||
})
|
||||
|
||||
async function getFollowedUsersVideos() {
|
||||
if (noMoreContent.value)
|
||||
return
|
||||
|
||||
if (offset.value === '0') {
|
||||
noMoreContent.value = true
|
||||
return
|
||||
}
|
||||
|
||||
isLoading.value = true
|
||||
try {
|
||||
const response: MomentResult = await browser.runtime.sendMessage({
|
||||
@@ -115,6 +138,9 @@ function jumpToLoginPage() {
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<!-- no more content -->
|
||||
<Empty v-if="noMoreContentWarning" class="pb-4" :description="$t('common.no_more_content')" />
|
||||
|
||||
<Transition name="fade">
|
||||
<Loading v-if="isLoading" />
|
||||
</Transition>
|
||||
|
||||
@@ -1,25 +1,34 @@
|
||||
<script setup lang="ts">
|
||||
import type { Ref } from 'vue'
|
||||
import type { TrendingResult, List as VideoItem } from '~/models/video/trending'
|
||||
import emitter from '~/utils/mitt'
|
||||
|
||||
const videoList = reactive<VideoItem[]>([])
|
||||
const isLoading = ref<boolean>(false)
|
||||
const containerRef = ref<HTMLElement>() as Ref<HTMLElement>
|
||||
const pn = ref<number>(1)
|
||||
const { handleReachBottom, handlePageRefresh } = useBewlyApp()
|
||||
|
||||
function initPageAction() {
|
||||
handleReachBottom.value = async () => {
|
||||
if (!isLoading.value)
|
||||
await getTrendingVideos()
|
||||
}
|
||||
|
||||
handlePageRefresh.value = async () => {
|
||||
videoList.length = 0
|
||||
pn.value = 1
|
||||
await getTrendingVideos()
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await getTrendingVideos()
|
||||
|
||||
emitter.off('reachBottom')
|
||||
emitter.on('reachBottom', async () => {
|
||||
if (!isLoading.value)
|
||||
await getTrendingVideos()
|
||||
})
|
||||
initPageAction()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
emitter.off('reachBottom')
|
||||
onActivated(() => {
|
||||
initPageAction()
|
||||
})
|
||||
|
||||
async function getTrendingVideos() {
|
||||
|
||||
Reference in New Issue
Block a user