From c20831f20d67a0634f7b49143b8d28c6db47f7a8 Mon Sep 17 00:00:00 2001 From: sam Date: Tue, 3 Dec 2024 20:02:09 +0100 Subject: [PATCH] feat(frontend): export ui --- .../src/lib/i18n/locales/en.json | 8 ++- .../src/routes/settings/+page.svelte | 3 +- .../routes/settings/export/+page.server.ts | 35 +++++++++++++ .../src/routes/settings/export/+page.svelte | 49 +++++++++++++++++++ .../routes/settings/members/[id]/+page.svelte | 9 ++-- .../routes/settings/members/new/+page.svelte | 3 +- .../src/routes/settings/profile/+page.svelte | 3 +- .../routes/settings/profile/bio/+page.svelte | 3 +- 8 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 Foxnouns.Frontend/src/routes/settings/export/+page.server.ts create mode 100644 Foxnouns.Frontend/src/routes/settings/export/+page.svelte diff --git a/Foxnouns.Frontend/src/lib/i18n/locales/en.json b/Foxnouns.Frontend/src/lib/i18n/locales/en.json index 73063c5..6a9f9f6 100644 --- a/Foxnouns.Frontend/src/lib/i18n/locales/en.json +++ b/Foxnouns.Frontend/src/lib/i18n/locales/en.json @@ -112,7 +112,13 @@ "create-member-name-label": "Member name", "auth-remove-method": "Remove", "force-log-out-warning": "Make sure you're still able to log in before using this!", - "force-log-out-confirmation": "Are you sure you want to log out from all devices? If you just want to log out from this device, click the \"Log out\" button on your settings page." + "force-log-out-confirmation": "Are you sure you want to log out from all devices? If you just want to log out from this device, click the \"Log out\" button on your settings page.", + "export-request-success": "Successfully requested a new export! Please note that it may take a few minutes to complete, especially if you have a lot of members.", + "export-title": "Request a copy of your data", + "export-info": "You can request a copy of your data once every 24 hours. Exports are stored for 15 days (a little over two weeks) and then deleted.", + "export-expires-at": "(expires {{expiresAt}})", + "export-download": "Download export", + "export-request-button": "Request a new export" }, "yes": "Yes", "no": "No", diff --git a/Foxnouns.Frontend/src/routes/settings/+page.svelte b/Foxnouns.Frontend/src/routes/settings/+page.svelte index 79f7d64..f43c8a5 100644 --- a/Foxnouns.Frontend/src/routes/settings/+page.svelte +++ b/Foxnouns.Frontend/src/routes/settings/+page.svelte @@ -7,6 +7,7 @@ import Error from "$components/Error.svelte"; import { idTimestamp } from "$lib"; import { DateTime } from "luxon"; + import { enhance } from "$app/forms"; type Props = { data: PageData; form: ActionData }; let { data, form }: Props = $props(); @@ -20,7 +21,7 @@
Change your username
-
+ { + const resp = await apiRequest("GET", "/data-exports", { + fetch, + cookies, + isInternal: true, + }); + + let canExport = true; + if (resp.expires_at) { + const created = DateTime.fromISO(resp.expires_at).minus(Duration.fromObject({ days: 15 })); + canExport = DateTime.now().diff(created, "seconds").seconds >= 86400; + } + + return { url: resp.url, expiresAt: resp.expires_at, canExport }; +}; + +export const actions = { + default: async ({ fetch, cookies }) => { + try { + fastRequest("POST", "/data-exports", { fetch, cookies, isInternal: true }); + return { ok: true, error: null }; + } catch (e) { + if (e instanceof ApiError) return { ok: false, error: e.obj }; + log.error("Error requesting data export:", e); + throw e; + } + }, +}; diff --git a/Foxnouns.Frontend/src/routes/settings/export/+page.svelte b/Foxnouns.Frontend/src/routes/settings/export/+page.svelte new file mode 100644 index 0000000..874f8e8 --- /dev/null +++ b/Foxnouns.Frontend/src/routes/settings/export/+page.svelte @@ -0,0 +1,49 @@ + + +
+

{$t("settings.export-title")}

+ + {#if form?.ok} +

+ + {$t("settings.export-request-success")} +

+ {:else if form?.error} + + {/if} + +

+ {$t("settings.export-info")} +

+ + + + +
diff --git a/Foxnouns.Frontend/src/routes/settings/members/[id]/+page.svelte b/Foxnouns.Frontend/src/routes/settings/members/[id]/+page.svelte index 22fd219..b4b38e2 100644 --- a/Foxnouns.Frontend/src/routes/settings/members/[id]/+page.svelte +++ b/Foxnouns.Frontend/src/routes/settings/members/[id]/+page.svelte @@ -14,6 +14,7 @@ import SidEditor from "$components/editor/SidEditor.svelte"; import BioEditor from "$components/editor/BioEditor.svelte"; import { PUBLIC_BASE_URL } from "$env/static/public"; + import { enhance } from "$app/forms"; type Props = { data: PageData; form: ActionData }; let { data, form }: Props = $props(); @@ -83,7 +84,7 @@

{$t("edit-profile.member-name")}

-
+

{$t("edit-profile.display-name")}

- +

{$t("edit-profile.profile-options-header")}

- +

{$t("edit-profile.bio-tab")}

- +
diff --git a/Foxnouns.Frontend/src/routes/settings/members/new/+page.svelte b/Foxnouns.Frontend/src/routes/settings/members/new/+page.svelte index 7999be2..2c1fc0b 100644 --- a/Foxnouns.Frontend/src/routes/settings/members/new/+page.svelte +++ b/Foxnouns.Frontend/src/routes/settings/members/new/+page.svelte @@ -1,4 +1,5 @@