104 lines
2.9 KiB
TypeScript
104 lines
2.9 KiB
TypeScript
import Link from "next/link";
|
|||
|
|
|
||
|
|
import { POINTS, SIGNS } from "@/lib/astro";
|
||
|
|
import { type ForumAuthor, ago, memberHref } from "@/lib/forum";
|
||
|
|
|
||
|
|
import { Avatar } from "./Avatar";
|
||
|
|
|
||
|
|
/** "☉ Halak · ☽ Rák · Asz Szűz": the signs a member chose to share. */
|
||
|
|
export function signsText(signs: Record<string, string> | null | undefined): string | null {
|
||
|
|
if (!signs) return null;
|
||
|
|
const parts = Object.entries(signs)
|
||
|
|
.sort(([a], [b]) => order(a) - order(b))
|
||
|
|
.map(([point, sign]) => {
|
||
|
|
const name = SIGNS[sign]?.hu ?? sign;
|
||
|
|
return point === "ascendant" ? `Asz ${name}` : `${POINTS[point]?.glyph ?? point} ${name}`;
|
||
|
|
});
|
||
|
|
return parts.length ? parts.join(" · ") : null;
|
||
|
|
}
|
||
|
|
|
||
|
|
const ORDER = [
|
||
|
|
"sun",
|
||
|
|
"moon",
|
||
|
|
"ascendant",
|
||
|
|
"mercury",
|
||
|
|
"venus",
|
||
|
|
"mars",
|
||
|
|
"jupiter",
|
||
|
|
"saturn",
|
||
|
|
"uranus",
|
||
|
|
"neptune",
|
||
|
|
"pluto",
|
||
|
|
];
|
||
|
|
function order(point: string) {
|
||
|
|
const i = ORDER.indexOf(point);
|
||
|
|
return i < 0 ? 99 : i;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Who wrote it: avatar with the online dot, nickname, rank, badges, the
|
||
|
|
* shared signs and the time. A deleted account shows as "Törölt tag".
|
||
|
|
*/
|
||
|
|
export function AuthorLine({
|
||
|
|
author,
|
||
|
|
size = 40,
|
||
|
|
time,
|
||
|
|
edited = false,
|
||
|
|
badges,
|
||
|
|
signs = true,
|
||
|
|
}: {
|
||
|
|
author: ForumAuthor | null;
|
||
|
|
size?: number;
|
||
|
|
time?: string;
|
||
|
|
edited?: boolean;
|
||
|
|
badges?: React.ReactNode;
|
||
|
|
signs?: boolean;
|
||
|
|
}) {
|
||
|
|
if (!author) {
|
||
|
|
return (
|
||
|
|
<div className="fa-line">
|
||
|
|
<Avatar avatar={null} size={size} />
|
||
|
|
<span className="fa-meta">
|
||
|
|
<span className="fa-name muted">Törölt tag</span>
|
||
|
|
{time && <span className="fa-sub">{ago(time)}</span>}
|
||
|
|
</span>
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|
||
|
|
const shown = signs ? signsText(author.signs) : null;
|
||
|
|
return (
|
||
|
|
<div className="fa-line">
|
||
|
|
<Link href={memberHref(author.nickname)} className="fa-avatar" tabIndex={-1} aria-hidden="true">
|
||
|
|
<Avatar avatar={author.avatar} size={size} online={author.online} />
|
||
|
|
</Link>
|
||
|
|
<span className="fa-meta">
|
||
|
|
<span className="fa-names">
|
||
|
|
<Link href={memberHref(author.nickname)} className="fa-name">
|
||
|
|
{author.nickname}
|
||
|
|
</Link>
|
||
|
|
{author.online && <span className="sr-only">(online)</span>}
|
||
|
|
<span className="fa-rank">{author.rank_name}</span>
|
||
|
|
{author.moderator && <span className="fa-badge fa-badge-mod">Moderátor</span>}
|
||
|
|
{badges}
|
||
|
|
</span>
|
||
|
|
{(shown || time) && (
|
||
|
|
<span className="fa-sub">
|
||
|
|
{shown && <span className="sym">{shown}</span>}
|
||
|
|
{shown && time && " · "}
|
||
|
|
{time && (
|
||
|
|
<time
|
||
|
|
suppressHydrationWarning
|
||
|
|
dateTime={time}
|
||
|
|
title={new Date(time).toLocaleString("hu-HU", { timeZone: "Europe/Budapest" })}
|
||
|
|
>
|
||
|
|
{ago(time)}
|
||
|
|
</time>
|
||
|
|
)}
|
||
|
|
{edited && " · szerkesztve"}
|
||
|
|
</span>
|
||
|
|
)}
|
||
|
|
</span>
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|