feat: implement infinite scrolling for public entity lists

Add cursor-based pagination to backend list queries
Introduce LoadMoreSentinel for intersection-based loading
Replace manual load more buttons with infinite scroll sentinel
This commit is contained in:
2026-05-06 08:33:08 +08:00
parent 91a001e3f9
commit c821e9ebba
16 changed files with 619 additions and 103 deletions

View File

@@ -0,0 +1,68 @@
<script setup lang="ts">
import { nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
const props = withDefaults(
defineProps<{
active: boolean;
disabled?: boolean;
rootMargin?: string;
}>(),
{
disabled: false,
rootMargin: '360px 0px'
}
);
const emit = defineEmits<{
load: [];
}>();
const sentinel = ref<HTMLElement | null>(null);
let observer: IntersectionObserver | null = null;
function disconnectObserver() {
observer?.disconnect();
observer = null;
}
function observeSentinel() {
disconnectObserver();
if (!props.active || props.disabled || !sentinel.value) {
return;
}
if (typeof IntersectionObserver === 'undefined') {
emit('load');
return;
}
observer = new IntersectionObserver(
(entries) => {
if (entries.some((entry) => entry.isIntersecting)) {
emit('load');
}
},
{ rootMargin: props.rootMargin }
);
observer.observe(sentinel.value);
}
onMounted(() => {
void nextTick(observeSentinel);
});
onBeforeUnmount(disconnectObserver);
watch(
() => [props.active, props.disabled, props.rootMargin, sentinel.value],
() => {
void nextTick(observeSentinel);
},
{ flush: 'post' }
);
</script>
<template>
<div v-if="active" ref="sentinel" class="load-more-sentinel" aria-hidden="true"></div>
</template>