diff --git a/frontend/src/app.d.ts b/frontend/src/app.d.ts index 9176095..d4759fd 100644 --- a/frontend/src/app.d.ts +++ b/frontend/src/app.d.ts @@ -1,8 +1,15 @@ // See https://kit.svelte.dev/docs/types#app + +import type { ErrorCode } from "$lib/api/entities"; + // for information about these interfaces declare global { namespace App { - // interface Error {} + interface Error { + code: ErrorCode; + message?: string | undefined; + details?: string | undefined; + } // interface Locals {} // interface PageData {} // interface Platform {} diff --git a/frontend/src/lib/components/ActiveLink.svelte b/frontend/src/lib/components/ActiveLink.svelte new file mode 100644 index 0000000..d9bc887 --- /dev/null +++ b/frontend/src/lib/components/ActiveLink.svelte @@ -0,0 +1,10 @@ + + + + + diff --git a/frontend/src/routes/edit/EditableField.svelte b/frontend/src/lib/components/edit/EditableField.svelte similarity index 100% rename from frontend/src/routes/edit/EditableField.svelte rename to frontend/src/lib/components/edit/EditableField.svelte diff --git a/frontend/src/routes/edit/EditableName.svelte b/frontend/src/lib/components/edit/EditableName.svelte similarity index 100% rename from frontend/src/routes/edit/EditableName.svelte rename to frontend/src/lib/components/edit/EditableName.svelte diff --git a/frontend/src/routes/edit/EditablePronouns.svelte b/frontend/src/lib/components/edit/EditablePronouns.svelte similarity index 100% rename from frontend/src/routes/edit/EditablePronouns.svelte rename to frontend/src/lib/components/edit/EditablePronouns.svelte diff --git a/frontend/src/routes/edit/FieldEntry.svelte b/frontend/src/lib/components/edit/FieldEntry.svelte similarity index 100% rename from frontend/src/routes/edit/FieldEntry.svelte rename to frontend/src/lib/components/edit/FieldEntry.svelte diff --git a/frontend/src/routes/edit/FlagButton.svelte b/frontend/src/lib/components/edit/FlagButton.svelte similarity index 100% rename from frontend/src/routes/edit/FlagButton.svelte rename to frontend/src/lib/components/edit/FlagButton.svelte diff --git a/frontend/src/routes/edit/MarkdownHelp.svelte b/frontend/src/lib/components/edit/MarkdownHelp.svelte similarity index 100% rename from frontend/src/routes/edit/MarkdownHelp.svelte rename to frontend/src/lib/components/edit/MarkdownHelp.svelte diff --git a/frontend/src/routes/+error.svelte b/frontend/src/routes/+error.svelte index 21dc4d0..4b46c30 100644 --- a/frontend/src/routes/+error.svelte +++ b/frontend/src/routes/+error.svelte @@ -1,17 +1,24 @@ + + Error - pronouns.cc + +

An error occurred ({$page.status})

