fix(frontend): use new but unsaved custom preferences on edit profile page

This commit is contained in:
Sam 2023-04-21 16:50:27 +02:00
parent bd279a7dae
commit 1dc4089cef
No known key found for this signature in database
GPG Key ID: B4EF20DDE721CAA1
3 changed files with 11 additions and 26 deletions

View File

@ -67,15 +67,6 @@ export interface Pronoun {
status: string; status: string;
} }
export enum WordStatus {
Unknown = "",
Favourite = "favourite",
Okay = "okay",
Jokingly = "jokingly",
FriendsOnly = "friends_only",
Avoid = "avoid",
}
export interface PartialMember { export interface PartialMember {
id: string; id: string;
name: string; name: string;

View File

@ -3,7 +3,6 @@
import { import {
MAX_DESCRIPTION_LENGTH, MAX_DESCRIPTION_LENGTH,
memberAvatars, memberAvatars,
WordStatus,
type APIError, type APIError,
type Field, type Field,
type FieldEntry, type FieldEntry,
@ -204,7 +203,7 @@
const addName = (event: Event) => { const addName = (event: Event) => {
event.preventDefault(); event.preventDefault();
names = [...names, { value: newName, status: WordStatus.Okay }]; names = [...names, { value: newName, status: "okay" }];
newName = ""; newName = "";
}; };
@ -218,14 +217,11 @@
{ {
pronouns: fullSet.pronouns.join("/"), pronouns: fullSet.pronouns.join("/"),
display_text: fullSet.display || null, display_text: fullSet.display || null,
status: WordStatus.Okay, status: "okay",
}, },
]; ];
} else { } else {
pronouns = [ pronouns = [...pronouns, { pronouns: newPronouns, display_text: null, status: "okay" }];
...pronouns,
{ pronouns: newPronouns, display_text: null, status: WordStatus.Okay },
];
} }
newPronouns = ""; newPronouns = "";
}; };
@ -309,7 +305,7 @@
$: deleteModalPronoun = updateModalPronoun(pronouns); $: deleteModalPronoun = updateModalPronoun(pronouns);
const updateModalPronoun = (pronouns: Pronoun[]) => { 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"; if (filtered.length < 1) return "the member's";
const split = filtered[0].pronouns.split("/"); const split = filtered[0].pronouns.split("/");

View File

@ -2,7 +2,6 @@
import { import {
MAX_DESCRIPTION_LENGTH, MAX_DESCRIPTION_LENGTH,
userAvatars, userAvatars,
WordStatus,
type APIError, type APIError,
type Field, type Field,
type FieldEntry, type FieldEntry,
@ -218,7 +217,7 @@
const addName = (event: Event) => { const addName = (event: Event) => {
event.preventDefault(); event.preventDefault();
names = [...names, { value: newName, status: WordStatus.Okay }]; names = [...names, { value: newName, status: "okay" }];
newName = ""; newName = "";
}; };
@ -232,14 +231,11 @@
{ {
pronouns: fullSet.pronouns.join("/"), pronouns: fullSet.pronouns.join("/"),
display_text: fullSet.display || null, display_text: fullSet.display || null,
status: WordStatus.Okay, status: "okay",
}, },
]; ];
} else { } else {
pronouns = [ pronouns = [...pronouns, { pronouns: newPronouns, display_text: null, status: "okay" }];
...pronouns,
{ pronouns: newPronouns, display_text: null, status: WordStatus.Okay },
];
} }
newPronouns = ""; newPronouns = "";
}; };
@ -311,6 +307,7 @@
}); });
data.user = resp; data.user = resp;
custom_preferences = resp.custom_preferences;
userStore.set(resp); userStore.set(resp);
localStorage.setItem("pronouns-user", JSON.stringify(resp)); localStorage.setItem("pronouns-user", JSON.stringify(resp));
@ -411,7 +408,7 @@
<EditableName <EditableName
bind:value={names[index].value} bind:value={names[index].value}
bind:status={names[index].status} bind:status={names[index].status}
preferences={data.user.custom_preferences} preferences={custom_preferences}
moveUp={() => moveName(index, true)} moveUp={() => moveName(index, true)}
moveDown={() => moveName(index, false)} moveDown={() => moveName(index, false)}
remove={() => removeName(index)} remove={() => removeName(index)}
@ -451,6 +448,7 @@
{#each pronouns as _, index} {#each pronouns as _, index}
<EditablePronouns <EditablePronouns
bind:pronoun={pronouns[index]} bind:pronoun={pronouns[index]}
preferences={custom_preferences}
moveUp={() => movePronoun(index, true)} moveUp={() => movePronoun(index, true)}
moveDown={() => movePronoun(index, false)} moveDown={() => movePronoun(index, false)}
remove={() => removePronoun(index)} remove={() => removePronoun(index)}
@ -492,7 +490,7 @@
{#each fields as _, index} {#each fields as _, index}
<EditableField <EditableField
bind:field={fields[index]} bind:field={fields[index]}
preferences={data.user.custom_preferences} preferences={custom_preferences}
deleteField={() => removeField(index)} deleteField={() => removeField(index)}
moveField={(up) => moveField(index, up)} moveField={(up) => moveField(index, up)}
/> />