From 1dc4089cef14f37671b8690871c1f4f224ea8910 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 21 Apr 2023 16:50:27 +0200 Subject: [PATCH] fix(frontend): use new but unsaved custom preferences on edit profile page --- frontend/src/lib/api/entities.ts | 9 --------- .../src/routes/edit/member/[id]/+page.svelte | 12 ++++-------- frontend/src/routes/edit/profile/+page.svelte | 16 +++++++--------- 3 files changed, 11 insertions(+), 26 deletions(-) diff --git a/frontend/src/lib/api/entities.ts b/frontend/src/lib/api/entities.ts index ccb3b22..267061e 100644 --- a/frontend/src/lib/api/entities.ts +++ b/frontend/src/lib/api/entities.ts @@ -67,15 +67,6 @@ export interface Pronoun { status: string; } -export enum WordStatus { - Unknown = "", - Favourite = "favourite", - Okay = "okay", - Jokingly = "jokingly", - FriendsOnly = "friends_only", - Avoid = "avoid", -} - export interface PartialMember { id: string; name: string; diff --git a/frontend/src/routes/edit/member/[id]/+page.svelte b/frontend/src/routes/edit/member/[id]/+page.svelte index f095364..8f8dab7 100644 --- a/frontend/src/routes/edit/member/[id]/+page.svelte +++ b/frontend/src/routes/edit/member/[id]/+page.svelte @@ -3,7 +3,6 @@ import { MAX_DESCRIPTION_LENGTH, memberAvatars, - WordStatus, type APIError, type Field, type FieldEntry, @@ -204,7 +203,7 @@ const addName = (event: Event) => { event.preventDefault(); - names = [...names, { value: newName, status: WordStatus.Okay }]; + names = [...names, { value: newName, status: "okay" }]; newName = ""; }; @@ -218,14 +217,11 @@ { pronouns: fullSet.pronouns.join("/"), display_text: fullSet.display || null, - status: WordStatus.Okay, + status: "okay", }, ]; } else { - pronouns = [ - ...pronouns, - { pronouns: newPronouns, display_text: null, status: WordStatus.Okay }, - ]; + pronouns = [...pronouns, { pronouns: newPronouns, display_text: null, status: "okay" }]; } newPronouns = ""; }; @@ -309,7 +305,7 @@ $: deleteModalPronoun = updateModalPronoun(pronouns); const updateModalPronoun = (pronouns: Pronoun[]) => { - const filtered = pronouns.filter((entry) => entry.status === WordStatus.Favourite); + const filtered = pronouns.filter((entry) => entry.status === "favourite"); if (filtered.length < 1) return "the member's"; const split = filtered[0].pronouns.split("/"); diff --git a/frontend/src/routes/edit/profile/+page.svelte b/frontend/src/routes/edit/profile/+page.svelte index a3ef65c..342837d 100644 --- a/frontend/src/routes/edit/profile/+page.svelte +++ b/frontend/src/routes/edit/profile/+page.svelte @@ -2,7 +2,6 @@ import { MAX_DESCRIPTION_LENGTH, userAvatars, - WordStatus, type APIError, type Field, type FieldEntry, @@ -218,7 +217,7 @@ const addName = (event: Event) => { event.preventDefault(); - names = [...names, { value: newName, status: WordStatus.Okay }]; + names = [...names, { value: newName, status: "okay" }]; newName = ""; }; @@ -232,14 +231,11 @@ { pronouns: fullSet.pronouns.join("/"), display_text: fullSet.display || null, - status: WordStatus.Okay, + status: "okay", }, ]; } else { - pronouns = [ - ...pronouns, - { pronouns: newPronouns, display_text: null, status: WordStatus.Okay }, - ]; + pronouns = [...pronouns, { pronouns: newPronouns, display_text: null, status: "okay" }]; } newPronouns = ""; }; @@ -311,6 +307,7 @@ }); data.user = resp; + custom_preferences = resp.custom_preferences; userStore.set(resp); localStorage.setItem("pronouns-user", JSON.stringify(resp)); @@ -411,7 +408,7 @@ moveName(index, true)} moveDown={() => moveName(index, false)} remove={() => removeName(index)} @@ -451,6 +448,7 @@ {#each pronouns as _, index} movePronoun(index, true)} moveDown={() => movePronoun(index, false)} remove={() => removePronoun(index)} @@ -492,7 +490,7 @@ {#each fields as _, index} removeField(index)} moveField={(up) => moveField(index, up)} />