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, Button, Pagination } from "react-bootstrap"; import { Trans, useTranslation } from "react-i18next"; import { PersonPlusFill } from "react-bootstrap-icons"; import MemberCard from "~/routes/$username/MemberCard"; import { ReactNode } from "react"; import BaseProfile from "~/components/profile/BaseProfile"; 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, members, currentPage, pageCount } = useLoaderData(); const { meUser } = useRouteLoaderData("root") || { meUser: undefined }; const isMeUser = meUser && meUser.id === user.id; const paginationItems: ReactNode[] = []; for (let i = 0; i < pageCount; i++) { paginationItems.push( {i + 1} , ); } const pagination = ( {paginationItems} ); return ( <> {isMeUser && ( You are currently viewing your public profile.
Edit your profile
)} {(members.length > 0 || isMeUser) && ( <>

{user.member_title || t("user.heading.members")}{" "} {isMeUser && ( // @ts-expect-error using as=Link causes an error here, even though it runs completely fine )}

{pageCount > 1 && pagination}
{members.length === 0 ? (
You don't have any members yet.
Members are sub-profiles that can have their own avatar, names, pronouns, and preferred terms.
You can create a new member with the "Create member" button above.{" "} (only you can see this)
) : (
{members.map((member, i) => ( ))}
)}
{pageCount > 1 && pagination} )} ); }