-{#if $page.status === 404} +{#if $page.error?.code === ErrorCode.NotFound}

The page you were looking for was not found. If you're sure the page exists, check for any typos in the address.

-{:else if $page.status === 429} +{:else if $page.error?.code === ErrorCode.Forbidden || $page.error?.code === ErrorCode.InvalidToken} +

You're not logged in, or you aren't allowed to access this page.

+{:else if $page.error?.code === 429}

You've exceeded a rate limit, please try again later.

-{:else if $page.status === 500} +{:else if $page.error?.code === 500}

An internal error occurred. Please try again later.

If this error keeps happening, please {/if} -

Error message: {$page.error?.message}

+

Error code: {$page.error?.code}

diff --git a/frontend/src/routes/@[username]/+error.svelte b/frontend/src/routes/@[username]/+error.svelte index 8e0cbbc..8ff04db 100644 --- a/frontend/src/routes/@[username]/+error.svelte +++ b/frontend/src/routes/@[username]/+error.svelte @@ -1,22 +1,39 @@ -

An error occurred ({$page.status})

+ + Error - pronouns.cc + -{#if $page.status === 404} -

The user you were looking for couldn't be found. Please check for any typos.

-{:else if $page.status === 429} -

You've exceeded a rate limit, please try again later.

-{:else if $page.status === 500} -

An internal error occurred. Please try again later.

+{#if $page.error?.code === ErrorCode.Forbidden || $page.error?.code === ErrorCode.InvalidToken} +

Not logged in

- If this error keeps happening, please file a bug report with an explanation of what you did to cause the error. + Either you aren't logged in, or your login has expired. Please log in again.

-{/if} +{:else if $page.error?.code === ErrorCode.NotOwnMember} +

Not your member

+

You can only edit your own members.

+{:else} +

An error occurred ({$page.status})

-

Error message: {$page.error?.message}

+ {#if $page.status === 404} +

The user you were looking for couldn't be found. Please check for any typos.

+ {:else if $page.status === 429} +

You've exceeded a rate limit, please try again later.

+ {:else if $page.status === 500} +

An internal error occurred. Please try again later.

+

+ If this error keeps happening, please file a bug report with an explanation of what you did to cause the error. +

+ {/if} + +

Error message: {$page.error?.message}

+{/if} diff --git a/frontend/src/routes/@[username]/+page.server.ts b/frontend/src/routes/@[username]/+page.server.ts index 9a4c26f..447c5e3 100644 --- a/frontend/src/routes/@[username]/+page.server.ts +++ b/frontend/src/routes/@[username]/+page.server.ts @@ -11,7 +11,7 @@ export const load = async ({ params }) => { return resp; } catch (e) { if ((e as APIError).code === ErrorCode.UserNotFound) { - throw error(404, (e as APIError).message); + throw error(404, e as APIError); } throw e; diff --git a/frontend/src/routes/@[username]/+page.svelte b/frontend/src/routes/@[username]/+page.svelte index 0492ad2..76da6de 100644 --- a/frontend/src/routes/@[username]/+page.svelte +++ b/frontend/src/routes/@[username]/+page.svelte @@ -164,7 +164,7 @@ {#if $userStore && $userStore.id === data.id} You are currently viewing your public profile. -
Edit your profile +
Edit your profile
{/if}
@@ -196,7 +196,7 @@

- Your profile is empty! You can customize it by going to the edit profile page. (only you can see this) diff --git a/frontend/src/routes/@[username]/[memberName]/+page.server.ts b/frontend/src/routes/@[username]/[memberName]/+page.server.ts index ab41c47..9b14e70 100644 --- a/frontend/src/routes/@[username]/[memberName]/+page.server.ts +++ b/frontend/src/routes/@[username]/[memberName]/+page.server.ts @@ -14,9 +14,9 @@ export const load = async ({ params }) => { (e as APIError).code === ErrorCode.UserNotFound || (e as APIError).code === ErrorCode.MemberNotFound ) { - throw error(404, (e as APIError).message); + throw error(404, e as APIError); } - throw error(500, (e as APIError).message); + throw error(500, e as APIError); } }; diff --git a/frontend/src/routes/@[username]/[memberName]/+page.svelte b/frontend/src/routes/@[username]/[memberName]/+page.svelte index 504448a..9089959 100644 --- a/frontend/src/routes/@[username]/[memberName]/+page.svelte +++ b/frontend/src/routes/@[username]/[memberName]/+page.svelte @@ -65,7 +65,7 @@ You are currently viewing the public profile of {data.display_name ?? data.name}. -
Edit profile +
Edit profile
{/if}

@@ -93,7 +93,7 @@

This member's profile is empty! You can customize it by going to the edit memberedit member page. (only you can see this)

diff --git a/frontend/src/routes/@[username]/[memberName]/edit/+layout.svelte b/frontend/src/routes/@[username]/[memberName]/edit/+layout.svelte new file mode 100644 index 0000000..b5e98a3 --- /dev/null +++ b/frontend/src/routes/@[username]/[memberName]/edit/+layout.svelte @@ -0,0 +1,170 @@ + + + + Edit member profile - pronouns.cc + + +

+ Edit profile + + + + + +

+ +{#if error} + +{/if} + + + +
+ +
+ + + +

+ If you want to delete this member, type {deleteModalPronoun} name ({$member.name}) below: +

+

+ +

+ {#if deleteError} + + {/if} +
+ + + + +
diff --git a/frontend/src/routes/@[username]/[memberName]/edit/+layout.ts b/frontend/src/routes/@[username]/[memberName]/edit/+layout.ts new file mode 100644 index 0000000..faa5c7a --- /dev/null +++ b/frontend/src/routes/@[username]/[memberName]/edit/+layout.ts @@ -0,0 +1,48 @@ +import { + type PrideFlag, + type MeUser, + type APIError, + type Member, + type PronounsJson, + ErrorCode, +} from "$lib/api/entities"; +import { apiFetchClient } from "$lib/api/fetch"; +import { error, redirect } from "@sveltejs/kit"; + +import pronounsRaw from "$lib/pronouns.json"; +import type { LayoutLoad } from "./$types"; +const pronouns = pronounsRaw as PronounsJson; + +export const ssr = false; + +export const load = (async ({ params }) => { + try { + const user = await apiFetchClient(`/users/@me`); + const member = await apiFetchClient( + `/users/${params.username}/members/${params.memberName}`, + ); + const flags = await apiFetchClient("/users/@me/flags"); + + if (user.id !== member.user.id) { + throw { code: ErrorCode.NotOwnMember, message: "Can only edit your own members" } as APIError; + } + + if ( + user.name !== params.username || + member.user.name !== params.username || + member.name !== params.memberName + ) { + throw redirect(303, `/@${user.name}/${member.name}`); + } + + return { + user, + member, + pronouns: pronouns.autocomplete, + flags, + }; + } catch (e) { + if ("code" in e) throw error(500, e as APIError); + throw e; + } +}) satisfies LayoutLoad; diff --git a/frontend/src/routes/@[username]/[memberName]/edit/+page.svelte b/frontend/src/routes/@[username]/[memberName]/edit/+page.svelte new file mode 100644 index 0000000..dbd4eaa --- /dev/null +++ b/frontend/src/routes/@[username]/[memberName]/edit/+page.svelte @@ -0,0 +1,151 @@ + + +
+
+
+
+ {#if $member.avatar === ""} + + {:else if $member.avatar} + New avatar + {:else} + + {/if} +
+
+ +

+ Only PNG, JPEG, GIF, and WebP images can be used + as avatars. Avatars cannot be larger than 1 MB, and animated avatars will be made static. +

+

+ + ($member.avatar = "")}>Remove avatar +

+
+
+
+
+ + +

+ + The member name is only used as part of the link to their profile page. +

+
+ {#if !memberNameValid} +

That member name is not valid.

+ {/if} + + + +

+ + Your display name is used in page titles and as a header. +

+
+
+
+

Names

+ {#each $member.names as _, index} + moveName(index, true)} + moveDown={() => moveName(index, false)} + remove={() => removeName(index)} + /> + {/each} +
+ + + +
diff --git a/frontend/src/routes/@[username]/[memberName]/edit/bio/+page.svelte b/frontend/src/routes/@[username]/[memberName]/edit/bio/+page.svelte new file mode 100644 index 0000000..76eb78b --- /dev/null +++ b/frontend/src/routes/@[username]/[memberName]/edit/bio/+page.svelte @@ -0,0 +1,29 @@ + + +
+