2023-03-18 15:19:53 +01:00
|
|
|
import {
|
|
|
|
ErrorCode,
|
|
|
|
type APIError,
|
|
|
|
type Invite,
|
|
|
|
type MeUser,
|
|
|
|
type PartialMember,
|
|
|
|
} from "$lib/api/entities";
|
|
|
|
import { apiFetchClient } from "$lib/api/fetch";
|
2023-03-14 00:16:19 +01:00
|
|
|
import type { LayoutLoad } from "./$types";
|
|
|
|
|
2023-03-13 17:11:05 +01:00
|
|
|
export const ssr = false;
|
2023-03-14 00:16:19 +01:00
|
|
|
|
|
|
|
export const load = (async ({ parent }) => {
|
2023-03-18 15:19:53 +01:00
|
|
|
const user = await apiFetchClient<MeUser>("/users/@me");
|
|
|
|
const members = await apiFetchClient<PartialMember[]>("/users/@me/members");
|
|
|
|
|
|
|
|
let invites: Invite[] = [];
|
|
|
|
let invitesEnabled = true;
|
|
|
|
try {
|
|
|
|
invites = await apiFetchClient<Invite[]>("/auth/invites");
|
|
|
|
} catch (e) {
|
|
|
|
if ((e as APIError).code === ErrorCode.InvitesDisabled) {
|
|
|
|
invitesEnabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-14 00:16:19 +01:00
|
|
|
const data = await parent();
|
2023-03-18 15:19:53 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
...data,
|
|
|
|
user,
|
|
|
|
members,
|
|
|
|
invites,
|
|
|
|
invitesEnabled,
|
|
|
|
};
|
2023-03-14 00:16:19 +01:00
|
|
|
}) satisfies LayoutLoad;
|