import { json, LoaderFunctionArgs, MetaFunction } from "@remix-run/node"; import { Link, redirect, useLoaderData, useRouteLoaderData } from "@remix-run/react"; import serverRequest from "~/lib/request.server"; import { Member } from "~/lib/api/member"; import BaseProfile from "~/components/profile/BaseProfile"; import { loader as rootLoader } from "~/root"; import { Alert, Button } from "react-bootstrap"; import { Trans, useTranslation } from "react-i18next"; import { ArrowLeft } from "react-bootstrap-icons"; export const meta: MetaFunction = ({ data }) => { const { member } = data!; return [ { title: `${member.display_name ?? member.name} • @${member.user.username} • pronouns.cc` }, ]; }; export const loader = async ({ params }: LoaderFunctionArgs) => { let username = params.username!; const memberName = params.member!; if (!username.startsWith("@")) throw redirect(`/@${username}/${memberName}`); username = username.substring("@".length); const member = await serverRequest("GET", `/users/${username}/members/${memberName}`); return json({ member }); }; export default function MemberPage() { const { t } = useTranslation(); const { member } = useLoaderData(); const { meUser } = useRouteLoaderData("root") || { meUser: undefined }; const isMeUser = meUser && meUser.id === member.user.id; const memberName = member.name; return ( <> {isMeUser && ( You are currently viewing the public profile of {{ memberName }}.
Edit profile
)}
{/* @ts-expect-error using as=Link causes an error here, even though it runs completely fine */}
); }