From 0bdd0148d2307e5aff89ccdac7d73863ffc393b9 Mon Sep 17 00:00:00 2001 From: sam Date: Sun, 29 Sep 2024 21:10:11 +0200 Subject: [PATCH] feat(frontend): member page --- .../app/components/profile/BaseProfile.tsx | 32 ++-- Foxnouns.Frontend/app/lib/api/member.ts | 4 +- .../app/routes/$username/route.tsx | 5 +- .../app/routes/$username_.$member/route.tsx | 64 +++++++ Foxnouns.Frontend/public/locales/en.json | 177 +++++++++--------- 5 files changed, 181 insertions(+), 101 deletions(-) create mode 100644 Foxnouns.Frontend/app/routes/$username_.$member/route.tsx diff --git a/Foxnouns.Frontend/app/components/profile/BaseProfile.tsx b/Foxnouns.Frontend/app/components/profile/BaseProfile.tsx index 4017877..a058755 100644 --- a/Foxnouns.Frontend/app/components/profile/BaseProfile.tsx +++ b/Foxnouns.Frontend/app/components/profile/BaseProfile.tsx @@ -10,14 +10,14 @@ import { renderMarkdown } from "~/lib/markdown"; export type Props = { name: string; fullName?: string; - avatarI18nKey: string; + userI18nKeys: boolean; profile: User | Member; customPreferences: Record; }; export default function BaseProfile({ name, - avatarI18nKey, + userI18nKeys, fullName, profile, customPreferences, @@ -30,13 +30,23 @@ export default function BaseProfile({
- {t(avatarI18nKey, + {userI18nKeys ? ( + {t("user.avatar-alt", + ) : ( + {t("member.avatar-alt", + )} {profile.flags && profile.bio && (
{profile.flags.map((f, i) => ( @@ -46,9 +56,9 @@ export default function BaseProfile({ )}
- {profile.display_name ? ( + {profile.display_name || fullName ? ( <> -

{profile.display_name}

+

{profile.display_name || name}

{fullName || `@${name}`}

) : ( diff --git a/Foxnouns.Frontend/app/lib/api/member.ts b/Foxnouns.Frontend/app/lib/api/member.ts index 7827f0a..1719f04 100644 --- a/Foxnouns.Frontend/app/lib/api/member.ts +++ b/Foxnouns.Frontend/app/lib/api/member.ts @@ -1,7 +1,9 @@ -import { Field, PartialMember, PrideFlag } from "~/lib/api/user"; +import { Field, PartialMember, PartialUser, PrideFlag } from "~/lib/api/user"; export type Member = PartialMember & { fields: Field[]; flags: PrideFlag[]; links: string[]; + + user: PartialUser; }; diff --git a/Foxnouns.Frontend/app/routes/$username/route.tsx b/Foxnouns.Frontend/app/routes/$username/route.tsx index af300d8..77f0f58 100644 --- a/Foxnouns.Frontend/app/routes/$username/route.tsx +++ b/Foxnouns.Frontend/app/routes/$username/route.tsx @@ -5,7 +5,6 @@ import serverRequest from "~/lib/request.server"; import { loader as rootLoader } from "~/root"; import { Alert, Button, Pagination } from "react-bootstrap"; import { Trans, useTranslation } from "react-i18next"; -import { renderMarkdown } from "~/lib/markdown"; import { PersonPlusFill } from "react-bootstrap-icons"; import MemberCard from "~/routes/$username/MemberCard"; import { ReactNode } from "react"; @@ -77,13 +76,13 @@ export default function UserPage() { You are currently viewing your public profile.
- Edit your profile + Edit your profile
)} diff --git a/Foxnouns.Frontend/app/routes/$username_.$member/route.tsx b/Foxnouns.Frontend/app/routes/$username_.$member/route.tsx new file mode 100644 index 0000000..d463fbf --- /dev/null +++ b/Foxnouns.Frontend/app/routes/$username_.$member/route.tsx @@ -0,0 +1,64 @@ +import { json, LoaderFunctionArgs, MetaFunction } from "@remix-run/node"; +import { Link, redirect, useLoaderData, useRouteLoaderData } from "@remix-run/react"; +import serverRequest from "~/lib/request.server"; +import { Member } from "~/lib/api/member"; +import BaseProfile from "~/components/profile/BaseProfile"; +import { loader as rootLoader } from "~/root"; +import { Alert, Button } from "react-bootstrap"; +import { Trans, useTranslation } from "react-i18next"; +import { ArrowLeft } from "react-bootstrap-icons"; + +export const meta: MetaFunction = ({ data }) => { + const { member } = data!; + + return [ + { title: `${member.display_name ?? member.name} • @${member.user.username} • pronouns.cc` }, + ]; +}; + +export const loader = async ({ params }: LoaderFunctionArgs) => { + let username = params.username!; + const memberName = params.member!; + if (!username.startsWith("@")) throw redirect(`/@${username}/${memberName}`); + username = username.substring("@".length); + + const member = await serverRequest("GET", `/users/${username}/members/${memberName}`); + return json({ member }); +}; + +export default function MemberPage() { + const { t } = useTranslation(); + const { member } = useLoaderData(); + const { meUser } = useRouteLoaderData("root") || { meUser: undefined }; + const isMeUser = meUser && meUser.id === member.user.id; + + const memberName = member.name; + + return ( + <> + {isMeUser && ( + + + You are currently viewing the public profile of {{ memberName }}. +
+ Edit your profile +
+
+ )} +
+ {/* @ts-expect-error using as=Link causes an error here, even though it runs completely fine */} + +
+ + + ); +} diff --git a/Foxnouns.Frontend/public/locales/en.json b/Foxnouns.Frontend/public/locales/en.json index 2a414ba..52464b5 100644 --- a/Foxnouns.Frontend/public/locales/en.json +++ b/Foxnouns.Frontend/public/locales/en.json @@ -1,88 +1,93 @@ { - "error": { - "heading": "An error occurred", - "validation": { - "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}}.", - "disallowed-value": "The value <1>{{actualValue}} is not allowed here. Allowed values are: <4>{{allowedValues}}", - "generic": "The value <1>{{actualValue}} is not allowed here. Reason: {{reason}}", - "generic-no-value": "The value you entered is not allowed here. Reason: {{reason}}" - }, - "errors": { - "authentication-error": "There was an error validating your credentials.", - "authentication-required": "You need to log in.", - "bad-request": "Server rejected your input, please check anything for errors.", - "forbidden": "You are not allowed to perform that action.", - "generic-error": "An unknown error occurred.", - "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.", - "user-not-found": "User not found, please check your spelling and try again." - }, - "title": "An error occurred", - "more-info": "Click here for a more detailed error" - }, - "navbar": { - "view-profile": "View profile", - "settings": "Settings", - "log-out": "Log out", - "log-in": "Log in or sign up" - }, - "user": { - "member-avatar-alt": "Avatar for {{name}}", - "member-hidden": "This member is unlisted, and not shown in your public member list.", - "own-profile-alert": "You are currently viewing your <1>public profile.<3><4>Edit your profile", - "avatar-alt": "Avatar for @{{username}}", - "heading": { - "names": "Names", - "pronouns": "Pronouns", - "members": "Members" - }, - "create-member-button": "Create member", - "no-members-blurb": "You don't have any members yet.<1>Members are sub-profiles that can have their own avatar, names, pronouns, and preferred terms.<3>You can create a new member with the \"Create member\" button above. <6>(only you can see this)" - }, - "log-in": { - "callback": { - "title": { - "discord-success": "Log in with Discord", - "discord-register": "Register with Discord" - }, - "success": "Successfully logged in!", - "success-link": "Welcome back, <1>@{{username}}!", - "redirect-hint": "If you're not redirected to your profile in a few seconds, press the link above.", - "remote-username": { - "discord": "Your discord username" - }, - "username": "Username", - "sign-up-button": "Sign up", - "invalid-ticket": "Invalid ticket (it might have been too long since you logged in with Discord), please <2>try again.", - "invalid-username": "Invalid username", - "username-taken": "That username is already taken, please try something else." - }, - "title": "Log in", - "form-title": "Log in with email", - "email": "Email address", - "password": "Password", - "log-in-button": "Log in", - "register-with-email": "Register with email", - "3rd-party": { - "title": "Log in with another service", - "desc": "If you prefer, you can also log in with one of these services:", - "discord": "Log in with Discord", - "google": "Log in with Google", - "tumblr": "Log in with Tumblr" - }, - "invalid-credentials": "Invalid email address or password, please check your spelling and try again." - }, - "welcome": { - "title": "Welcome", - "header": "Welcome to pronouns.cc!", - "blurb": "{welcome.blurb}", - "customize-profile": "Customize your profile", - "customize-profile-blurb": "{welcome.customize-profile-blurb}", - "create-members": "Create members", - "create-members-blurb": "{welcome.create-members-blurb}", - "custom-preferences": "Customize your preferences", - "custom-preferences-blurb": "{welcome.custom-preferences-blurb}", - "profile-button": "Go to your profile" - } + "error": { + "heading": "An error occurred", + "validation": { + "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}}.", + "disallowed-value": "The value <1>{{actualValue}} is not allowed here. Allowed values are: <4>{{allowedValues}}", + "generic": "The value <1>{{actualValue}} is not allowed here. Reason: {{reason}}", + "generic-no-value": "The value you entered is not allowed here. Reason: {{reason}}" + }, + "errors": { + "authentication-error": "There was an error validating your credentials.", + "authentication-required": "You need to log in.", + "bad-request": "Server rejected your input, please check anything for errors.", + "forbidden": "You are not allowed to perform that action.", + "generic-error": "An unknown error occurred.", + "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.", + "user-not-found": "User not found, please check your spelling and try again." + }, + "title": "An error occurred", + "more-info": "Click here for a more detailed error" + }, + "navbar": { + "view-profile": "View profile", + "settings": "Settings", + "log-out": "Log out", + "log-in": "Log in or sign up" + }, + "user": { + "avatar-alt": "Avatar for @{{username}}", + "heading": { + "names": "Names", + "pronouns": "Pronouns", + "members": "Members" + }, + "member-avatar-alt": "Avatar for {{name}}", + "member-hidden": "This member is unlisted, and not shown in your public member list.", + "own-profile-alert": "You are currently viewing your <1>public profile.<3><4>Edit your profile", + "create-member-button": "Create member", + "no-members-blurb": "You don't have any members yet.<1>Members are sub-profiles that can have their own avatar, names, pronouns, and preferred terms.<3>You can create a new member with the \"Create member\" button above. <6>(only you can see this)" + }, + "member": { + "avatar-alt": "Avatar for {{name}}", + "own-profile-alert": "You are currently viewing the <1>public profile of {{memberName}}.<5><6>Edit your profile", + "back": "Back to {{name}}" + }, + "log-in": { + "callback": { + "title": { + "discord-success": "Log in with Discord", + "discord-register": "Register with Discord" + }, + "success": "Successfully logged in!", + "success-link": "Welcome back, <1>@{{username}}!", + "redirect-hint": "If you're not redirected to your profile in a few seconds, press the link above.", + "remote-username": { + "discord": "Your discord username" + }, + "username": "Username", + "sign-up-button": "Sign up", + "invalid-ticket": "Invalid ticket (it might have been too long since you logged in with Discord), please <2>try again.", + "invalid-username": "Invalid username", + "username-taken": "That username is already taken, please try something else." + }, + "title": "Log in", + "form-title": "Log in with email", + "email": "Email address", + "password": "Password", + "log-in-button": "Log in", + "register-with-email": "Register with email", + "3rd-party": { + "title": "Log in with another service", + "desc": "If you prefer, you can also log in with one of these services:", + "discord": "Log in with Discord", + "google": "Log in with Google", + "tumblr": "Log in with Tumblr" + }, + "invalid-credentials": "Invalid email address or password, please check your spelling and try again." + }, + "welcome": { + "title": "Welcome", + "header": "Welcome to pronouns.cc!", + "blurb": "{welcome.blurb}", + "customize-profile": "Customize your profile", + "customize-profile-blurb": "{welcome.customize-profile-blurb}", + "create-members": "Create members", + "create-members-blurb": "{welcome.create-members-blurb}", + "custom-preferences": "Customize your preferences", + "custom-preferences-blurb": "{welcome.custom-preferences-blurb}", + "profile-button": "Go to your profile" + } }