2022-08-16 18:04:06 -07:00
|
|
|
import { GetServerSideProps } from "next";
|
|
|
|
import Head from "next/head";
|
|
|
|
import fetchAPI from "../../../lib/fetch";
|
2022-11-17 08:33:59 -08:00
|
|
|
import { Name, Pronoun, User, WordStatus } from "../../../lib/types";
|
2022-08-16 18:04:06 -07:00
|
|
|
import FieldCard from "../../../components/FieldCard";
|
|
|
|
import Card from "../../../components/Card";
|
|
|
|
import ReactMarkdown from "react-markdown";
|
2022-09-05 16:01:24 -07:00
|
|
|
import Image from "next/image";
|
2022-09-15 15:49:04 -07:00
|
|
|
import { userState } from "../../../lib/state";
|
|
|
|
import { useRecoilValue } from "recoil";
|
|
|
|
import Link from "next/link";
|
2022-09-20 05:12:46 -07:00
|
|
|
import FallbackImage from "../../../components/FallbackImage";
|
2022-11-17 08:33:59 -08:00
|
|
|
import { ReactNode } from "react";
|
2022-11-18 05:11:52 -08:00
|
|
|
import {
|
|
|
|
EmojiLaughing,
|
|
|
|
HandThumbsDown,
|
|
|
|
HandThumbsUp,
|
|
|
|
HeartFill,
|
|
|
|
People,
|
|
|
|
} from "react-bootstrap-icons";
|
2022-11-18 06:26:52 -08:00
|
|
|
import BlueLink from "../../../components/BlueLink";
|
2022-08-16 18:04:06 -07:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
user: User;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function Index({ user }: Props) {
|
2022-09-15 15:49:04 -07:00
|
|
|
const isMeUser = useRecoilValue(userState)?.id === user.id;
|
|
|
|
|
2022-08-16 18:04:06 -07:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Head>
|
|
|
|
<title key="title">@{user.username} - pronouns.cc</title>
|
|
|
|
</Head>
|
2022-09-15 15:49:04 -07:00
|
|
|
{isMeUser && (
|
|
|
|
<div className="lg:w-1/3 mx-auto bg-slate-100 dark:bg-slate-700 shadow rounded-md p-2">
|
|
|
|
<span>
|
|
|
|
You are currently viewing your{" "}
|
|
|
|
<span className="font-bold">public</span> profile.
|
|
|
|
</span>
|
|
|
|
<br />
|
2022-11-18 06:26:52 -08:00
|
|
|
<BlueLink to="/edit/profile">Edit your profile</BlueLink>
|
2022-09-15 15:49:04 -07:00
|
|
|
</div>
|
|
|
|
)}
|
2022-08-16 18:04:06 -07:00
|
|
|
<div className="container mx-auto">
|
|
|
|
<div className="flex flex-col m-2 p-2 lg:flex-row justify-center lg:justify-start items-center space-y-4 lg:space-y-0 lg:space-x-16 lg:items-start border-b border-slate-200 dark:border-slate-700">
|
2022-09-20 05:12:46 -07:00
|
|
|
{user.avatar_urls && user.avatar_urls.length !== 0 && (
|
|
|
|
<FallbackImage
|
2022-09-05 16:01:24 -07:00
|
|
|
className="max-w-xs rounded-full"
|
2022-09-20 05:12:46 -07:00
|
|
|
urls={user.avatar_urls}
|
2022-09-05 16:01:24 -07:00
|
|
|
alt={`@${user.username}'s avatar`}
|
|
|
|
/>
|
2022-08-16 18:04:06 -07:00
|
|
|
)}
|
|
|
|
<div className="flex flex-col">
|
|
|
|
{user.display_name && (
|
|
|
|
<h1 className="text-2xl font-bold">{user.display_name}</h1>
|
|
|
|
)}
|
|
|
|
<h3
|
2022-11-18 05:11:52 -08:00
|
|
|
className={`${
|
|
|
|
user.display_name
|
|
|
|
? "text-xl italic text-slate-600 dark:text-slate-400"
|
|
|
|
: "text-2xl font-bold"
|
|
|
|
}`}
|
2022-08-16 18:04:06 -07:00
|
|
|
>
|
|
|
|
@{user.username}
|
|
|
|
</h3>
|
|
|
|
{user.bio && (
|
|
|
|
<ReactMarkdown className="prose dark:prose-invert prose-slate">
|
|
|
|
{user.bio}
|
|
|
|
</ReactMarkdown>
|
|
|
|
)}
|
2022-11-17 08:33:59 -08:00
|
|
|
{user.links?.length && (
|
2022-08-16 18:04:06 -07:00
|
|
|
<div className="flex flex-col mx-auto lg:ml-auto">
|
|
|
|
{user.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>
|
|
|
|
</div>
|
2022-11-18 05:11:52 -08:00
|
|
|
{user.names?.length > 0 && (
|
|
|
|
<div className="border-b border-slate-200 dark:border-slate-700">
|
|
|
|
{user.names.map((name, index) => (
|
|
|
|
<NameEntry name={name} key={index} />
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{user.pronouns?.length > 0 && (
|
|
|
|
<div className="border-b border-slate-200 dark:border-slate-700">
|
|
|
|
{user.pronouns.map((pronoun, index) => (
|
|
|
|
<PronounEntry pronoun={pronoun} key={index} />
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)}
|
2022-08-16 18:04:06 -07:00
|
|
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 py-2">
|
|
|
|
{user.fields?.map((field, index) => (
|
|
|
|
<FieldCard key={index} field={field}></FieldCard>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-17 08:33:59 -08:00
|
|
|
const entryIcon = (status: WordStatus) => {
|
|
|
|
let icon: ReactNode;
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
case WordStatus.Favourite:
|
|
|
|
icon = <HeartFill className="inline" />;
|
|
|
|
break;
|
|
|
|
case WordStatus.Okay:
|
|
|
|
icon = <HandThumbsUp className="inline" />;
|
|
|
|
break;
|
|
|
|
case WordStatus.Jokingly:
|
|
|
|
icon = <EmojiLaughing className="inline" />;
|
|
|
|
break;
|
|
|
|
case WordStatus.FriendsOnly:
|
2022-11-18 05:11:52 -08:00
|
|
|
icon = <People className="inline" />;
|
2022-11-17 08:33:59 -08:00
|
|
|
break;
|
|
|
|
case WordStatus.Avoid:
|
2022-11-18 05:11:52 -08:00
|
|
|
icon = <HandThumbsDown className="inline" />;
|
2022-11-17 08:33:59 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return icon;
|
2022-11-18 05:11:52 -08:00
|
|
|
};
|
2022-11-17 08:33:59 -08:00
|
|
|
|
|
|
|
function NameEntry(props: { name: Name }) {
|
|
|
|
const { name } = props;
|
|
|
|
|
2022-11-18 05:11:52 -08:00
|
|
|
return (
|
|
|
|
<p
|
|
|
|
className={`text-lg ${
|
|
|
|
name.status === WordStatus.Favourite && "font-bold"
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
{entryIcon(name.status)} {name.name}
|
|
|
|
</p>
|
|
|
|
);
|
2022-11-17 08:33:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function PronounEntry(props: { pronoun: Pronoun }) {
|
|
|
|
const { pronoun } = props;
|
|
|
|
|
2022-11-18 05:11:52 -08:00
|
|
|
return (
|
|
|
|
<p
|
|
|
|
className={`text-lg ${
|
|
|
|
pronoun.status === WordStatus.Favourite && "font-bold"
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
{entryIcon(pronoun.status)}{" "}
|
|
|
|
{pronoun.display_text ??
|
|
|
|
pronoun.pronouns.split("/").slice(0, 2).join("/")}
|
|
|
|
</p>
|
|
|
|
);
|
2022-11-17 08:33:59 -08:00
|
|
|
}
|
|
|
|
|
2022-08-16 18:04:06 -07:00
|
|
|
export const getServerSideProps: GetServerSideProps = async (context) => {
|
|
|
|
try {
|
|
|
|
const user = await fetchAPI<User>(`/users/${context.params!.user}`);
|
|
|
|
|
|
|
|
return { props: { user } };
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
|
|
|
|
return { notFound: true };
|
|
|
|
}
|
|
|
|
};
|