feat(frontend): add members to user page
This commit is contained in:
parent
f81ae97821
commit
6f79d35f11
7 changed files with 212 additions and 94 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { CustomPreference, defaultPreferences } from "~/lib/api/user";
|
import { CustomPreference, defaultPreferences, mergePreferences } from "~/lib/api/user";
|
||||||
import { OverlayTrigger, Tooltip } from "react-bootstrap";
|
import { OverlayTrigger, Tooltip } from "react-bootstrap";
|
||||||
import Icon from "~/components/KeyedIcon";
|
import Icon from "~/components/KeyedIcon";
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ export default function StatusIcon({
|
||||||
preferences: Record<string, CustomPreference>;
|
preferences: Record<string, CustomPreference>;
|
||||||
status: string;
|
status: string;
|
||||||
}) {
|
}) {
|
||||||
const mergedPrefs = Object.assign({}, defaultPreferences, preferences);
|
const mergedPrefs = mergePreferences(preferences);
|
||||||
const currentPref = status in mergedPrefs ? mergedPrefs[status] : defaultPreferences.missing;
|
const currentPref = status in mergedPrefs ? mergedPrefs[status] : defaultPreferences.missing;
|
||||||
|
|
||||||
const id = crypto.randomUUID();
|
const id = crypto.randomUUID();
|
||||||
|
|
|
@ -2,11 +2,11 @@ import {
|
||||||
CustomPreference,
|
CustomPreference,
|
||||||
defaultPreferences,
|
defaultPreferences,
|
||||||
FieldEntry,
|
FieldEntry,
|
||||||
|
mergePreferences,
|
||||||
PreferenceSize,
|
PreferenceSize,
|
||||||
Pronoun,
|
Pronoun,
|
||||||
} from "~/lib/api/user";
|
} from "~/lib/api/user";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { ReactNode } from "react";
|
|
||||||
import StatusIcon from "~/components/StatusIcon";
|
import StatusIcon from "~/components/StatusIcon";
|
||||||
import PronounLink from "~/components/PronounLink";
|
import PronounLink from "~/components/PronounLink";
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ export default function StatusLine({
|
||||||
entry: FieldEntry | Pronoun;
|
entry: FieldEntry | Pronoun;
|
||||||
preferences: Record<string, CustomPreference>;
|
preferences: Record<string, CustomPreference>;
|
||||||
}) {
|
}) {
|
||||||
const mergedPrefs = Object.assign({}, defaultPreferences, preferences);
|
const mergedPrefs = mergePreferences(preferences);
|
||||||
const currentPref =
|
const currentPref =
|
||||||
entry.status in mergedPrefs ? mergedPrefs[entry.status] : defaultPreferences.missing;
|
entry.status in mergedPrefs ? mergedPrefs[entry.status] : defaultPreferences.missing;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ export type PartialUser = {
|
||||||
username: string;
|
username: string;
|
||||||
display_name?: string | null;
|
display_name?: string | null;
|
||||||
avatar_url?: string | null;
|
avatar_url?: string | null;
|
||||||
|
custom_preferences: Record<string, CustomPreference>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type User = PartialUser & {
|
export type User = PartialUser & {
|
||||||
|
@ -12,7 +13,6 @@ export type User = PartialUser & {
|
||||||
names: FieldEntry[];
|
names: FieldEntry[];
|
||||||
pronouns: Pronoun[];
|
pronouns: Pronoun[];
|
||||||
fields: Field[];
|
fields: Field[];
|
||||||
custom_preferences: Record<string, CustomPreference>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UserWithMembers = User & { members: PartialMember[] };
|
export type UserWithMembers = User & { members: PartialMember[] };
|
||||||
|
@ -35,6 +35,7 @@ export type PartialMember = {
|
||||||
avatar_url: string | null;
|
avatar_url: string | null;
|
||||||
names: FieldEntry[];
|
names: FieldEntry[];
|
||||||
pronouns: Pronoun[];
|
pronouns: Pronoun[];
|
||||||
|
unlisted: boolean | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FieldEntry = {
|
export type FieldEntry = {
|
||||||
|
@ -63,6 +64,10 @@ export enum PreferenceSize {
|
||||||
Small = "SMALL",
|
Small = "SMALL",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function mergePreferences(prefs: Record<string, CustomPreference>) {
|
||||||
|
return Object.assign({}, defaultPreferences, prefs);
|
||||||
|
}
|
||||||
|
|
||||||
export const defaultPreferences = Object.freeze({
|
export const defaultPreferences = Object.freeze({
|
||||||
favourite: {
|
favourite: {
|
||||||
icon: "heart-fill",
|
icon: "heart-fill",
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
export const defaultAvatarUrl = "https://pronouns.cc/default/512.webp";
|
|
@ -0,0 +1,74 @@
|
||||||
|
import {
|
||||||
|
defaultPreferences,
|
||||||
|
mergePreferences,
|
||||||
|
PartialMember,
|
||||||
|
PartialUser,
|
||||||
|
Pronoun,
|
||||||
|
} from "~/lib/api/user";
|
||||||
|
import { Link } from "@remix-run/react";
|
||||||
|
import { defaultAvatarUrl } from "~/lib/utils";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { OverlayTrigger, Tooltip } from "react-bootstrap";
|
||||||
|
import { Lock } from "react-bootstrap-icons";
|
||||||
|
|
||||||
|
export default function MemberCard({ user, member }: { user: PartialUser; member: PartialMember }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const mergedPrefs = mergePreferences(user.custom_preferences);
|
||||||
|
const pronouns: Pronoun[] = [];
|
||||||
|
for (const pronoun of member.pronouns) {
|
||||||
|
const pref =
|
||||||
|
pronoun.status in mergedPrefs ? mergedPrefs[pronoun.status] : defaultPreferences.missing;
|
||||||
|
if (pref.favourite) pronouns.push(pronoun);
|
||||||
|
}
|
||||||
|
|
||||||
|
const displayedPronouns = pronouns
|
||||||
|
.map((pronoun) => {
|
||||||
|
if (pronoun.display_text) {
|
||||||
|
return pronoun.display_text;
|
||||||
|
} else {
|
||||||
|
const split = pronoun.value.split("/");
|
||||||
|
if (split.length === 5) return split.splice(0, 2).join("/");
|
||||||
|
return pronoun.value;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.join(", ");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="col">
|
||||||
|
<Link to={`/@${user.username}/${member.name}`}>
|
||||||
|
<img
|
||||||
|
src={member.avatar_url || defaultAvatarUrl}
|
||||||
|
alt={t("user.member-avatar-alt", { name: member.name })}
|
||||||
|
width={200}
|
||||||
|
height={200}
|
||||||
|
loading="lazy"
|
||||||
|
className="rounded-circle img-fluid"
|
||||||
|
/>
|
||||||
|
</Link>
|
||||||
|
<p className="m-2">
|
||||||
|
<Link to={`/@${user.username}/${member.name}`}>
|
||||||
|
{member.display_name ?? member.name}
|
||||||
|
{member.unlisted === true && (
|
||||||
|
<>
|
||||||
|
<OverlayTrigger
|
||||||
|
key={member.id}
|
||||||
|
placement="top"
|
||||||
|
overlay={
|
||||||
|
<Tooltip id={member.id} aria-hidden={true}>
|
||||||
|
{t("user.member-hidden")}
|
||||||
|
</Tooltip>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<span className="d-inline-block">
|
||||||
|
<Lock aria-hidden={true} style={{ pointerEvents: "none" }} />
|
||||||
|
</span>
|
||||||
|
</OverlayTrigger>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Link>
|
||||||
|
{displayedPronouns && <>{displayedPronouns}</>}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -3,11 +3,14 @@ import { Link, redirect, useLoaderData, useRouteLoaderData } from "@remix-run/re
|
||||||
import { UserWithMembers } from "~/lib/api/user";
|
import { UserWithMembers } from "~/lib/api/user";
|
||||||
import serverRequest from "~/lib/request.server";
|
import serverRequest from "~/lib/request.server";
|
||||||
import { loader as rootLoader } from "~/root";
|
import { loader as rootLoader } from "~/root";
|
||||||
import { Alert } from "react-bootstrap";
|
import { Alert, Button } from "react-bootstrap";
|
||||||
import { Trans, useTranslation } from "react-i18next";
|
import { Trans, useTranslation } from "react-i18next";
|
||||||
import { renderMarkdown } from "~/lib/markdown";
|
import { renderMarkdown } from "~/lib/markdown";
|
||||||
import ProfileLink from "~/components/ProfileLink";
|
import ProfileLink from "~/components/ProfileLink";
|
||||||
import ProfileField from "~/components/ProfileField";
|
import ProfileField from "~/components/ProfileField";
|
||||||
|
import { PersonPlusFill } from "react-bootstrap-icons";
|
||||||
|
import { defaultAvatarUrl } from "~/lib/utils";
|
||||||
|
import MemberCard from "~/routes/$username/MemberCard";
|
||||||
|
|
||||||
export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||||
const { user } = data!;
|
const { user } = data!;
|
||||||
|
@ -39,16 +42,17 @@ export default function UserPage() {
|
||||||
const { user } = useLoaderData<typeof loader>();
|
const { user } = useLoaderData<typeof loader>();
|
||||||
const { meUser } = useRouteLoaderData<typeof rootLoader>("root") || { meUser: undefined };
|
const { meUser } = useRouteLoaderData<typeof rootLoader>("root") || { meUser: undefined };
|
||||||
|
|
||||||
|
const isMeUser = meUser && meUser.id === user.id;
|
||||||
const bio = renderMarkdown(user.bio);
|
const bio = renderMarkdown(user.bio);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{meUser && meUser.id === user.id && (
|
{isMeUser && (
|
||||||
<Alert variant="secondary">
|
<Alert variant="secondary">
|
||||||
<Trans t={t} i18nKey="user.own-profile-alert">
|
<Trans t={t} i18nKey="user.own-profile-alert">
|
||||||
You are currently viewing your <strong>public</strong> profile.
|
You are currently viewing your <strong>public</strong> profile.
|
||||||
<br />
|
<br />
|
||||||
<Link to={`/@${user.username}/edit`}>Edit your profile</Link>
|
<Link to="/edit/profile">Edit your profile</Link>
|
||||||
</Trans>
|
</Trans>
|
||||||
</Alert>
|
</Alert>
|
||||||
)}
|
)}
|
||||||
|
@ -56,7 +60,7 @@ export default function UserPage() {
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="col-md-4 text-center">
|
<div className="col-md-4 text-center">
|
||||||
<img
|
<img
|
||||||
src={user.avatar_url || "https://pronouns.cc/default/512.webp"}
|
src={user.avatar_url || defaultAvatarUrl}
|
||||||
alt={t("user.avatar-alt", { username: user.username })}
|
alt={t("user.avatar-alt", { username: user.username })}
|
||||||
width={200}
|
width={200}
|
||||||
height={200}
|
height={200}
|
||||||
|
@ -116,6 +120,39 @@ export default function UserPage() {
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{user.members.length > 0 ||
|
||||||
|
(isMeUser && (
|
||||||
|
<>
|
||||||
|
<hr />
|
||||||
|
<h2>
|
||||||
|
{user.member_title || t("user.heading.members")}{" "}
|
||||||
|
{/* @ts-expect-error using as=Link causes an error here, even though it runs completely fine */}
|
||||||
|
<Button as={Link} to="/settings/members/create" variant="success">
|
||||||
|
<PersonPlusFill /> {t("user.create-member-button")}
|
||||||
|
</Button>
|
||||||
|
</h2>
|
||||||
|
<div className="grid">
|
||||||
|
{user.members.length === 0 ? (
|
||||||
|
<div>
|
||||||
|
<Trans t={t} i18nKey="user.no-members-blurb">
|
||||||
|
You don't have any members yet.
|
||||||
|
<br />
|
||||||
|
Members are sub-profiles that can have their own avatar, names, pronouns, and preferred terms.
|
||||||
|
<br />
|
||||||
|
You can create a new member with the "Create member" button above.{" "}
|
||||||
|
<span className="text-muted">(only you can see this)</span>
|
||||||
|
</Trans>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="row row-cols-2 row-cols-md-3 row-cols-lg-4 row-cols-xl-5 text-center">
|
||||||
|
{user.members.map((member, i) => (
|
||||||
|
<MemberCard user={user} member={member} key={i} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
))}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,87 +1,88 @@
|
||||||
{
|
{
|
||||||
"error": {
|
"error": {
|
||||||
"heading": "An error occurred",
|
"heading": "An error occurred",
|
||||||
"validation": {
|
"validation": {
|
||||||
"too-long": "Value is too long, maximum length is {{maxLength}}, current length is {{actualLength}}.",
|
"too-long": "Value is too long, maximum length is {{maxLength}}, current length is {{actualLength}}.",
|
||||||
"too-short": "Value is too short, minimum length is {{minLength}}, current length is {{actualLength}}.",
|
"too-short": "Value is too short, minimum length is {{minLength}}, current length is {{actualLength}}.",
|
||||||
"disallowed-value": "The value <1>{{actualValue}}</1> is not allowed here. Allowed values are: <4>{{allowedValues}}</4>",
|
"disallowed-value": "The value <1>{{actualValue}}</1> is not allowed here. Allowed values are: <4>{{allowedValues}}</4>",
|
||||||
"generic": "The value <1>{{actualValue}}</1> is not allowed here. Reason: {{reason}}",
|
"generic": "The value <1>{{actualValue}}</1> is not allowed here. Reason: {{reason}}",
|
||||||
"generic-no-value": "The value you entered is not allowed here. Reason: {{reason}}"
|
"generic-no-value": "The value you entered is not allowed here. Reason: {{reason}}"
|
||||||
},
|
},
|
||||||
"errors": {
|
"errors": {
|
||||||
"authentication-error": "There was an error validating your credentials.",
|
"authentication-error": "There was an error validating your credentials.",
|
||||||
"authentication-required": "You need to log in.",
|
"authentication-required": "You need to log in.",
|
||||||
"bad-request": "Server rejected your input, please check anything for errors.",
|
"bad-request": "Server rejected your input, please check anything for errors.",
|
||||||
"forbidden": "You are not allowed to perform that action.",
|
"forbidden": "You are not allowed to perform that action.",
|
||||||
"generic-error": "An unknown error occurred.",
|
"generic-error": "An unknown error occurred.",
|
||||||
"internal-server-error": "Server experienced an internal error, please try again later.",
|
"internal-server-error": "Server experienced an internal error, please try again later.",
|
||||||
"member-not-found": "Member not found, please check your spelling and try again.",
|
"member-not-found": "Member not found, please check your spelling and try again.",
|
||||||
"user-not-found": "User not found, please check your spelling and try again."
|
"user-not-found": "User not found, please check your spelling and try again."
|
||||||
},
|
},
|
||||||
"title": "An error occurred",
|
"title": "An error occurred",
|
||||||
"more-info": "Click here for a more detailed error"
|
"more-info": "Click here for a more detailed error"
|
||||||
},
|
},
|
||||||
"navbar": {
|
"navbar": {
|
||||||
"view-profile": "View profile",
|
"view-profile": "View profile",
|
||||||
"settings": "Settings",
|
"settings": "Settings",
|
||||||
"log-out": "Log out",
|
"log-out": "Log out",
|
||||||
"log-in": "Log in or sign up",
|
"log-in": "Log in or sign up"
|
||||||
"theme": "Theme",
|
},
|
||||||
"theme-auto": "Automatic",
|
"user": {
|
||||||
"theme-dark": "Dark",
|
"member-avatar-alt": "Avatar for {{name}}",
|
||||||
"theme-light": "Light"
|
"member-hidden": "This member is unlisted, and not shown in your public member list.",
|
||||||
},
|
"own-profile-alert": "You are currently viewing your <1>public</1> profile.<3></3><4>Edit your profile</4>",
|
||||||
"user": {
|
"avatar-alt": "Avatar for @{{username}}",
|
||||||
"own-profile-alert": "You are currently viewing your <1>public</1> profile.<3></3><4>Edit your profile</4>",
|
"heading": {
|
||||||
"avatar-alt": "Avatar for @{{username}}",
|
"names": "Names",
|
||||||
"heading": {
|
"pronouns": "Pronouns",
|
||||||
"names": "Names",
|
"members": "Members"
|
||||||
"pronouns": "Pronouns"
|
},
|
||||||
}
|
"create-member-button": "Create member",
|
||||||
},
|
"no-members-blurb": "You don't have any members yet.<1></1>Members are sub-profiles that can have their own avatar, names, pronouns, and preferred terms.<3></3>You can create a new member with the \"Create member\" button above. <6>(only you can see this)</6>"
|
||||||
"log-in": {
|
},
|
||||||
"callback": {
|
"log-in": {
|
||||||
"title": {
|
"callback": {
|
||||||
"discord-success": "Log in with Discord",
|
"title": {
|
||||||
"discord-register": "Register with Discord"
|
"discord-success": "Log in with Discord",
|
||||||
},
|
"discord-register": "Register with Discord"
|
||||||
"success": "Successfully logged in!",
|
},
|
||||||
"success-link": "Welcome back, <1>@{{username}}</1>!",
|
"success": "Successfully logged in!",
|
||||||
"redirect-hint": "If you're not redirected to your profile in a few seconds, press the link above.",
|
"success-link": "Welcome back, <1>@{{username}}</1>!",
|
||||||
"remote-username": {
|
"redirect-hint": "If you're not redirected to your profile in a few seconds, press the link above.",
|
||||||
"discord": "Your discord username"
|
"remote-username": {
|
||||||
},
|
"discord": "Your discord username"
|
||||||
"username": "Username",
|
},
|
||||||
"sign-up-button": "Sign up",
|
"username": "Username",
|
||||||
"invalid-ticket": "Invalid ticket (it might have been too long since you logged in with Discord), please <2>try again</2>.",
|
"sign-up-button": "Sign up",
|
||||||
"invalid-username": "Invalid username",
|
"invalid-ticket": "Invalid ticket (it might have been too long since you logged in with Discord), please <2>try again</2>.",
|
||||||
"username-taken": "That username is already taken, please try something else."
|
"invalid-username": "Invalid username",
|
||||||
},
|
"username-taken": "That username is already taken, please try something else."
|
||||||
"title": "Log in",
|
},
|
||||||
"form-title": "Log in with email",
|
"title": "Log in",
|
||||||
"email": "Email address",
|
"form-title": "Log in with email",
|
||||||
"password": "Password",
|
"email": "Email address",
|
||||||
"log-in-button": "Log in",
|
"password": "Password",
|
||||||
"register-with-email": "Register with email",
|
"log-in-button": "Log in",
|
||||||
"3rd-party": {
|
"register-with-email": "Register with email",
|
||||||
"title": "Log in with another service",
|
"3rd-party": {
|
||||||
"desc": "If you prefer, you can also log in with one of these services:",
|
"title": "Log in with another service",
|
||||||
"discord": "Log in with Discord",
|
"desc": "If you prefer, you can also log in with one of these services:",
|
||||||
"google": "Log in with Google",
|
"discord": "Log in with Discord",
|
||||||
"tumblr": "Log in with Tumblr"
|
"google": "Log in with Google",
|
||||||
},
|
"tumblr": "Log in with Tumblr"
|
||||||
"invalid-credentials": "Invalid email address or password, please check your spelling and try again."
|
},
|
||||||
},
|
"invalid-credentials": "Invalid email address or password, please check your spelling and try again."
|
||||||
"welcome": {
|
},
|
||||||
"title": "Welcome",
|
"welcome": {
|
||||||
"header": "Welcome to pronouns.cc!",
|
"title": "Welcome",
|
||||||
"blurb": "{welcome.blurb}",
|
"header": "Welcome to pronouns.cc!",
|
||||||
"customize-profile": "Customize your profile",
|
"blurb": "{welcome.blurb}",
|
||||||
"customize-profile-blurb": "{welcome.customize-profile-blurb}",
|
"customize-profile": "Customize your profile",
|
||||||
"create-members": "Create members",
|
"customize-profile-blurb": "{welcome.customize-profile-blurb}",
|
||||||
"create-members-blurb": "{welcome.create-members-blurb}",
|
"create-members": "Create members",
|
||||||
"custom-preferences": "Customize your preferences",
|
"create-members-blurb": "{welcome.create-members-blurb}",
|
||||||
"custom-preferences-blurb": "{welcome.custom-preferences-blurb}",
|
"custom-preferences": "Customize your preferences",
|
||||||
"profile-button": "Go to your profile"
|
"custom-preferences-blurb": "{welcome.custom-preferences-blurb}",
|
||||||
}
|
"profile-button": "Go to your profile"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue