mirror of
https://github.com/bookorbit/bookorbit.git
synced 2026-11-03 08:21:39 -06:00
fix: prevent double API call on library load
- remove racy watch(loading)+loadIfSentinelVisible fallback that fired before RecycleScroller set virtual height - add hasMore guard and total reset in useBookQuery for defensive correctness
This commit is contained in:
@@ -19,12 +19,14 @@ export function useBookQuery(libraryId: Ref<number | null>) {
|
||||
|
||||
async function load(reset = false) {
|
||||
if (loading.value || libraryId.value === null) return
|
||||
if (!reset && !hasMore.value) return
|
||||
loading.value = true
|
||||
error.value = null
|
||||
|
||||
if (reset) {
|
||||
pagination.page = 0
|
||||
items.value = []
|
||||
total.value = 0
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -196,14 +196,6 @@ function clearFilters() {
|
||||
const sentinel = ref<HTMLElement | null>(null)
|
||||
let observer: IntersectionObserver | null = null
|
||||
|
||||
function loadIfSentinelVisible() {
|
||||
if (!hasMore.value || loading.value) return
|
||||
const el = sentinel.value
|
||||
if (!el) return
|
||||
const rect = el.getBoundingClientRect()
|
||||
if (rect.top < window.innerHeight + 300) load()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
load(true)
|
||||
|
||||
@@ -233,14 +225,6 @@ watch(libraryId, (newId) => {
|
||||
|
||||
watch(filter, () => load(true), { deep: true })
|
||||
|
||||
watch(
|
||||
loading,
|
||||
(isLoading) => {
|
||||
if (!isLoading) loadIfSentinelVisible()
|
||||
},
|
||||
{ flush: 'post' },
|
||||
)
|
||||
|
||||
const { selectionMode, selectedIds, selectedCount, enterSelectionMode, exitSelectionMode, toggleBook, rangeSelectTo, isSelected } = useBookSelection()
|
||||
const {
|
||||
pendingId: deleteBookId,
|
||||
|
||||
Reference in New Issue
Block a user