import type * as getPreferences from '#lib/lexicons/dev/knotless/getPreferences.ts'; import type * as listThemes from '#lib/lexicons/dev/knotless/listThemes.ts'; import type { PageLoad } from './$types'; import { xrpc } from '#lib/data.ts'; import { themesOf } from '#lib/preferences.ts'; /** The most themes of one's own Appearance lists, which is all of anyone's but a few. */ const MINE = 100; /** The themes the viewer published, those it added, and who made each of those still there: none for no one, nor on a server that keeps no index. */ export const load: PageLoad = async (event) => { const { me } = await event.parent(); if (!me) return { mine: [], added: [], makers: {} }; const [made, prefs] = await Promise.all([ xrpc( event, 'dev.knotless.listThemes', { actor: me.did, limit: MINE }, true ), xrpc(event, 'dev.knotless.getPreferences', {}, true) ]); const added = prefs ? themesOf(prefs) : []; const uris = added.map((a) => a.uri); const found = uris.length ? await xrpc(event, 'dev.knotless.listThemes', { uris }, true) : null; const makers = Object.fromEntries((found?.themes ?? []).map((t) => [t.uri, t.creator.handle])); return { mine: made?.themes ?? [], added, makers }; };