import { backend, type GuildEntry, type PostEntry } from '$lib/backend.js'; import { getMe } from '$lib/globals.svelte.js'; import type { LoadEvent } from '@sveltejs/kit'; async function loadFeed (event: LoadEvent): Promise { const resp = await backend.withEvent(event).fetch('home/feed'); if ([200].indexOf(resp.status) < 0) { console.error(`fetch feed returned status ${resp.status}`); return null; } try { const respJ = await resp.json(); const { feed } : { feed: PostEntry[] } = respJ; return feed; } catch (e) { return null; } } async function loadTopGuilds (event: LoadEvent): Promise { const resp = await backend.withEvent(event).fetch('top/guilds'); if ([200].indexOf(resp.status) < 0) { console.error(`fetch top_guilds returned status ${resp.status}`); return null; } try { const respJ = await resp.json(); const { has: top_guilds } : { has: GuildEntry[] } = respJ; console.log('top_guilds is', top_guilds); return top_guilds; } catch (e) { return null; } } export async function load(event): Promise<{feed: PostEntry[] | null, top_guilds?: GuildEntry[] | null}> { let feed = null; let me = getMe(); let top_guilds = null; if (me) { feed = await loadFeed(event); top_guilds = await loadTopGuilds(event); } return { feed, top_guilds }; }