mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-02 03:06:52 -05:00
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { type LoaderFunctionArgs, redirect } from "react-router";
|
|
import { requireUser } from "~/features/auth/core/user.server";
|
|
import * as UserRepository from "~/features/user-page/UserRepository.server";
|
|
import { notFoundIfFalsy } from "~/utils/remix.server";
|
|
import { userPage } from "~/utils/urls";
|
|
import { userParamsSchema } from "../user-page-schemas";
|
|
|
|
export const loader = async ({ params }: LoaderFunctionArgs) => {
|
|
const user = requireUser();
|
|
const { identifier } = userParamsSchema.parse(params);
|
|
const userToBeEdited = notFoundIfFalsy(
|
|
await UserRepository.findLayoutDataByIdentifier(identifier),
|
|
);
|
|
if (user.id !== userToBeEdited.id) {
|
|
throw redirect(userPage(userToBeEdited));
|
|
}
|
|
|
|
const userProfile = (await UserRepository.findProfileByIdentifier(
|
|
identifier,
|
|
true,
|
|
))!;
|
|
|
|
const preferences = await UserRepository.preferencesByUserId(user.id);
|
|
|
|
return {
|
|
user: userProfile,
|
|
favoriteBadgeIds: userProfile.favoriteBadgeIds,
|
|
discordUniqueName: userProfile.discordUniqueName,
|
|
newProfileEnabled: preferences?.newProfileEnabled ?? false,
|
|
};
|
|
};
|