feat: add avatar/bio/links/names/pronouns to user page
This commit is contained in:
parent
412d720abc
commit
862a64840e
16 changed files with 650 additions and 90 deletions
16
Foxnouns.Frontend/app/components/KeyedIcon.tsx
Normal file
16
Foxnouns.Frontend/app/components/KeyedIcon.tsx
Normal file
|
@ -0,0 +1,16 @@
|
|||
import * as icons from "react-bootstrap-icons";
|
||||
import { IconProps as BaseIconProps } from "react-bootstrap-icons";
|
||||
import { pascalCase } from "change-case";
|
||||
|
||||
const startsWithNumberRegex = /^\d/;
|
||||
|
||||
export default function Icon({ iconName, ...props }: BaseIconProps & { iconName: string }) {
|
||||
let icon = pascalCase(iconName);
|
||||
if (startsWithNumberRegex.test(icon)) {
|
||||
icon = `Icon${icon}`;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line import/namespace
|
||||
const BootstrapIcon = icons[icon as keyof typeof icons];
|
||||
return <BootstrapIcon {...props} />;
|
||||
}
|
27
Foxnouns.Frontend/app/components/ProfileLink.tsx
Normal file
27
Foxnouns.Frontend/app/components/ProfileLink.tsx
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { Globe } from "react-bootstrap-icons";
|
||||
|
||||
export default function ProfileLink({ link }: { link: string }) {
|
||||
const isLink = link.startsWith("http://") || link.startsWith("https://");
|
||||
|
||||
let displayLink = link;
|
||||
if (link.startsWith("http://")) displayLink = link.substring("http://".length);
|
||||
else if (link.startsWith("https://")) displayLink = link.substring("https://".length);
|
||||
if (displayLink.endsWith("/")) displayLink = displayLink.substring(0, displayLink.length - 1);
|
||||
|
||||
if (isLink) {
|
||||
return (
|
||||
<a href={link} className="text-decoration-none" rel="me nofollow noreferrer" target="_blank">
|
||||
<li className="py-2 py-lg-0">
|
||||
<Globe className="text-body" aria-hidden={true} />{" "}
|
||||
<span className="text-decoration-underline">{displayLink}</span>
|
||||
</li>
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<li className="py-2 py-lg-0">
|
||||
<Globe aria-hidden={true} /> {displayLink}
|
||||
</li>
|
||||
);
|
||||
}
|
32
Foxnouns.Frontend/app/components/PronounLink.tsx
Normal file
32
Foxnouns.Frontend/app/components/PronounLink.tsx
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { Pronoun } from "~/lib/api/user";
|
||||
import { Link } from "@remix-run/react";
|
||||
|
||||
export default function PronounLink({ pronoun }: { pronoun: Pronoun }) {
|
||||
let displayText: string;
|
||||
if (pronoun.display_text) displayText = pronoun.display_text;
|
||||
else {
|
||||
const split = pronoun.value.split("/");
|
||||
if (split.length === 5) displayText = split.splice(0, 2).join("/");
|
||||
else displayText = pronoun.value;
|
||||
}
|
||||
|
||||
let link: string;
|
||||
const linkBase = pronoun.value
|
||||
.split("/")
|
||||
.map((value) => encodeURIComponent(value))
|
||||
.join("/");
|
||||
|
||||
if (pronoun.display_text) {
|
||||
link = `${linkBase},${encodeURIComponent(pronoun.display_text)}`;
|
||||
} else {
|
||||
link = linkBase;
|
||||
}
|
||||
|
||||
return pronoun.value.split("/").length === 5 ? (
|
||||
<Link className="text-reset" to={`/pronouns/${link}`}>
|
||||
{displayText}
|
||||
</Link>
|
||||
) : (
|
||||
<>{displayText}</>
|
||||
);
|
||||
}
|
34
Foxnouns.Frontend/app/components/StatusIcon.tsx
Normal file
34
Foxnouns.Frontend/app/components/StatusIcon.tsx
Normal file
|
@ -0,0 +1,34 @@
|
|||
import { CustomPreference, defaultPreferences } from "~/lib/api/user";
|
||||
import { OverlayTrigger, Tooltip } from "react-bootstrap";
|
||||
import Icon from "~/components/KeyedIcon";
|
||||
|
||||
export default function StatusIcon({
|
||||
preferences,
|
||||
status,
|
||||
}: {
|
||||
preferences: Record<string, CustomPreference>;
|
||||
status: string;
|
||||
}) {
|
||||
const mergedPrefs = Object.assign({}, defaultPreferences, preferences);
|
||||
const currentPref = status in mergedPrefs ? mergedPrefs[status] : defaultPreferences.missing;
|
||||
|
||||
const id = crypto.randomUUID();
|
||||
return (
|
||||
<>
|
||||
<OverlayTrigger
|
||||
key={id}
|
||||
placement="top"
|
||||
overlay={
|
||||
<Tooltip id={id} aria-hidden={true}>
|
||||
{currentPref.tooltip}
|
||||
</Tooltip>
|
||||
}
|
||||
>
|
||||
<span className="d-inline-block">
|
||||
<Icon iconName={currentPref.icon} aria-hidden={true} style={{ pointerEvents: "none" }} />
|
||||
</span>
|
||||
</OverlayTrigger>
|
||||
<span className="visually-hidden">{currentPref.tooltip}:</span>
|
||||
</>
|
||||
);
|
||||
}
|
36
Foxnouns.Frontend/app/components/StatusLine.tsx
Normal file
36
Foxnouns.Frontend/app/components/StatusLine.tsx
Normal file
|
@ -0,0 +1,36 @@
|
|||
import {
|
||||
CustomPreference,
|
||||
defaultPreferences,
|
||||
FieldEntry,
|
||||
PreferenceSize,
|
||||
Pronoun,
|
||||
} from "~/lib/api/user";
|
||||
import classNames from "classnames";
|
||||
import { ReactNode } from "react";
|
||||
import StatusIcon from "~/components/StatusIcon";
|
||||
|
||||
export default function StatusLine({
|
||||
entry,
|
||||
preferences,
|
||||
children,
|
||||
}: {
|
||||
entry: FieldEntry | Pronoun;
|
||||
preferences: Record<string, CustomPreference>;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const mergedPrefs = Object.assign({}, defaultPreferences, preferences);
|
||||
const currentPref =
|
||||
entry.status in mergedPrefs ? mergedPrefs[entry.status] : defaultPreferences.missing;
|
||||
|
||||
const classes = classNames({
|
||||
"text-muted": currentPref.muted,
|
||||
"fw-bold fs-5": currentPref.size == PreferenceSize.Large,
|
||||
"fs-6": currentPref.size == PreferenceSize.Small,
|
||||
});
|
||||
|
||||
return (
|
||||
<span className={classes}>
|
||||
<StatusIcon preferences={preferences} status={entry.status} /> {children}
|
||||
</span>
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue