2024-06-29 05:05:50 +02:00
|
|
|
<!-- Timeline.vue -->
|
2024-04-27 09:39:26 +02:00
|
|
|
<template>
|
2024-12-29 16:03:06 +01:00
|
|
|
<TransitionGroup name="timeline-item" tag="div" class="timeline-items first:*:rounded-t divide-y divide-border *:border-x first:*:border-t *:overflow-hidden last:*:rounded-b last:*:!border-b *:shadow-none">
|
2024-12-15 16:19:28 +01:00
|
|
|
<TimelineItem :type="type" v-for="item in items" :key="item.id" :item="item" @update="updateItem"
|
|
|
|
|
@delete="removeItem" />
|
|
|
|
|
</TransitionGroup>
|
|
|
|
|
|
|
|
|
|
<div v-if="isLoading" class="p-4 flex items-center justify-center h-48">
|
|
|
|
|
<Loader class="size-8 animate-spin" />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div v-if="error" class="timeline-error">
|
|
|
|
|
{{ error.message }}
|
2024-06-15 23:18:58 +02:00
|
|
|
</div>
|
2024-12-15 16:19:28 +01:00
|
|
|
|
|
|
|
|
<!-- If there are some posts, but the user scrolled to the end -->
|
|
|
|
|
<Card v-if="hasReachedEnd && items.length > 0" class="shadow-none bg-transparent border-none p-4">
|
|
|
|
|
<CardHeader class="text-center gap-y-4">
|
|
|
|
|
<CardTitle>{{ m.steep_suave_fish_snap() }}</CardTitle>
|
|
|
|
|
<CardDescription>
|
|
|
|
|
{{ m.muddy_bland_shark_accept() }}
|
|
|
|
|
</CardDescription>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
<!-- If there are no posts at all -->
|
|
|
|
|
<Card v-else-if="hasReachedEnd && items.length === 0" class="shadow-none bg-transparent border-none p-4">
|
|
|
|
|
<CardHeader class="text-center gap-y-4">
|
|
|
|
|
<CardTitle>{{ m.fine_arable_lemming_fold() }}</CardTitle>
|
|
|
|
|
<CardDescription>
|
|
|
|
|
{{ m.petty_honest_fish_stir() }}
|
|
|
|
|
</CardDescription>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
<div v-else-if="!infiniteScroll.value" class="py-10 px-4">
|
|
|
|
|
<Button variant="secondary" @click="loadNext" :disabled="isLoading" class="w-full">
|
|
|
|
|
{{ m.gaudy_bland_gorilla_talk() }}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div v-else ref="loadMoreTrigger" class="h-20"></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";
|
2024-12-02 17:22:43 +01:00
|
|
|
import { Loader } from "lucide-vue-next";
|
2024-12-02 12:33:53 +01:00
|
|
|
import {
|
|
|
|
|
Card,
|
|
|
|
|
CardDescription,
|
|
|
|
|
CardHeader,
|
|
|
|
|
CardTitle,
|
|
|
|
|
} from "~/components/ui/card";
|
2024-12-07 22:17:22 +01:00
|
|
|
import * as m from "~/paraglide/messages.js";
|
2024-06-29 05:05:50 +02:00
|
|
|
import { SettingIds } from "~/settings";
|
2024-12-07 13:46:19 +01:00
|
|
|
import { Button } from "../ui/button";
|
2024-06-29 05:05:50 +02:00
|
|
|
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
|
|
|
}
|
2024-12-29 16:03:06 +01:00
|
|
|
</style>
|