import { json, LoaderFunctionArgs, MetaFunction } from "@remix-run/node"; import { Link, redirect, useLoaderData, useRouteLoaderData } from "@remix-run/react"; import { UserWithMembers } from "~/lib/api/user"; import serverRequest from "~/lib/request.server"; import { loader as rootLoader } from "~/root"; import { Alert } from "react-bootstrap"; import { Trans, useTranslation } from "react-i18next"; import { renderMarkdown } from "~/lib/markdown"; import ProfileLink from "~/components/ProfileLink"; import ProfileField from "~/components/ProfileField"; export const meta: MetaFunction = ({ data }) => { const { user } = data!; return [{ title: `@${user.username} • pronouns.cc` }]; }; export const loader = async ({ request, params }: LoaderFunctionArgs) => { const url = new URL(request.url); let memberPage = parseInt(url.searchParams.get("page") ?? "0", 10); let username = params.username!; if (!username.startsWith("@")) throw redirect(`/@${username}`); username = username.substring("@".length); const user = await serverRequest("GET", `/users/${username}`); const pageCount = Math.ceil(user.members.length / 20); let members = user.members.slice(memberPage * 20, (memberPage + 1) * 20); if (members.length === 0) { members = user.members.slice(0, 20); memberPage = 0; } return json({ user, members, currentPage: memberPage, pageCount }); }; export default function UserPage() { const { t } = useTranslation(); const { user } = useLoaderData(); const { meUser } = useRouteLoaderData("root") || { meUser: undefined }; const bio = renderMarkdown(user.bio); return ( <> {meUser && meUser.id === user.id && ( You are currently viewing your public profile.
Edit your profile
)}
{t("user.avatar-alt",
{user.display_name ? ( <>

{user.display_name}

@{user.username}

) : ( <>

@{user.username}

)} {bio && ( <>

)}
{user.links.length > 0 && (
    {user.links.map((l, i) => ( ))}
)}
{user.names.length > 0 && ( )} {user.pronouns.length > 0 && ( )} {user.fields.map((f, i) => ( ))}
); }