import type * as getFollowers from '#lib/lexicons/dev/knotless/getFollowers.ts'; import type * as getFollows from '#lib/lexicons/dev/knotless/getFollows.ts'; import type * as getActorStars from '#lib/lexicons/dev/knotless/getActorStars.ts'; import type * as getActorActivity from '#lib/lexicons/dev/knotless/getActorActivity.ts'; import type * as getActorRepos from '#lib/lexicons/dev/knotless/getActorRepos.ts'; import type * as getOrg from '#lib/lexicons/dev/knotless/getOrg.ts'; import type * as getFeed from '#lib/lexicons/dev/knotless/getFeed.ts'; import type * as getProfile from '#lib/lexicons/dev/knotless/getProfile.ts'; import type { Kind, Order } from '#lib/organisms/ProfileRepos.svelte'; import type { ProfileTab } from '#lib/templates/ProfilePage.svelte'; import type { PageLoad } from './$types'; import type { AtIdentifierString, DatetimeString } from '@atproto/lex'; import { since, today as on, YEAR } from '#lib/activity.ts'; import { xrpc } from '#lib/data.ts'; /** Events on each page of the activity tab. */ const PAGE = 40; const one = (of: readonly T[], value: string | null): T => of.find((v) => v === value) ?? of[0]; /** * Who the account is and the repositories its PDS holds, and to itself * those of others shared with it; and, as far as an * index knows, how much it did each day of the year and, on the activity * tab, a page of all it did, or on the stars tab, what it starred; or a * page of who follows it, or whom it follows; or, of an organization, its * members. */ export const load: PageLoad = async (event) => { // A handle or a DID, as the path names it; the server says if it is neither. const actor = event.params.authority as AtIdentifierString; const asked = event.url.searchParams; const tab = one( ['overview', 'repos', 'stars', 'activity', 'followers', 'following', 'members'], asked.get('tab') ); const [{ now, tz }, profile, { repos, shared = [] }] = await Promise.all([ event.parent(), xrpc(event, 'dev.knotless.getProfile', { actor }), xrpc(event, 'dev.knotless.getActorRepos', { actor }) ]); // Days are counted in the viewer's zone, as the feed's are. const today = on(now, tz); const cursor = asked.get('cursor') ?? undefined; const [activity, feed, stars, follows, org] = await Promise.all([ xrpc( event, 'dev.knotless.getActorActivity', { actor: profile.did, since: since(today, YEAR) as DatetimeString, tz: tz ?? undefined }, true ), tab === 'activity' ? xrpc( event, 'dev.knotless.getFeed', { actor: profile.did, limit: PAGE, cursor }, true ) : null, tab === 'stars' ? xrpc( event, 'dev.knotless.getActorStars', { actor: profile.did }, true ) : null, tab === 'followers' ? xrpc( event, 'dev.knotless.getFollowers', { actor: profile.did, cursor }, true ) : tab === 'following' ? xrpc( event, 'dev.knotless.getFollows', { actor: profile.did, cursor }, true ) : null, tab === 'members' ? xrpc(event, 'dev.knotless.getOrg', { actor: profile.did }, true) : null ]); const filter = { q: asked.get('q') ?? '', kind: one(['all', 'sources', 'forks', 'shared'], asked.get('kind')), order: one(['pushed', 'created', 'name'], asked.get('sort')) }; return { today, tab, profile, repos, shared, activity, feed, stars, follows, org, filter }; };