From 8aeefb56da3a96cd5a9e4d0c873826781ad9c040 Mon Sep 17 00:00:00 2001 From: hanabi Date: Sun, 20 Nov 2022 19:58:17 -0500 Subject: [PATCH] refactor: minor api change, type reafactor --- frontend/lib/types.ts | 67 ++++++++++++------------------- frontend/pages/u/[user]/index.tsx | 30 +++++++------- 2 files changed, 40 insertions(+), 57 deletions(-) diff --git a/frontend/lib/types.ts b/frontend/lib/types.ts index e2fcc18..d4a893c 100644 --- a/frontend/lib/types.ts +++ b/frontend/lib/types.ts @@ -1,43 +1,33 @@ +export interface PartialPerson { + id: string; + name: string; + display_name: string | null; + avatar_urls: string[] | null; +} +export type PartialUser = PartialPerson; +export type PartialMember = PartialPerson; + +export interface Person extends PartialPerson { + bio: string | null; + links: string[] | null; + names: Name[]; + pronouns: Pronoun[]; + fields: Field[]; +} + +export interface Member extends Person { + user?: PartialUser; +} + +export interface User extends Person { + members: PartialMember[]; +} + export interface MeUser extends User { discord: string | null; discord_username: string | null; } -export interface User { - id: string; - username: string; - display_name: string | null; - bio: string | null; - avatar_urls: string[] | null; - links: string[] | null; - members: PartialMember[]; - names: Name[]; - pronouns: Pronoun[]; - fields: Field[]; -} - -export interface PartialMember { - id: string; - name: string; - display_name: string | null; - avatar_urls: string[] | null; -} - -export interface Member extends PartialMember { - bio: string | null; - links: string[] | null; - id: string; - display_name: string | null; - name: string; - avatar_urls: string[] | null; - - names: Name[]; - pronouns: Pronoun[]; - fields: Field[]; - - user?: PartialUser; -} - export interface Name { name: string; status: WordStatus; @@ -109,10 +99,3 @@ export interface SignupResponse { user: MeUser; token: string; } - -export interface PartialUser { - id: string; - username: string; - display_name: string | null; - avatar_urls: string[] | null; -} diff --git a/frontend/pages/u/[user]/index.tsx b/frontend/pages/u/[user]/index.tsx index e70cd35..eb7d6bf 100644 --- a/frontend/pages/u/[user]/index.tsx +++ b/frontend/pages/u/[user]/index.tsx @@ -33,7 +33,7 @@ export default function Index({ user, partialMembers }: Props) { return ( <> - {`@${user.username} - pronouns.cc`} + {`@${user.name} - pronouns.cc`} @@ -62,11 +62,11 @@ export default function Index({ user, partialMembers }: Props) { } export const getServerSideProps: GetServerSideProps = async (context) => { - const username = context.params!.user; + const name = context.params!.user; try { const [userResponse, partialMembersResponse] = await Promise.allSettled([ - fetchAPI(`/users/${username}`), - fetchAPI(`/users/${username}/members`), + fetchAPI(`/users/${name}`), + fetchAPI(`/users/${name}/members`), ]); if (userResponse.status === "rejected") throw new Error("Could not fetch user"); @@ -90,7 +90,7 @@ function UserHead({ user }: { user: User }) { user.pronouns?.filter((pronoun) => pronoun.status === WordStatus.Favourite) ?.length ) { - description = `@${user.username} goes by ${user.names + description = `@${user.name} goes by ${user.names .filter((name) => name.status === WordStatus.Favourite) .map((name) => name.name) .join(", ")} and uses ${user.pronouns @@ -104,7 +104,7 @@ function UserHead({ user }: { user: User }) { } else if ( user.names?.filter((name) => name.status === WordStatus.Favourite)?.length ) { - description = `@${user.username} goes by ${user.names + description = `@${user.name} goes by ${user.names .filter((name) => name.status === WordStatus.Favourite) .map((name) => name.name) .join(", ")}.`; @@ -112,7 +112,7 @@ function UserHead({ user }: { user: User }) { user.pronouns?.filter((pronoun) => pronoun.status === WordStatus.Favourite) ?.length ) { - description = `@${user.username} uses ${user.pronouns + description = `@${user.name} uses ${user.pronouns .filter((pronoun) => pronoun.status === WordStatus.Favourite) .map( (pronoun) => @@ -135,8 +135,8 @@ function UserHead({ user }: { user: User }) { property="og:title" content={ user.display_name - ? `${user.display_name} (@${user.username})` - : `@${user.username}` + ? `${user.display_name} (@${user.name})` + : `@${user.name}` } /> {user.avatar_urls && user.avatar_urls.length > 0 ? ( @@ -156,7 +156,7 @@ function UserHead({ user }: { user: User }) { ); @@ -191,7 +191,7 @@ function MemberList({
    {partialMembers.map((partialMember) => (
  • - + {partialMember.display_name ?? partialMember.name}
  • @@ -206,7 +206,7 @@ function UserAvatar({ user }: { user: User }) { ) : ( <> @@ -214,12 +214,12 @@ function UserAvatar({ user }: { user: User }) { } function UserInfo({ user }: { user: User }) { - const { display_name, username, bio, links } = user; + const { display_name, name, bio, links } = user; return (
    {/* display name */} {display_name &&

    {display_name}

    } - {/* username */} + {/* name */}

    - @{username} + @{name}

    {/* bio */} {bio && (