fix: autoload new items when at top of timeline

This commit is contained in:
Daniel Roe 2022-11-29 15:25:45 +00:00
parent 5c5143d2c9
commit 264c796e2f
No known key found for this signature in database
GPG key ID: 22D5008E4F5D9B55

View file

@ -9,14 +9,34 @@ const { paginator, stream } = defineProps<{
}>() }>()
const virtualScroller = $(computedEager(() => useFeatureFlags().experimentalVirtualScroll)) const virtualScroller = $(computedEager(() => useFeatureFlags().experimentalVirtualScroll))
const updater = ref()
const observer = new IntersectionObserver((entries) => {
const [entry] = entries
if (entry.isIntersecting) {
observer.unobserve(entry.target)
setTimeout(() => {
(entry.target as HTMLButtonElement)?.click()
}, 50)
}
}, { threshold: 0.5 })
watch(updater, (v) => {
if (v)
observer.observe(v)
})
</script> </script>
<template> <template>
<CommonPaginator v-bind="{ paginator, stream }" :virtual-scroller="virtualScroller"> <CommonPaginator v-bind="{ paginator, stream }" :virtual-scroller="virtualScroller">
<template #updater="{ number, update }"> <template #updater="{ number, update }">
<button py-4 border="b base" flex="~ col" p-3 w-full text-primary font-bold @click="update"> <button
{{ $t('timeline.show_new_items', [number]) }} v-if="number"
</button> ref="updater"
style="background: repeating-linear-gradient(to right,var(--c-primary) 0%,var(--c-primary-active) 100%)"
absolute h-1 w-full animate-pulse
:aria-title="$t('timeline.show_new_items', [number])"
@click="update"
/>
</template> </template>
<template #default="{ item, active }"> <template #default="{ item, active }">
<template v-if="virtualScroller"> <template v-if="virtualScroller">