2022-11-21 03:52:24 +01:00
|
|
|
import Head from "next/head";
|
2022-12-22 15:49:08 +01:00
|
|
|
import React from "react";
|
2022-11-21 03:52:24 +01:00
|
|
|
import {
|
|
|
|
EmojiLaughing,
|
|
|
|
HandThumbsDown,
|
|
|
|
HandThumbsUp,
|
|
|
|
HeartFill,
|
|
|
|
People,
|
|
|
|
} from "react-bootstrap-icons";
|
2022-12-22 15:49:08 +01:00
|
|
|
import ReactMarkdown from "react-markdown";
|
|
|
|
import { useRecoilValue } from "recoil";
|
|
|
|
|
|
|
|
import { Field, Label, LabelStatus, Person, User } from "../lib/api";
|
|
|
|
import { userState } from "../lib/state";
|
2022-11-21 03:52:24 +01:00
|
|
|
import BlueLink from "./BlueLink";
|
|
|
|
import Card from "./Card";
|
2022-12-22 15:49:08 +01:00
|
|
|
import FallbackImage from "./FallbackImage";
|
2022-11-21 03:52:24 +01:00
|
|
|
|
|
|
|
export default function PersonPage({ person }: { person: Person }) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Head>
|
2022-11-24 20:44:47 +01:00
|
|
|
<title key="title">{`${person.fullHandle()} - pronouns.cc`}</title>
|
2022-11-21 03:52:24 +01:00
|
|
|
</Head>
|
|
|
|
<PersonHead person={person} />
|
|
|
|
<IsOwnUserPageNotice person={person} />
|
|
|
|
<div className="container mx-auto pb-[20vh]">
|
|
|
|
<div
|
|
|
|
className="
|
|
|
|
m-2 p-2
|
|
|
|
flex flex-col lg:flex-row
|
|
|
|
justify-center lg:justify-start
|
|
|
|
items-center lg:items-start
|
|
|
|
lg:space-x-16
|
|
|
|
space-y-4 lg:space-y-0
|
|
|
|
border-b border-slate-200 dark:border-slate-700
|
|
|
|
"
|
|
|
|
>
|
|
|
|
<PersonAvatar person={person} />
|
|
|
|
<PersonInfo person={person} />
|
|
|
|
</div>
|
2022-11-24 20:44:47 +01:00
|
|
|
<LabelList content={person.names} />
|
|
|
|
<LabelList content={person.pronouns} />
|
|
|
|
<FieldCardGrid fields={person.fields} />
|
|
|
|
{person instanceof User ? (
|
|
|
|
<MemberList user={person} />
|
2022-11-21 17:04:07 +01:00
|
|
|
) : (
|
2022-11-24 20:44:47 +01:00
|
|
|
<BlueLink
|
|
|
|
to={person.relativeURL()}
|
|
|
|
>{`< ${person.display()}`}</BlueLink>
|
2022-11-21 17:04:07 +01:00
|
|
|
)}
|
2022-11-21 03:52:24 +01:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function PersonHead({ person }: { person: Person }) {
|
2022-11-24 20:44:47 +01:00
|
|
|
const { displayName, avatarUrls, bio, names, pronouns } = person;
|
2022-11-21 03:52:24 +01:00
|
|
|
let description = "";
|
2022-11-24 20:44:47 +01:00
|
|
|
const favNames = names.filter((x) => x.status === LabelStatus.Favourite);
|
|
|
|
const favPronouns = pronouns.filter(
|
|
|
|
(x) => x.status === LabelStatus.Favourite
|
|
|
|
);
|
|
|
|
if (favNames.length || favPronouns.length) {
|
|
|
|
description = `${person.shortHandle()}${
|
|
|
|
favNames.length
|
|
|
|
? ` goes by ${favNames.map((x) => x.display()).join(", ")}`
|
|
|
|
: ""
|
|
|
|
}${favNames.length && favPronouns.length ? " and" : ""}${
|
|
|
|
favPronouns.length
|
|
|
|
? `uses ${favPronouns
|
|
|
|
.map((x) => x.shortDisplay())
|
|
|
|
.join(", ")} pronouns.`
|
|
|
|
: ""
|
|
|
|
}`;
|
2022-11-21 03:52:24 +01:00
|
|
|
} else if (bio && bio !== "") {
|
2022-11-24 20:44:47 +01:00
|
|
|
description = `${bio.slice(0, 500)}${bio.length > 500 ? "…" : ""}`;
|
2022-11-21 03:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Head>
|
|
|
|
<meta key="og:sitename" property="og:site_name" content="pronouns.cc" />
|
|
|
|
<meta
|
|
|
|
key="og:title"
|
|
|
|
property="og:title"
|
|
|
|
content={
|
2022-11-24 20:44:47 +01:00
|
|
|
displayName
|
|
|
|
? `${displayName} (${person.fullHandle()})`
|
|
|
|
: person.fullHandle()
|
2022-11-21 03:52:24 +01:00
|
|
|
}
|
|
|
|
/>
|
2022-11-24 20:44:47 +01:00
|
|
|
{avatarUrls && avatarUrls.length > 0 && (
|
|
|
|
<meta key="og:image" property="og:image" content={avatarUrls[0]} />
|
2022-11-21 03:52:24 +01:00
|
|
|
)}
|
|
|
|
<meta
|
|
|
|
key="og:description"
|
|
|
|
property="og:description"
|
|
|
|
content={description}
|
|
|
|
/>
|
2022-11-24 20:44:47 +01:00
|
|
|
<meta key="og:url" property="og:url" content={person.absoluteURL()} />
|
2022-11-21 03:52:24 +01:00
|
|
|
</Head>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function IsOwnUserPageNotice({ person }: { person: Person }) {
|
|
|
|
return useRecoilValue(userState)?.id === person.id ? (
|
|
|
|
<div className="lg:w-1/3 mx-auto bg-slate-100 dark:bg-slate-700 shadow rounded-md p-2">
|
|
|
|
You are currently viewing your <b>public</b> user profile.
|
|
|
|
<br />
|
|
|
|
<BlueLink to="/edit/profile">Edit your profile</BlueLink>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<></>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function MemberList({ user, className }: { user: User; className?: string }) {
|
2022-11-24 20:44:47 +01:00
|
|
|
const partialMembers = user.partialMembers;
|
2022-11-21 03:52:24 +01:00
|
|
|
return (
|
|
|
|
<div className={`mx-auto flex-col items-center ${className || ""}`}>
|
|
|
|
<h1 className="text-2xl">Members</h1>
|
|
|
|
<ul>
|
2022-11-24 20:44:47 +01:00
|
|
|
{partialMembers.map((partialMember) => (
|
2022-11-21 03:52:24 +01:00
|
|
|
<li className='before:[content:"-_"]' key={partialMember.id}>
|
|
|
|
<BlueLink to={`/u/${user.name}/${partialMember.name}`}>
|
2022-11-24 20:44:47 +01:00
|
|
|
<span>{partialMember.displayName ?? partialMember.name}</span>
|
2022-11-21 03:52:24 +01:00
|
|
|
</BlueLink>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function PersonAvatar({ person }: { person: Person }) {
|
2022-11-24 20:44:47 +01:00
|
|
|
const { displayName, name, avatarUrls } = person;
|
|
|
|
return avatarUrls && avatarUrls.length !== 0 ? (
|
2022-11-21 03:52:24 +01:00
|
|
|
<FallbackImage
|
|
|
|
className="max-w-xs rounded-full"
|
2022-11-24 20:44:47 +01:00
|
|
|
urls={avatarUrls}
|
|
|
|
alt={`${displayName || name}'s avatar`}
|
2022-11-21 03:52:24 +01:00
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<></>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function PersonInfo({ person }: { person: Person }) {
|
2022-11-24 20:44:47 +01:00
|
|
|
const { displayName, name, bio, links } = person;
|
2022-11-21 03:52:24 +01:00
|
|
|
return (
|
|
|
|
<div className="flex flex-col">
|
|
|
|
{/* name */}
|
2022-11-21 17:04:07 +01:00
|
|
|
<h1 className="text-2xl font-bold">
|
2022-11-24 20:44:47 +01:00
|
|
|
{displayName === null ? name : displayName}
|
2022-11-21 17:04:07 +01:00
|
|
|
</h1>
|
2022-11-21 04:16:07 +01:00
|
|
|
{/* handle */}
|
|
|
|
<h3 className="text-xl font-light text-slate-600 dark:text-slate-400">
|
2022-11-24 20:44:47 +01:00
|
|
|
{person.fullHandle()}
|
2022-11-21 03:52:24 +01:00
|
|
|
</h3>
|
|
|
|
{/* bio */}
|
|
|
|
{bio && (
|
|
|
|
<ReactMarkdown className="prose dark:prose-invert prose-slate">
|
|
|
|
{bio}
|
|
|
|
</ReactMarkdown>
|
|
|
|
)}
|
|
|
|
{/* links */}
|
2022-11-24 20:44:47 +01:00
|
|
|
{links.length > 0 && (
|
2022-11-21 03:52:24 +01:00
|
|
|
<div className="flex flex-col mx-auto lg:ml-auto">
|
|
|
|
{links.map((link, index) => (
|
|
|
|
<a
|
|
|
|
key={index}
|
|
|
|
href={link}
|
|
|
|
rel="nofollow noopener noreferrer me"
|
|
|
|
className="hover:underline text-sky-500 dark:text-sky-400"
|
|
|
|
>
|
|
|
|
{link}
|
|
|
|
</a>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-24 20:44:47 +01:00
|
|
|
function LabelList({ content }: { content: Label[] }) {
|
|
|
|
return content.length > 0 ? (
|
2022-11-21 03:52:24 +01:00
|
|
|
<div className="border-b border-slate-200 dark:border-slate-700">
|
|
|
|
{content.map((label, index) => (
|
|
|
|
<LabelLine key={index} label={label} />
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<></>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-24 20:44:47 +01:00
|
|
|
function LabelStatusIcon({ status }: { status: LabelStatus }) {
|
2022-11-21 03:52:24 +01:00
|
|
|
return React.createElement(
|
|
|
|
{
|
2022-11-24 20:44:47 +01:00
|
|
|
[LabelStatus.Favourite]: HeartFill,
|
|
|
|
[LabelStatus.Okay]: HandThumbsUp,
|
|
|
|
[LabelStatus.Jokingly]: EmojiLaughing,
|
|
|
|
[LabelStatus.FriendsOnly]: People,
|
|
|
|
[LabelStatus.Avoid]: HandThumbsDown,
|
2022-11-21 03:52:24 +01:00
|
|
|
}[status],
|
|
|
|
{ className: "inline" }
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-24 20:44:47 +01:00
|
|
|
function LabelsLine({
|
|
|
|
status,
|
|
|
|
texts,
|
|
|
|
}: {
|
|
|
|
status: LabelStatus;
|
|
|
|
texts: string[];
|
|
|
|
}) {
|
|
|
|
return !texts.length ? (
|
|
|
|
<></>
|
|
|
|
) : (
|
2022-11-21 03:52:24 +01:00
|
|
|
<p
|
|
|
|
className={`
|
2022-11-24 20:44:47 +01:00
|
|
|
${status === LabelStatus.Favourite ? "text-lg font-bold" : ""}
|
2022-11-21 03:52:24 +01:00
|
|
|
${
|
2022-11-24 20:44:47 +01:00
|
|
|
status === LabelStatus.Avoid ? "text-slate-600 dark:text-slate-400" : ""
|
2022-11-21 03:52:24 +01:00
|
|
|
}`}
|
|
|
|
>
|
2022-11-24 20:44:47 +01:00
|
|
|
<LabelStatusIcon status={status} /> {texts.join(", ")}
|
2022-11-21 03:52:24 +01:00
|
|
|
</p>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-24 20:44:47 +01:00
|
|
|
function LabelLine({ label }: { label: Label }) {
|
|
|
|
return <LabelsLine status={label.status} texts={[label.display()]} />;
|
2022-11-21 03:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function FieldCardGrid({ fields }: { fields: Field[] }) {
|
|
|
|
return (
|
|
|
|
<div className="flex flex-col md:flex-row gap-4 py-2 [&>*]:flex-1">
|
2022-11-24 20:44:47 +01:00
|
|
|
{fields.map((field, index) => (
|
2022-11-21 03:52:24 +01:00
|
|
|
<FieldCard field={field} key={index} />
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-24 20:44:47 +01:00
|
|
|
const labelStatusOrder: LabelStatus[] = [
|
|
|
|
LabelStatus.Favourite,
|
|
|
|
LabelStatus.Okay,
|
|
|
|
LabelStatus.Jokingly,
|
|
|
|
LabelStatus.FriendsOnly,
|
|
|
|
LabelStatus.Avoid,
|
|
|
|
];
|
2022-11-21 03:52:24 +01:00
|
|
|
|
|
|
|
function FieldCard({
|
|
|
|
field,
|
|
|
|
draggable,
|
|
|
|
}: {
|
|
|
|
field: Field;
|
|
|
|
draggable?: boolean;
|
|
|
|
}) {
|
|
|
|
return (
|
|
|
|
<Card title={field.name} draggable={draggable}>
|
2022-11-24 20:44:47 +01:00
|
|
|
{labelStatusOrder.map((status, i) => (
|
2022-11-21 03:52:24 +01:00
|
|
|
<LabelsLine
|
|
|
|
key={i}
|
2022-11-24 20:44:47 +01:00
|
|
|
status={status}
|
|
|
|
texts={field.labels
|
|
|
|
.filter((x) => x.status === status)
|
|
|
|
.map((x) => x.display())}
|
2022-11-21 03:52:24 +01:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
}
|