mirror of
https://github.com/versia-pub/frontend.git
synced 2025-12-06 16:38:20 +01:00
feat: ✨ Timeline refactors, timelines now auto-refresh
This commit is contained in:
parent
3004bf4816
commit
b14a616ef4
|
|
@ -70,10 +70,16 @@
|
||||||
</ButtonsDropdownElement>
|
</ButtonsDropdownElement>
|
||||||
</HeadlessMenuItem>
|
</HeadlessMenuItem>
|
||||||
<HeadlessMenuItem>
|
<HeadlessMenuItem>
|
||||||
<ButtonsDropdownElement @click="note && copy(note.uri)" icon="tabler:code" class="w-full">
|
<ButtonsDropdownElement @click="note && copy(note.uri)" icon="tabler:link" class="w-full">
|
||||||
Copy Link
|
Copy Link
|
||||||
</ButtonsDropdownElement>
|
</ButtonsDropdownElement>
|
||||||
</HeadlessMenuItem>
|
</HeadlessMenuItem>
|
||||||
|
<HeadlessMenuItem>
|
||||||
|
<ButtonsDropdownElement @click="note && deleteNote()" icon="tabler:backspace"
|
||||||
|
class="w-full border-r-2 border-red-500">
|
||||||
|
Delete
|
||||||
|
</ButtonsDropdownElement>
|
||||||
|
</HeadlessMenuItem>
|
||||||
</template>
|
</template>
|
||||||
</DropdownsAdaptiveDropdown>
|
</DropdownsAdaptiveDropdown>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -89,6 +95,10 @@ const props = defineProps<{
|
||||||
small?: boolean;
|
small?: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
const emits = defineEmits<{
|
||||||
|
delete: [];
|
||||||
|
}>();
|
||||||
|
|
||||||
// Handle reblogs
|
// Handle reblogs
|
||||||
const note = computed(() => props.note?.reblog ?? props.note);
|
const note = computed(() => props.note?.reblog ?? props.note);
|
||||||
const noteClosed = ref(
|
const noteClosed = ref(
|
||||||
|
|
@ -96,7 +106,8 @@ const noteClosed = ref(
|
||||||
);
|
);
|
||||||
|
|
||||||
const { copy } = useClipboard();
|
const { copy } = useClipboard();
|
||||||
const client = useMegalodon();
|
const tokenData = useTokenData();
|
||||||
|
const client = useMegalodon(tokenData);
|
||||||
const mentions = await useResolveMentions(
|
const mentions = await useResolveMentions(
|
||||||
note.value?.mentions ?? [],
|
note.value?.mentions ?? [],
|
||||||
client.value,
|
client.value,
|
||||||
|
|
@ -124,6 +135,15 @@ const numberFormat = (number = 0) =>
|
||||||
}).format(number);
|
}).format(number);
|
||||||
const attachments = note.value?.media_attachments ?? [];
|
const attachments = note.value?.media_attachments ?? [];
|
||||||
const noteUrl = note.value && `/@${note.value.account.acct}/${note.value.id}`;
|
const noteUrl = note.value && `/@${note.value.account.acct}/${note.value.id}`;
|
||||||
|
|
||||||
|
const deleteNote = async () => {
|
||||||
|
const result = await client.value?.deleteStatus(note.value?.id ?? "");
|
||||||
|
|
||||||
|
if (result?.data) {
|
||||||
|
console.log("Status deleted", result.data);
|
||||||
|
emits('delete')
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
||||||
21
components/timelines/Account.vue
Normal file
21
components/timelines/Account.vue
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<template>
|
||||||
|
<TimelinesTimeline :timeline="timeline" :load-next="loadNext" :load-prev="loadPrev" @delete="noteDelete" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
const props = defineProps<{
|
||||||
|
id?: string;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const client = useMegalodon();
|
||||||
|
const timelineParameters = ref({});
|
||||||
|
const { timeline, loadNext, loadPrev } = useAccountTimeline(
|
||||||
|
client.value,
|
||||||
|
props.id ?? null,
|
||||||
|
timelineParameters,
|
||||||
|
);
|
||||||
|
|
||||||
|
const noteDelete = async (id: string) => {
|
||||||
|
timeline.value = timeline.value.filter((note) => note.id !== id);
|
||||||
|
};
|
||||||
|
</script>
|
||||||
16
components/timelines/Local.vue
Normal file
16
components/timelines/Local.vue
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<template>
|
||||||
|
<TimelinesTimeline :timeline="timeline" :load-next="loadNext" :load-prev="loadPrev" @delete="noteDelete" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
const client = useMegalodon();
|
||||||
|
const timelineParameters = ref({});
|
||||||
|
const { timeline, loadNext, loadPrev } = useLocalTimeline(
|
||||||
|
client.value,
|
||||||
|
timelineParameters,
|
||||||
|
);
|
||||||
|
|
||||||
|
const noteDelete = async (id: string) => {
|
||||||
|
timeline.value = timeline.value.filter((note) => note.id !== id);
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
@ -1,49 +1,16 @@
|
||||||
<template>
|
<template>
|
||||||
<ClientOnly>
|
<TimelinesTimeline :timeline="timeline" :load-next="loadNext" :load-prev="loadPrev" @delete="noteDelete" />
|
||||||
|
|
||||||
<SocialElementsNotesNote v-for="note of timeline" :key="note.id" :note="note" />
|
|
||||||
<span ref="skeleton"></span>
|
|
||||||
<SocialElementsNotesNote 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 posts, you've seen them all</span>
|
|
||||||
</div>
|
|
||||||
</ClientOnly>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
const client = useMegalodon();
|
const client = useMegalodon();
|
||||||
|
|
||||||
const isLoading = ref(true);
|
|
||||||
|
|
||||||
const timelineParameters = ref({});
|
const timelineParameters = ref({});
|
||||||
const hasReachedEnd = ref(false);
|
|
||||||
const { timeline, loadNext, loadPrev } = usePublicTimeline(
|
const { timeline, loadNext, loadPrev } = usePublicTimeline(
|
||||||
client.value,
|
client.value,
|
||||||
timelineParameters,
|
timelineParameters,
|
||||||
);
|
);
|
||||||
const skeleton = ref<HTMLSpanElement | null>(null);
|
|
||||||
|
|
||||||
onMounted(() => {
|
const noteDelete = async (id: string) => {
|
||||||
useIntersectionObserver(skeleton, async (entries) => {
|
timeline.value = timeline.value.filter((note) => note.id !== id);
|
||||||
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>
|
</script>
|
||||||
62
components/timelines/timeline.vue
Normal file
62
components/timelines/timeline.vue
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
<template>
|
||||||
|
<ClientOnly>
|
||||||
|
|
||||||
|
<SocialElementsNotesNote @delete="emits('delete', note.id)" v-for="note of timeline" :key="note.id"
|
||||||
|
:note="note" />
|
||||||
|
<span ref="skeleton"></span>
|
||||||
|
<SocialElementsNotesNote 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 posts, you've seen them all</span>
|
||||||
|
</div>
|
||||||
|
</ClientOnly>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { Status } from '~/types/mastodon/status';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
timeline: Status[];
|
||||||
|
loadNext: () => Promise<void>;
|
||||||
|
loadPrev: () => Promise<void>;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emits = defineEmits<{
|
||||||
|
delete: [id: string];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const isLoading = ref(true);
|
||||||
|
|
||||||
|
const hasReachedEnd = ref(false);
|
||||||
|
const skeleton = ref<HTMLSpanElement | null>(null);
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
useIntersectionObserver(skeleton, async (entries) => {
|
||||||
|
if (
|
||||||
|
entries[0].isIntersecting &&
|
||||||
|
!hasReachedEnd.value &&
|
||||||
|
!isLoading.value
|
||||||
|
) {
|
||||||
|
isLoading.value = true;
|
||||||
|
await props.loadNext();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Every 5 seconds, load newer posts (prev)
|
||||||
|
useIntervalFn(() => {
|
||||||
|
props.loadPrev();
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
|
watch(() => props.timeline, (newTimeline, oldTimeline) => {
|
||||||
|
// If posts are deleted, don't start loading more posts
|
||||||
|
if (newTimeline.length === oldTimeline.length - 1) return;
|
||||||
|
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>
|
||||||
|
|
@ -1,19 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<NuxtLayout name="app">
|
<NuxtLayout name="app">
|
||||||
<SocialElementsUsersAccount v-if="isMobile" :account="account ?? undefined" />
|
<SocialElementsUsersAccount v-if="isMobile" :account="account ?? undefined" />
|
||||||
<ClientOnly>
|
<TimelinesAccount :id="accountId ?? undefined" :key="accountId ?? undefined" />
|
||||||
<div class="w-full">
|
|
||||||
<SocialElementsNotesNote v-for="note of timeline" :key="note.id" :note="note" />
|
|
||||||
<span ref="skeleton"></span>
|
|
||||||
<SocialElementsNotesNote 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 posts, you've seen them all</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</ClientOnly>
|
|
||||||
|
|
||||||
<template #right>
|
<template #right>
|
||||||
<SocialElementsUsersAccount v-if="!isMobile" :account="account ?? undefined" />
|
<SocialElementsUsersAccount v-if="!isMobile" :account="account ?? undefined" />
|
||||||
|
|
@ -44,42 +32,10 @@ const account = computed<Account | null>(
|
||||||
);
|
);
|
||||||
const accountId = computed(() => account.value?.id ?? null);
|
const accountId = computed(() => account.value?.id ?? null);
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
useIntersectionObserver(skeleton, async (entries) => {
|
|
||||||
if (
|
|
||||||
entries[0].isIntersecting &&
|
|
||||||
!hasReachedEnd.value &&
|
|
||||||
!isLoadingTimeline.value
|
|
||||||
) {
|
|
||||||
isLoadingTimeline.value = true;
|
|
||||||
await loadNext();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
useServerSeoMeta({
|
useServerSeoMeta({
|
||||||
title: account.value?.display_name,
|
title: account.value?.display_name,
|
||||||
description: account.value?.note,
|
description: account.value?.note,
|
||||||
ogImage: account.value?.avatar,
|
ogImage: account.value?.avatar,
|
||||||
profileUsername: account.value?.acct,
|
profileUsername: account.value?.acct,
|
||||||
});
|
});
|
||||||
|
|
||||||
const isLoadingTimeline = ref(true);
|
|
||||||
|
|
||||||
const timelineParameters = ref({});
|
|
||||||
const hasReachedEnd = ref(false);
|
|
||||||
const { timeline, loadNext, loadPrev } = useAccountTimeline(
|
|
||||||
client.value,
|
|
||||||
accountId,
|
|
||||||
timelineParameters,
|
|
||||||
);
|
|
||||||
const skeleton = ref<HTMLSpanElement | null>(null);
|
|
||||||
|
|
||||||
watch(timeline, (newTimeline, oldTimeline) => {
|
|
||||||
isLoadingTimeline.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>
|
</script>
|
||||||
|
|
@ -1,51 +1,9 @@
|
||||||
<template>
|
<template>
|
||||||
<ClientOnly>
|
<TimelinesLocal />
|
||||||
<SocialElementsNotesNote v-for="note of timeline" :key="note.id" :note="note" />
|
|
||||||
<span ref="skeleton"></span>
|
|
||||||
<SocialElementsNotesNote 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 posts, you've seen them all</span>
|
|
||||||
</div>
|
|
||||||
</ClientOnly>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
layout: "app",
|
layout: "app",
|
||||||
});
|
});
|
||||||
const client = useMegalodon();
|
|
||||||
|
|
||||||
const isLoading = ref(true);
|
|
||||||
|
|
||||||
const timelineParameters = ref({});
|
|
||||||
const hasReachedEnd = ref(false);
|
|
||||||
const { timeline, loadNext, loadPrev } = useLocalTimeline(
|
|
||||||
client.value,
|
|
||||||
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>
|
</script>
|
||||||
Loading…
Reference in a new issue