2024-09-10 21:24:40 +02:00
|
|
|
import { json, LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
|
2024-09-24 20:56:10 +02:00
|
|
|
import { Link, redirect, useLoaderData, useRouteLoaderData } from "@remix-run/react";
|
2024-09-17 22:12:12 +02:00
|
|
|
import { UserWithMembers } from "~/lib/api/user";
|
2024-09-05 22:29:12 +02:00
|
|
|
import serverRequest from "~/lib/request.server";
|
2024-09-24 20:56:10 +02:00
|
|
|
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 StatusLine from "~/components/StatusLine";
|
|
|
|
import PronounLink from "~/components/PronounLink";
|
2024-09-05 22:29:12 +02:00
|
|
|
|
|
|
|
export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
|
|
|
const { user } = data!;
|
|
|
|
|
|
|
|
return [{ title: `@${user.username} - pronouns.cc` }];
|
|
|
|
};
|
|
|
|
|
2024-09-17 22:12:12 +02:00
|
|
|
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
|
|
|
const url = new URL(request.url);
|
|
|
|
const memberPage = parseInt(url.searchParams.get("page") ?? "0", 10);
|
|
|
|
|
2024-09-05 22:29:12 +02:00
|
|
|
let username = params.username!;
|
|
|
|
if (!username.startsWith("@")) throw redirect(`/@${username}`);
|
|
|
|
username = username.substring("@".length);
|
|
|
|
|
2024-09-17 22:12:12 +02:00
|
|
|
const user = await serverRequest<UserWithMembers>("GET", `/users/${username}`);
|
|
|
|
let members = user.members.slice(memberPage * 20, (memberPage + 1) * 20);
|
|
|
|
if (members.length === 0) members = user.members.slice(0, 20);
|
2024-09-05 22:29:12 +02:00
|
|
|
|
2024-09-17 22:12:12 +02:00
|
|
|
return json({ user, members });
|
2024-09-05 22:29:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default function UserPage() {
|
2024-09-24 20:56:10 +02:00
|
|
|
const { t } = useTranslation();
|
2024-09-05 22:29:12 +02:00
|
|
|
const { user } = useLoaderData<typeof loader>();
|
2024-09-24 20:56:10 +02:00
|
|
|
const { meUser } = useRouteLoaderData<typeof rootLoader>("root") || { meUser: undefined };
|
|
|
|
|
|
|
|
const bio = renderMarkdown(user.bio);
|
2024-09-05 22:29:12 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2024-09-24 20:56:10 +02:00
|
|
|
{meUser && meUser.id === user.id && (
|
|
|
|
<Alert variant="secondary">
|
|
|
|
<Trans t={t} i18nKey="user.own-profile-alert">
|
|
|
|
You are currently viewing your <strong>public</strong> profile.
|
|
|
|
<br />
|
|
|
|
<Link to={`/@${user.username}/edit`}>Edit your profile</Link>
|
|
|
|
</Trans>
|
|
|
|
</Alert>
|
|
|
|
)}
|
|
|
|
<div className="grid row-gap-3">
|
|
|
|
<div className="row">
|
|
|
|
<div className="col-md-4 text-center">
|
|
|
|
<img
|
|
|
|
src={user.avatar_url || "https://pronouns.cc/default/512.webp"}
|
|
|
|
alt={t("user.avatar-alt", { username: user.username })}
|
|
|
|
width={200}
|
|
|
|
height={200}
|
|
|
|
className="rounded-circle img-fluid"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="col-md">
|
|
|
|
{user.display_name ? (
|
|
|
|
<>
|
|
|
|
<h2>{user.display_name}</h2>
|
|
|
|
<p className="fs-5 text-body-secondary">@{user.username}</p>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<h2>@{user.username}</h2>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{bio && (
|
|
|
|
<>
|
|
|
|
<hr />
|
|
|
|
<p dangerouslySetInnerHTML={{ __html: bio }}></p>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
{user.links.length > 0 && (
|
|
|
|
<div className="col-md d-flex align-items-center">
|
|
|
|
<ul className="list-unstyled">
|
|
|
|
{user.links.map((l, i) => (
|
|
|
|
<ProfileLink link={l} key={i} />
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<div className="row row-cols-1 row-cols-sm-2 row-cols-md-3">
|
|
|
|
{user.names.length > 0 && (
|
|
|
|
<div className="col-md">
|
|
|
|
<h3>{t("user.heading.names")}</h3>
|
|
|
|
<ul className="list-unstyled fs-5">
|
|
|
|
{user.names.map((n, i) => (
|
|
|
|
<StatusLine entry={n} preferences={user.custom_preferences} key={i}>
|
|
|
|
{n.value}
|
|
|
|
</StatusLine>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{user.pronouns.length > 0 && (
|
|
|
|
<div className="col-md">
|
|
|
|
<h3>{t("user.heading.pronouns")}</h3>
|
|
|
|
{user.pronouns.map((p, i) => (
|
|
|
|
<StatusLine entry={p} preferences={user.custom_preferences} key={i}>
|
|
|
|
<PronounLink pronoun={p} />
|
|
|
|
</StatusLine>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-09-05 22:29:12 +02:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|