diff --git a/web/src/lib/components/timeline/TimelineView.svelte b/web/src/lib/components/timeline/TimelineView.svelte index ed5f39ba0..8c4570ba4 100644 --- a/web/src/lib/components/timeline/TimelineView.svelte +++ b/web/src/lib/components/timeline/TimelineView.svelte @@ -19,6 +19,7 @@ followingOnly = false, signedIn = false, loading = false, + trendingLoading = loading, basePath }: { feed?: ShTangledFeedGetTimeline.$output["feed"]; @@ -26,6 +27,7 @@ followingOnly?: boolean; signedIn?: boolean; loading?: boolean; + trendingLoading?: boolean; /** route the global/following toggle stays on, e.g. "/" or "/timeline" */ basePath: string; } = $props(); @@ -88,7 +90,7 @@
- {#if loading} + {#if trendingLoading} {:else} diff --git a/web/src/lib/components/timeline/load.ts b/web/src/lib/components/timeline/load.ts index 8cca25b58..2532097a2 100644 --- a/web/src/lib/components/timeline/load.ts +++ b/web/src/lib/components/timeline/load.ts @@ -6,19 +6,22 @@ import type * as ShTangledFeedGetTimeline from "$lib/api/lexicons/types/sh/tangl const PAGE_LIMIT = 50; -export interface LoadTimelineOptions { +export interface LoadFeedOptions { ctx: BobbinContext; followingOnly: boolean; } // shared by /timeline and the signed-in homescreen at / -export const loadTimeline = async ({ ctx, followingOnly }: LoadTimelineOptions) => { - const [{ feed }, trending] = await Promise.all([ - jsonGet(ctx, "sh.tangled.feed.getTimeline", { - followingOnly, - limit: PAGE_LIMIT - }), - getTrending(ctx).catch(() => ({ people: [], repos: [] })) - ]); - return { feed, trending: trending.repos.map(toRepoCard), followingOnly }; +export const loadFeed = async ({ ctx, followingOnly }: LoadFeedOptions) => { + const { feed } = await jsonGet( + ctx, + "sh.tangled.feed.getTimeline", + { followingOnly, limit: PAGE_LIMIT } + ); + return feed; +}; + +export const loadTrendingRepos = async (ctx: BobbinContext) => { + const trending = await getTrending(ctx).catch(() => ({ people: [], repos: [] })); + return trending.repos.map(toRepoCard); }; diff --git a/web/src/lib/components/timeline/timelineFeed.svelte.ts b/web/src/lib/components/timeline/timelineFeed.svelte.ts index 59279e84f..aefd09317 100644 --- a/web/src/lib/components/timeline/timelineFeed.svelte.ts +++ b/web/src/lib/components/timeline/timelineFeed.svelte.ts @@ -1,6 +1,6 @@ import { createBobbinClient } from "$lib/api/client"; import { getAuth } from "$lib/auth.svelte"; -import { loadTimeline } from "./load"; +import { loadFeed, loadTrendingRepos } from "./load"; import type * as ShTangledFeedGetTimeline from "$lib/api/lexicons/types/sh/tangled/feed/getTimeline"; import type { RepoCardData } from "$lib/components/profile/types"; @@ -16,6 +16,7 @@ export const createTimelineFeed = (opts: TimelineFeedOptions) => { let feed = $state([]); let trending = $state([]); let loading = $state(true); + let trendingLoading = $state(true); let failed = $state(false); const signedIn = $derived(Boolean(auth.currentDid)); @@ -32,11 +33,10 @@ export const createTimelineFeed = (opts: TimelineFeedOptions) => { let cancelled = false; const ctx = createBobbinClient({ serviceUrl: auth.bobbinUrl, agent }); - loadTimeline({ ctx, followingOnly: wantFollowing }) + loadFeed({ ctx, followingOnly: wantFollowing }) .then((result) => { if (cancelled) return; - feed = result.feed; - trending = result.trending; + feed = result; loading = false; }) .catch(() => { @@ -51,6 +51,33 @@ export const createTimelineFeed = (opts: TimelineFeedOptions) => { }; }); + $effect(() => { + const isEnabled = opts.enabled ? opts.enabled() : true; + if (!isEnabled || auth.resolving) return; + + const agent = auth.agent ?? undefined; + + trendingLoading = true; + let cancelled = false; + + const ctx = createBobbinClient({ serviceUrl: auth.bobbinUrl, agent }); + loadTrendingRepos(ctx) + .then((result) => { + if (cancelled) return; + trending = result; + trendingLoading = false; + }) + .catch(() => { + if (!cancelled) { + trendingLoading = false; + } + }); + + return () => { + cancelled = true; + }; + }); + return { get feed() { return feed; @@ -61,6 +88,9 @@ export const createTimelineFeed = (opts: TimelineFeedOptions) => { get loading() { return loading; }, + get trendingLoading() { + return trendingLoading; + }, get failed() { return failed; }, diff --git a/web/src/routes/+page.svelte b/web/src/routes/+page.svelte index e631e0df3..96c4af3ac 100644 --- a/web/src/routes/+page.svelte +++ b/web/src/routes/+page.svelte @@ -1,4 +1,5 @@ @@ -22,7 +24,8 @@ feed={feedState.feed} trending={feedState.trending} loading={feedState.loading} - followingOnly={false} + trendingLoading={feedState.trendingLoading} + followingOnly={followingOnly && feedState.signedIn} signedIn={feedState.signedIn} basePath="/" /> diff --git a/web/src/routes/timeline/+page.svelte b/web/src/routes/timeline/+page.svelte index 7298263f7..1c37a9c90 100644 --- a/web/src/routes/timeline/+page.svelte +++ b/web/src/routes/timeline/+page.svelte @@ -15,6 +15,7 @@ feed={feedState.feed} trending={feedState.trending} loading={feedState.loading} + trendingLoading={feedState.trendingLoading} followingOnly={followingOnly && feedState.signedIn} signedIn={feedState.signedIn} basePath="/timeline"