mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-07-27 13:58:59 -05:00
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import type { LoaderFunctionArgs } from "react-router";
|
|
import { getUser } from "~/features/auth/core/user.server";
|
|
import * as FriendRepository from "~/features/friends/FriendRepository.server";
|
|
import * as UserRepository from "~/features/user-page/UserRepository.server";
|
|
import type { SerializeFrom } from "~/utils/remix";
|
|
import { notFoundIfFalsy } from "~/utils/remix.server";
|
|
|
|
export type UserPageLoaderData = SerializeFrom<typeof loader>;
|
|
|
|
export const loader = async ({ params }: LoaderFunctionArgs) => {
|
|
const loggedInUser = getUser();
|
|
|
|
const user = notFoundIfFalsy(
|
|
await UserRepository.findLayoutDataByIdentifier(
|
|
params.identifier!,
|
|
loggedInUser?.id,
|
|
),
|
|
);
|
|
|
|
const widgetsEnabled = await UserRepository.widgetsEnabledByIdentifier(
|
|
params.identifier!,
|
|
);
|
|
|
|
const mutualFriends =
|
|
loggedInUser && loggedInUser.id !== user.id
|
|
? await FriendRepository.findMutualFriends({
|
|
loggedInUserId: loggedInUser.id,
|
|
targetUserId: user.id,
|
|
})
|
|
: [];
|
|
|
|
return {
|
|
user,
|
|
customTheme: user.customTheme,
|
|
type: widgetsEnabled ? ("new" as const) : ("old" as const),
|
|
mutualFriends,
|
|
};
|
|
};
|