From 37fe5813f0119638a1fb9f043d6622d37636611d Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 14 Mar 2023 00:42:44 +0100 Subject: [PATCH] feat(frontend): add field editing --- frontend/src/routes/edit/EditableField.svelte | 106 ++++++++++++++++++ frontend/src/routes/edit/profile/+page.svelte | 21 ++++ 2 files changed, 127 insertions(+) create mode 100644 frontend/src/routes/edit/EditableField.svelte diff --git a/frontend/src/routes/edit/EditableField.svelte b/frontend/src/routes/edit/EditableField.svelte new file mode 100644 index 0000000..5b8c380 --- /dev/null +++ b/frontend/src/routes/edit/EditableField.svelte @@ -0,0 +1,106 @@ + + +
+ + Name + + + + {#each field.entries as _, index} +
+ moveEntry(index, true)} + /> + moveEntry(index, false)} + /> + + (field.entries[index].status = WordStatus.Favourite)} + active={field.entries[index].status === WordStatus.Favourite} + /> + (field.entries[index].status = WordStatus.Okay)} + active={field.entries[index].status === WordStatus.Okay} + /> + (field.entries[index].status = WordStatus.Jokingly)} + active={field.entries[index].status === WordStatus.Jokingly} + /> + (field.entries[index].status = WordStatus.FriendsOnly)} + active={field.entries[index].status === WordStatus.FriendsOnly} + /> + (field.entries[index].status = WordStatus.Avoid)} + active={field.entries[index].status === WordStatus.Avoid} + /> + removeEntry(index)} + /> +
+ {/each} + +
+ + addEntry()} /> +
+
diff --git a/frontend/src/routes/edit/profile/+page.svelte b/frontend/src/routes/edit/profile/+page.svelte index 2ffb937..b80382b 100644 --- a/frontend/src/routes/edit/profile/+page.svelte +++ b/frontend/src/routes/edit/profile/+page.svelte @@ -16,6 +16,7 @@ import { encode } from "base64-arraybuffer"; import { apiFetchClient } from "$lib/api/fetch"; import IconButton from "$lib/components/IconButton.svelte"; + import EditableField from "../EditableField.svelte"; const MAX_AVATAR_BYTES = 1_000_000; @@ -196,6 +197,13 @@ else links = [...links.slice(0, index - 1), ...links.slice(0, index + 1)]; }; + const removeField = (index: number) => { + if (fields.length === 1) fields = []; + else if (index === 0) fields = fields.slice(1); + else if (index === fields.length - 1) fields = fields.slice(0, fields.length - 1); + else fields = [...fields.slice(0, index - 1), ...fields.slice(0, index + 1)]; + }; + const updateUser = async () => { try { const resp = await apiFetchClient("/users/@me", "PATCH", { @@ -419,5 +427,18 @@ +
+

+ Fields +

+ +
+
+ {#each fields as _, index} + removeField(index)} /> + {/each} +
{/if}