Something went wrong. Try again.
appview-less bluesky client
Something went wrong. Try again.
2.6 kB · 103 lines
Svelte
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104<script lang="ts"> import { type State as PostComposerState } from './PostComposer.svelte'; import { AtpClient } from '$lib/at/client.svelte'; import { accounts } from '$lib/accounts'; import { postCursors, fetchTimeline, allPosts, timelines, fetchInteractionsToTimelineEnd, accountPreferences } from '$lib/state.svelte'; import { buildThreadsFiltered } from '$lib/thread'; import type { Did } from '@atcute/lexicons/syntax'; import GenericTimelineView from './GenericTimelineView.svelte';
interface Props { client?: AtpClient | null; targetDid?: Did; postComposerState: PostComposerState; class?: string; showReplies?: boolean; }
let { client = null, targetDid = undefined, showReplies = true, postComposerState = $bindable(), class: className = '' }: Props = $props();
let viewOwnPosts = $state(true); let displayCount = $state(10);
const userDid = $derived(client?.user?.did); const did = $derived(targetDid ?? userDid);
const currentPrefs = $derived(userDid ? accountPreferences.get(userDid) : null); const mutes = $derived(new Set(currentPrefs?.mutes ?? []));
const threads = $derived( did && timelines.has(did) ? buildThreadsFiltered( did, timelines.get(did)!, allPosts, mutes, $accounts, { viewOwnPosts }, displayCount ) : [] );
let fetchingInteractions = $state(false); let scheduledFetchInteractions = $state(false);
const loadMore = async () => { if (!client || !userDid || !did) return;
await fetchTimeline(client, did, 7, showReplies, { downwards: userDid === did ? 'sameAuthor' : 'none' }); if (client.user && userDid) { if (!fetchingInteractions) { scheduledFetchInteractions = false; fetchingInteractions = true; await fetchInteractionsToTimelineEnd(client, userDid, did); fetchingInteractions = false; } else { scheduledFetchInteractions = true; } } };
$effect(() => { if (client && scheduledFetchInteractions && userDid && did && did !== userDid) { if (!fetchingInteractions) { scheduledFetchInteractions = false; fetchingInteractions = true; fetchInteractionsToTimelineEnd(client, userDid, did).finally( () => (fetchingInteractions = false) ); } else { scheduledFetchInteractions = true; } } });</script>
<GenericTimelineView {client} {threads} timelineId={`replies:${did}`} bind:postComposerState bind:displayCount class={className} isLoggedIn={!!(did || $accounts.length > 0)} canLoad={!!(client && userDid && did)} onLoadMore={loadMore} isComplete={did ? postCursors.get(did)?.end : false}/>