2024-04-27 03:28:12 +02:00
|
|
|
<template>
|
|
|
|
|
<ClientOnly>
|
|
|
|
|
|
|
|
|
|
<SocialElementsNotificationsNotif v-for="notif of timeline" :key="notif.id" :notification="notif" />
|
|
|
|
|
<span ref="skeleton"></span>
|
|
|
|
|
<SocialElementsNotificationsNotif v-for="index of 5" v-if="!hasReachedEnd" :skeleton="true" />
|
|
|
|
|
|
|
|
|
|
<div v-if="hasReachedEnd"
|
|
|
|
|
class="text-center flex flex-row justify-center items-center py-10 text-gray-400 gap-3">
|
|
|
|
|
<Icon name="tabler:message-off" class="h-6 w-6" />
|
|
|
|
|
<span>No more notifications, you've seen them all</span>
|
|
|
|
|
</div>
|
|
|
|
|
</ClientOnly>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2024-04-27 06:50:30 +02:00
|
|
|
const tokenData = useTokenData();
|
|
|
|
|
const client = useMegalodon(tokenData);
|
2024-04-27 03:28:12 +02:00
|
|
|
|
|
|
|
|
const isLoading = ref(true);
|
|
|
|
|
|
|
|
|
|
const timelineParameters = ref({});
|
|
|
|
|
const hasReachedEnd = ref(false);
|
|
|
|
|
const { timeline, loadNext, loadPrev } = useNotificationTimeline(
|
2024-04-27 06:50:30 +02:00
|
|
|
client.value,
|
2024-04-27 03:28:12 +02:00
|
|
|
timelineParameters,
|
|
|
|
|
);
|
|
|
|
|
const skeleton = ref<HTMLSpanElement | null>(null);
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
useIntersectionObserver(skeleton, async (entries) => {
|
|
|
|
|
if (
|
|
|
|
|
entries[0].isIntersecting &&
|
|
|
|
|
!hasReachedEnd.value &&
|
|
|
|
|
!isLoading.value
|
|
|
|
|
) {
|
|
|
|
|
isLoading.value = true;
|
|
|
|
|
await loadNext();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
watch(timeline, (newTimeline, oldTimeline) => {
|
|
|
|
|
isLoading.value = false;
|
|
|
|
|
// If less than NOTES_PER_PAGE statuses are returned, we have reached the end
|
|
|
|
|
if (newTimeline.length - oldTimeline.length < useConfig().NOTES_PER_PAGE) {
|
|
|
|
|
hasReachedEnd.value = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
</script>
|