21 lines
818 B
TypeScript
21 lines
818 B
TypeScript
import type { PageServerLoad } from './$types';
|
|
import { getBooksForDiscovery, getVotedBooks } from '$lib/server/pocketbase';
|
|
import type { DiscoveryPrefs } from '$lib/server/pocketbase';
|
|
|
|
export const load: PageServerLoad = async ({ locals, url }) => {
|
|
let prefs: DiscoveryPrefs | undefined;
|
|
const prefsParam = url.searchParams.get('prefs');
|
|
if (prefsParam) {
|
|
try { prefs = JSON.parse(prefsParam) as DiscoveryPrefs; } catch { /* ignore */ }
|
|
}
|
|
|
|
// Return promises directly — SvelteKit streams them, so the page transitions
|
|
// immediately and content resolves async (skeleton shown while loading).
|
|
return {
|
|
streamed: {
|
|
books: getBooksForDiscovery(locals.sessionId, locals.user?.id, prefs).catch(() => []),
|
|
votedBooks: getVotedBooks(locals.sessionId, locals.user?.id).catch(() => []),
|
|
}
|
|
};
|
|
};
|