diff --git a/Foxnouns.Frontend/src/lib/components/editor/LinksEditor.svelte b/Foxnouns.Frontend/src/lib/components/editor/LinksEditor.svelte new file mode 100644 index 0000000..f908e0e --- /dev/null +++ b/Foxnouns.Frontend/src/lib/components/editor/LinksEditor.svelte @@ -0,0 +1,84 @@ + + +

+ {$t("editor.links-header")} + +

+ + + +{#each links as _, index} +
+ moveValue(index, true)} + /> + moveValue(index, false)} + /> + + removeValue(index)} + /> +
+{/each} + +
+ + + diff --git a/Foxnouns.Frontend/src/lib/components/profile/ProfileLink.svelte b/Foxnouns.Frontend/src/lib/components/profile/ProfileLink.svelte index d4672a8..0a42c58 100644 --- a/Foxnouns.Frontend/src/lib/components/profile/ProfileLink.svelte +++ b/Foxnouns.Frontend/src/lib/components/profile/ProfileLink.svelte @@ -9,7 +9,7 @@ if (raw.startsWith("https://")) out = raw.substring("https://".length); else if (raw.startsWith("http://")) out = raw.substring("http://".length); - if (raw.endsWith("/")) out = raw.substring(0, raw.length - 1); + if (out.endsWith("/")) out = out.substring(0, out.length - 1); return out; }; diff --git a/Foxnouns.Frontend/src/lib/i18n/locales/en.json b/Foxnouns.Frontend/src/lib/i18n/locales/en.json index eb80a83..f3a7d87 100644 --- a/Foxnouns.Frontend/src/lib/i18n/locales/en.json +++ b/Foxnouns.Frontend/src/lib/i18n/locales/en.json @@ -202,7 +202,8 @@ "flag-search-no-flags": "No flags matched your search query.", "flag-search-no-account-flags": "You haven't uploaded any flags yet.", "flag-search-hint": "Can't find the flag you're looking for? Try using the search bar above.", - "flag-manage-your-flags": "Manage your flags" + "flag-manage-your-flags": "Manage your flags", + "links-header": "Links" }, "cancel": "Cancel" } diff --git a/Foxnouns.Frontend/src/routes/settings/members/[id]/flags-links/+page.svelte b/Foxnouns.Frontend/src/routes/settings/members/[id]/flags-links/+page.svelte index db35e18..b6aaadb 100644 --- a/Foxnouns.Frontend/src/routes/settings/members/[id]/flags-links/+page.svelte +++ b/Foxnouns.Frontend/src/routes/settings/members/[id]/flags-links/+page.svelte @@ -2,6 +2,7 @@ import { fastRequest } from "$api"; import type { RawApiError } from "$api/error"; import ApiError from "$api/error"; + import LinksEditor from "$components/editor/LinksEditor.svelte"; import ProfileFlagsEditor from "$components/editor/ProfileFlagsEditor.svelte"; import log from "$lib/log"; import type { PageData } from "./$types"; @@ -9,20 +10,41 @@ type Props = { data: PageData }; let { data }: Props = $props(); - let form: { ok: boolean; error: RawApiError | null } | null = $state(null); + let flagForm: { ok: boolean; error: RawApiError | null } | null = $state(null); + let linksForm: { ok: boolean; error: RawApiError | null } | null = $state(null); - const save = async (flags: string[]) => { + const flagSave = async (flags: string[]) => { try { await fastRequest("PATCH", `/users/@me/members/${data.member.id}`, { body: { flags }, token: data.token, }); - form = { ok: true, error: null }; + flagForm = { ok: true, error: null }; } catch (e) { log.error("Could not update profile flags for member %s:", data.member.id, e); - if (e instanceof ApiError) form = { ok: false, error: e.obj }; + if (e instanceof ApiError) flagForm = { ok: false, error: e.obj }; + } + }; + + const linksSave = async (links: string[]) => { + try { + await fastRequest("PATCH", "/users/@me", { + body: { links }, + token: data.token, + }); + linksForm = { ok: true, error: null }; + } catch (e) { + log.error("Could not update profile links:", e); + if (e instanceof ApiError) linksForm = { ok: false, error: e.obj }; } }; - + + + diff --git a/Foxnouns.Frontend/src/routes/settings/profile/flags-links/+page.svelte b/Foxnouns.Frontend/src/routes/settings/profile/flags-links/+page.svelte index 0273e6b..4b2b165 100644 --- a/Foxnouns.Frontend/src/routes/settings/profile/flags-links/+page.svelte +++ b/Foxnouns.Frontend/src/routes/settings/profile/flags-links/+page.svelte @@ -2,6 +2,7 @@ import { fastRequest } from "$api"; import type { RawApiError } from "$api/error"; import ApiError from "$api/error"; + import LinksEditor from "$components/editor/LinksEditor.svelte"; import ProfileFlagsEditor from "$components/editor/ProfileFlagsEditor.svelte"; import log from "$lib/log"; import type { PageData } from "./$types"; @@ -9,20 +10,41 @@ type Props = { data: PageData }; let { data }: Props = $props(); - let form: { ok: boolean; error: RawApiError | null } | null = $state(null); + let flagForm: { ok: boolean; error: RawApiError | null } | null = $state(null); + let linksForm: { ok: boolean; error: RawApiError | null } | null = $state(null); - const save = async (flags: string[]) => { + const flagSave = async (flags: string[]) => { try { await fastRequest("PATCH", "/users/@me", { body: { flags }, token: data.token, }); - form = { ok: true, error: null }; + flagForm = { ok: true, error: null }; } catch (e) { log.error("Could not update profile flags:", e); - if (e instanceof ApiError) form = { ok: false, error: e.obj }; + if (e instanceof ApiError) flagForm = { ok: false, error: e.obj }; + } + }; + + const linksSave = async (links: string[]) => { + try { + await fastRequest("PATCH", "/users/@me", { + body: { links }, + token: data.token, + }); + linksForm = { ok: true, error: null }; + } catch (e) { + log.error("Could not update profile links:", e); + if (e instanceof ApiError) linksForm = { ok: false, error: e.obj }; } }; - + + +