From ba48ba0eb2cd2dd3ccb5fe47ed02d5d453e6848e Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 31 Mar 2023 00:11:28 +0200 Subject: [PATCH] feat: add names/pronouns/field entries on enter --- frontend/src/lib/components/IconButton.svelte | 3 +- frontend/src/routes/edit/EditableField.svelte | 10 ++- .../src/routes/edit/member/[id]/+page.svelte | 90 +++++++++++++------ frontend/src/routes/edit/member/[id]/+page.ts | 6 +- frontend/src/routes/edit/profile/+page.svelte | 37 ++++---- 5 files changed, 97 insertions(+), 49 deletions(-) diff --git a/frontend/src/lib/components/IconButton.svelte b/frontend/src/lib/components/IconButton.svelte index 580e63d..16473c5 100644 --- a/frontend/src/lib/components/IconButton.svelte +++ b/frontend/src/lib/components/IconButton.svelte @@ -6,6 +6,7 @@ export let tooltip: string; export let active: boolean = false; export let disabled: boolean = false; + export let type: string | undefined = undefined; export let click: ((e: MouseEvent) => void) | undefined = undefined; export let href: string | undefined = undefined; @@ -14,6 +15,6 @@ {tooltip} - diff --git a/frontend/src/routes/edit/EditableField.svelte b/frontend/src/routes/edit/EditableField.svelte index afa5fcc..446fe71 100644 --- a/frontend/src/routes/edit/EditableField.svelte +++ b/frontend/src/routes/edit/EditableField.svelte @@ -10,7 +10,9 @@ let newEntry: string = ""; - const addEntry = () => { + const addEntry = (event: Event) => { + event.preventDefault(); + field.entries = [...field.entries, { value: newEntry, status: WordStatus.Okay }]; newEntry = ""; }; @@ -61,8 +63,8 @@ /> {/each} -
+
- addEntry()} /> -
+ + diff --git a/frontend/src/routes/edit/member/[id]/+page.svelte b/frontend/src/routes/edit/member/[id]/+page.svelte index c8e701f..8b8c029 100644 --- a/frontend/src/routes/edit/member/[id]/+page.svelte +++ b/frontend/src/routes/edit/member/[id]/+page.svelte @@ -20,6 +20,7 @@ Modal, ModalBody, ModalFooter, + Popover, } from "sveltestrap"; import { encode } from "base64-arraybuffer"; import { apiFetchClient, fastFetchClient } from "$lib/api/fetch"; @@ -59,7 +60,6 @@ let newName = ""; let newPronouns = ""; - let newPronounsDisplay = ""; let newLink = ""; let modified = false; @@ -169,21 +169,38 @@ fields[newIndex] = temp; }; - const addName = () => { + const addName = (event: Event) => { + event.preventDefault(); + names = [...names, { value: newName, status: WordStatus.Okay }]; newName = ""; }; - const addPronouns = () => { - pronouns = [ - ...pronouns, - { pronouns: newPronouns, display_text: newPronounsDisplay || null, status: WordStatus.Okay }, - ]; + const addPronouns = (event: Event) => { + event.preventDefault(); + + if (newPronouns in data.pronouns) { + const fullSet = data.pronouns[newPronouns]; + pronouns = [ + ...pronouns, + { + pronouns: fullSet.pronouns.join("/"), + display_text: fullSet.display || null, + status: WordStatus.Okay, + }, + ]; + } else { + pronouns = [ + ...pronouns, + { pronouns: newPronouns, display_text: null, status: WordStatus.Okay }, + ]; + } newPronouns = ""; - newPronounsDisplay = ""; }; - const addLink = () => { + const addLink = (event: Event) => { + event.preventDefault(); + links = [...links, newLink]; newLink = ""; }; @@ -375,9 +392,10 @@
- -