2024-06-29 05:05:50 +02:00
|
|
|
<!-- Timeline.vue -->
|
2024-04-27 09:39:26 +02:00
|
|
|
<template>
|
2024-11-30 16:39:02 +01:00
|
|
|
<div class="timeline rounded overflow-hidden">
|
|
|
|
|
<TransitionGroup name="timeline-item" tag="div" class="timeline-items *:rounded space-y-4 *:border *:border-border/50">
|
2024-06-29 05:05:50 +02:00
|
|
|
<TimelineItem :type="type" v-for="item in items" :key="item.id" :item="item" @update="updateItem"
|
|
|
|
|
@delete="removeItem" />
|
|
|
|
|
</TransitionGroup>
|
|
|
|
|
|
2024-11-30 02:19:32 +01:00
|
|
|
<!-- <TimelineItem v-if="isLoading" :type="type" v-for="_ in 5" /> -->
|
2024-06-29 05:05:50 +02:00
|
|
|
|
|
|
|
|
<div v-if="error" class="timeline-error">
|
|
|
|
|
{{ error.message }}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div v-if="hasReachedEnd && items.length > 0"
|
2024-07-22 01:23:29 +02:00
|
|
|
class="flex flex-col items-center justify-center gap-2 text-gray-200 text-center p-10">
|
2024-06-29 05:05:50 +02:00
|
|
|
<span class="text-lg font-semibold">You've scrolled so far, there's nothing left to show.</span>
|
|
|
|
|
<span class="text-sm">You can always go back and see what you missed.</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div v-else-if="hasReachedEnd && items.length === 0"
|
2024-07-22 01:23:29 +02:00
|
|
|
class="flex flex-col items-center justify-center gap-2 text-gray-200 text-center p-10">
|
2024-06-29 05:05:50 +02:00
|
|
|
<span class="text-lg font-semibold">There's nothing to show here.</span>
|
|
|
|
|
<span class="text-sm">Either you're all caught up or there's nothing to show.</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div v-else-if="!infiniteScroll.value" class="py-10 px-4">
|
|
|
|
|
<Button theme="secondary" @click="loadNext" :disabled="isLoading" class="w-full">
|
|
|
|
|
Load More
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div v-else ref="loadMoreTrigger" class="h-20"></div>
|
2024-06-15 23:18:58 +02:00
|
|
|
</div>
|
2024-04-27 09:39:26 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2024-08-28 00:23:29 +02:00
|
|
|
import type { Notification, Status } from "@versia/client/types";
|
2024-06-29 05:05:50 +02:00
|
|
|
import { useIntersectionObserver } from "@vueuse/core";
|
|
|
|
|
import { onMounted, watch } from "vue";
|
|
|
|
|
import Button from "~/packages/ui/components/buttons/button.vue";
|
|
|
|
|
import { SettingIds } from "~/settings";
|
|
|
|
|
import TimelineItem from "./timeline-item.vue";
|
2024-04-27 09:39:26 +02:00
|
|
|
|
|
|
|
|
const props = defineProps<{
|
2024-06-29 05:05:50 +02:00
|
|
|
items: Status[] | Notification[];
|
|
|
|
|
type: "status" | "notification";
|
|
|
|
|
isLoading: boolean;
|
|
|
|
|
hasReachedEnd: boolean;
|
|
|
|
|
error: Error | null;
|
|
|
|
|
loadNext: () => void;
|
|
|
|
|
loadPrev: () => void;
|
|
|
|
|
removeItem: (id: string) => void;
|
|
|
|
|
updateItem: ((item: Status) => void) | ((item: Notification) => void);
|
2024-04-27 09:39:26 +02:00
|
|
|
}>();
|
|
|
|
|
|
2024-06-29 05:05:50 +02:00
|
|
|
const emit = defineEmits<(e: "update") => void>();
|
2024-04-27 09:39:26 +02:00
|
|
|
|
2024-06-29 05:05:50 +02:00
|
|
|
const loadMoreTrigger = ref<HTMLElement | null>(null);
|
2024-04-27 09:39:26 +02:00
|
|
|
|
2024-06-29 05:05:50 +02:00
|
|
|
useIntersectionObserver(loadMoreTrigger, ([observer]) => {
|
|
|
|
|
if (observer?.isIntersecting && !props.isLoading && !props.hasReachedEnd) {
|
|
|
|
|
props.loadNext();
|
|
|
|
|
}
|
2024-04-28 07:02:27 +02:00
|
|
|
});
|
|
|
|
|
|
2024-06-29 05:05:50 +02:00
|
|
|
const infiniteScroll = useSetting(SettingIds.InfiniteScroll);
|
2024-04-27 09:39:26 +02:00
|
|
|
|
2024-04-27 09:58:17 +02:00
|
|
|
watch(
|
2024-06-29 05:05:50 +02:00
|
|
|
() => props.items,
|
|
|
|
|
() => {
|
|
|
|
|
emit("update");
|
2024-04-27 09:58:17 +02:00
|
|
|
},
|
|
|
|
|
);
|
2024-06-29 05:05:50 +02:00
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
props.loadNext();
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.timeline-item-enter-active,
|
|
|
|
|
.timeline-item-leave-active {
|
|
|
|
|
transition: all 0.5s ease;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.timeline-item-enter-from,
|
|
|
|
|
.timeline-item-leave-to {
|
|
|
|
|
opacity: 0;
|
2024-07-21 21:17:01 +02:00
|
|
|
scale: 0.99;
|
2024-06-29 05:05:50 +02:00
|
|
|
}
|
|
|
|
|
</style>
|