Files
BewlyBewly/src/contentScripts/views/Home/components/Trending.vue
Hakadao 20d157abdf refactor message listeners && fix moment card url not linking the video page
* Refactor messageListeners and add utils module to simply use api

* chore: add previously deleted annotation

* refactor: message listeners (#447)

* Refactor API imports and update API endpoints

* Fix variable naming in FavoritesPop and Favorites components

* Fix variable naming inconsistency in getHistoryList function

* Fix API parameter naming conventions

* Refactor API_AUTH afterHandle functions

* Add API documentation links  and add function to be the api item

* Refactor API body and params

* Remove unused getAccessKey function in auth.ts

---------

Co-authored-by: pengyunfei <pengyunfei@360.cn>
Co-authored-by: Hakadao <a578457889743@gmail.com>

* refactor: API imports and update API endpoints (#460)

* Refactor API imports and update API endpoints

* Fix variable naming in FavoritesPop and Favorites components

* Fix variable naming inconsistency in getHistoryList function

* Fix API parameter naming conventions

* Refactor API_AUTH afterHandle functions

* Add API documentation links  and add function to be the api item

* Refactor API body and params

* Remove unused getAccessKey function in auth.ts

* Add message definition constants

---------

Co-authored-by: pengyunfei <pengyunfei@360.cn>
Co-authored-by: Hakadao <a578457889743@gmail.com>

* refactor: Add cSpell words and update API calls

* Fix API method case and add day parameter to ranking API

* feat(Settings): add bilibili settings entry

* chore(Settings): hide the bilibili settings temporary

* feat: support firefox(REAL) (#500)

* refactor: new rule support `Chromium` and `Firefox`

* refactor: add default `priority`

* fix: `message.bilibili.com` not working

* fix: `show.bilibili.com` not working

* fix: 修复一些子站的问题

* 添加了一些其他的子站

* fix(VideoCard): bug fixes (#316) (#319) (#320)

* fix(VideoCard): fix double page open on author's name click (#315)

* fix(VideoCard): ensure clicking on bangumi name or avatar goes to the right page

* feat(Settings): add an "always show top bar logo" setting (#219)

* feat(Settings): add discord link to about page

* feat(Settings): redesign settings panel

* style(Settings): adjust the block ads position

* feat(Settings): add credits section on about page

* chore(Settings): add ChatGPT to the credits section

* feat(Settings): redesign settings panel

* style: decrease the content opacity in light mode
decrease the opacity in light mode to ensure the text can be seen clearly

* refactor: remove the "backdrop-glass" shortcut

* refactor: rename `--bew-filter-glass` to  `--bew-filter-glass-1`

* feat: add performance settings

* chore: remove the credits section

* feat(TopBar): add top bar icon badges config

* feat(VideoCard): implement adaptive width in horizontal mode

* feat(Home): implement grid layout switcher

* feat(Dock): redesign dock

* style: adjust dock styles

* style: add edge glow effect in some dialogs

* fix(Dock): active color incorrect when hovering dock item in dark mode

* chore: update version number

* feat(manifest): add extension id when in firefox

* refactor(rules.json): reduce redundant code

---------

Co-authored-by: starknt <1431880400@qq.com>

* chore: firefox-extension build

* Merge branch 'dev' into refactor-message-listeners

* refactor: Refactor API imports and update API endpoints

* fix(MomentsPop): moment card url not linking the video page

* chore: update version number

---------

Co-authored-by: pengyunfei <pengyunfei@360.cn>
Co-authored-by: Jimmy Chow <jimmychow@192.168.10.102>
Co-authored-by: cloudflypeng <44285412+cloudflypeng@users.noreply.github.com>
Co-authored-by: starknt <1431880400@qq.com>
Co-authored-by: 梦念逍遥 <2589141604@qq.com>
2024-04-11 21:07:06 +08:00

153 lines
3.6 KiB
Vue

<script setup lang="ts">
import type { Ref } from 'vue'
import type { GridLayout } from '~/logic'
import type { TrendingResult, List as VideoItem } from '~/models/video/trending'
import API from '~/background/msg.define'
const props = defineProps<{
gridLayout: GridLayout
}>()
const emit = defineEmits<{
(e: 'beforeLoading'): void
(e: 'afterLoading'): void
}>()
const gridValue = computed((): string => {
if (props.gridLayout === 'adaptive')
return '~ 2xl:cols-5 xl:cols-4 lg:cols-3 md:cols-2 gap-5'
if (props.gridLayout === 'twoColumns')
return '~ cols-1 xl:cols-2 gap-4'
return '~ cols-1 gap-4'
})
const videoList = reactive<VideoItem[]>([])
const isLoading = ref<boolean>(false)
const containerRef = ref<HTMLElement>() as Ref<HTMLElement>
const pn = ref<number>(1)
const noMoreContent = ref<boolean>(false)
const { handleReachBottom, handlePageRefresh } = useBewlyApp()
onMounted(async () => {
await initData()
initPageAction()
})
onActivated(() => {
initPageAction()
})
async function initData() {
noMoreContent.value = false
videoList.length = 0
pn.value = 1
await getData()
}
async function getData() {
await getTrendingVideos()
}
function initPageAction() {
handleReachBottom.value = async () => {
if (!isLoading.value)
await getData()
}
handlePageRefresh.value = async () => {
initData()
}
}
async function getTrendingVideos() {
if (noMoreContent.value)
return
emit('beforeLoading')
isLoading.value = true
try {
const response: TrendingResult = await browser.runtime.sendMessage({
contentScriptQuery: API.VIDEO.GET_POPULAR_VIDEOS,
pn: pn.value++,
ps: 30,
})
if (response.code === 0) {
noMoreContent.value = response.data.no_more
const resData = [] as VideoItem[]
response.data.list.forEach((item: VideoItem) => {
resData.push(item)
})
// when videoList has length property, it means it is the first time to load
if (!videoList.length) {
Object.assign(videoList, resData)
}
else {
// else we concat the new data to the old data
Object.assign(videoList, videoList.concat(resData))
}
}
}
finally {
isLoading.value = false
emit('afterLoading')
}
}
defineExpose({ initData })
</script>
<template>
<div>
<!-- By directly using predefined unocss grid properties, it is possible to dynamically set the grid attribute -->
<div hidden grid="~ 2xl:cols-5 xl:cols-4 lg:cols-3 md:cols-2 gap-5" />
<div hidden grid="~ cols-1 xl:cols-2 gap-4" />
<div hidden grid="~ cols-1 gap-4" />
<div
ref="containerRef"
m="b-0 t-0" relative w-full h-full
:grid="gridValue"
>
<VideoCard
v-for="video in videoList"
:id="Number(video.aid)"
:key="video.aid"
:duration="video.duration"
:title="video.title"
:desc="video.desc"
:cover="video.pic"
:author="video.owner.name"
:author-face="video.owner.face"
:mid="video.owner.mid"
:view="video.stat.view"
:danmaku="video.stat.danmaku"
:published-timestamp="video.pubdate"
:bvid="video.bvid"
:tag="video.rcmd_reason.content"
:cid="video.cid"
show-preview
:horizontal="gridLayout !== 'adaptive'"
/>
<!-- skeleton -->
<template v-if="isLoading">
<VideoCardSkeleton
v-for="item in 30" :key="item"
:horizontal="gridLayout !== 'adaptive'"
/>
</template>
</div>
<Transition name="fade">
<Loading v-if="isLoading" />
</Transition>
</div>
</template>
<style lang="scss" scoped>
</style>