mirror of
https://github.com/koel/koel
synced 2024-12-29 22:13:06 +00:00
30 lines
746 B
TypeScript
30 lines
746 B
TypeScript
import { Ref } from 'vue'
|
|
import { useInfiniteScroll as baseUseInfiniteScroll } from '@vueuse/core'
|
|
import ToTopButton from '@/components/ui/BtnScrollToTop.vue'
|
|
|
|
export const useInfiniteScroll = (el: Ref<HTMLElement | null>, loadMore: Closure) => {
|
|
baseUseInfiniteScroll(el, loadMore, { distance: 32 })
|
|
|
|
let tries = 0
|
|
const MAX_TRIES = 5
|
|
|
|
const makeScrollable = async () => {
|
|
const container = el.value
|
|
|
|
if (!container) {
|
|
window.setTimeout(() => makeScrollable(), 200)
|
|
return
|
|
}
|
|
|
|
if (container.scrollHeight <= container.clientHeight && tries < MAX_TRIES) {
|
|
tries++
|
|
await loadMore()
|
|
window.setTimeout(() => makeScrollable(), 200)
|
|
}
|
|
}
|
|
|
|
return {
|
|
ToTopButton,
|
|
makeScrollable
|
|
}
|
|
}
|