From f2a298da75b055a5377fc2939e9968a2759fad8f Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 20 Sep 2022 14:12:46 +0200 Subject: [PATCH] feat(frontend): support multiple avatar urls --- frontend/components/FallbackImage.tsx | 31 +++++++++++++++++++++++++++ frontend/components/FieldCard.tsx | 8 +++---- frontend/lib/types.ts | 22 +++++++++++++++++-- frontend/pages/u/[user]/index.tsx | 14 ++++++++---- 4 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 frontend/components/FallbackImage.tsx diff --git a/frontend/components/FallbackImage.tsx b/frontend/components/FallbackImage.tsx new file mode 100644 index 0000000..5ccca12 --- /dev/null +++ b/frontend/components/FallbackImage.tsx @@ -0,0 +1,31 @@ +import { HTMLAttributes } from "react"; + +export interface Props extends HTMLAttributes { + urls: string[]; + alt: string; +} + +export default function FallbackImage({ urls, alt, className }: Props) { + const fallbackUrl = urls.pop()!; + urls.push(fallbackUrl); + + return ( + + {urls.length !== 0 && + urls.map((url, key) => { + let contentType: string; + if (url.endsWith(".webp")) { + contentType = "image/webp"; + } else if (url.endsWith(".jpg") || url.endsWith(".jpeg")) { + contentType = "image/jpeg"; + } else if (url.endsWith(".png")) { + contentType = "image/png"; + } else { + contentType = "application/octet-stream"; + } + return ; + })} + {alt} + + ); +} diff --git a/frontend/components/FieldCard.tsx b/frontend/components/FieldCard.tsx index 29711ea..12846aa 100644 --- a/frontend/components/FieldCard.tsx +++ b/frontend/components/FieldCard.tsx @@ -39,22 +39,22 @@ export default function FieldCard({ {linkPronoun(entry)}

))} - {field.okay?.length !== 0 && ( + {field.okay && field.okay.length !== 0 && (

{field.okay!.join(", ")}

)} - {field.jokingly?.length !== 0 && ( + {field.jokingly && field.jokingly.length !== 0 && (

{field.jokingly!.join(", ")}

)} - {field.friends_only?.length !== 0 && ( + {field.friends_only && field.friends_only.length !== 0 && (

{field.friends_only!.join(", ")}

)} - {field.avoid?.length !== 0 && ( + {field.avoid && field.avoid.length !== 0 && (

{field.avoid!.join(", ")}

diff --git a/frontend/lib/types.ts b/frontend/lib/types.ts index d251838..38c6c78 100644 --- a/frontend/lib/types.ts +++ b/frontend/lib/types.ts @@ -1,5 +1,4 @@ export interface MeUser extends User { - avatar_source: string | null; discord: string | null; discord_username: string | null; } @@ -9,7 +8,7 @@ export interface User { username: string; display_name: string | null; bio: string | null; - avatar_url: string | null; + avatar_urls: string[] | null; links: string[] | null; members: PartialMember[]; fields: Field[]; @@ -21,6 +20,17 @@ export interface PartialMember { avatar_url: string | null; } +export interface Name { + name: string; + status: WordStatus; +} + +export interface Pronoun { + display_text?: string; + pronouns: string; + status: WordStatus; +} + export interface Field { name: string; favourite: string[] | null; @@ -36,6 +46,14 @@ export interface APIError { details?: string; } +export enum WordStatus { + Favourite = 1, + Okay = 2, + Jokingly = 3, + FriendsOnly = 4, + Avoid = 5, +} + export enum ErrorCode { BadRequest = 400, Forbidden = 403, diff --git a/frontend/pages/u/[user]/index.tsx b/frontend/pages/u/[user]/index.tsx index f425dd8..263c895 100644 --- a/frontend/pages/u/[user]/index.tsx +++ b/frontend/pages/u/[user]/index.tsx @@ -9,6 +9,7 @@ import Image from "next/image"; import { userState } from "../../../lib/state"; import { useRecoilValue } from "recoil"; import Link from "next/link"; +import FallbackImage from "../../../components/FallbackImage"; interface Props { user: User; @@ -39,13 +40,18 @@ export default function Index({ user }: Props) { )}
- {user.avatar_url && ( - // eslint-disable-next-line @next/next/no-img-element - {`@${user.username}'s + // eslint-disable-next-line @next/next/no-img-element + // {`@${user.username}'s )}
{user.display_name && (