From c866cbb939ded430ac3f9e60ab66a171a29c759a Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 29 May 2023 17:00:09 +0200 Subject: [PATCH] feat: add snapshot to /edit/profile and /edit/member/:id --- .../src/routes/edit/member/[id]/+page.svelte | 52 +++++++++++++++++- frontend/src/routes/edit/profile/+page.svelte | 55 ++++++++++++++++++- 2 files changed, 105 insertions(+), 2 deletions(-) diff --git a/frontend/src/routes/edit/member/[id]/+page.svelte b/frontend/src/routes/edit/member/[id]/+page.svelte index 7ba9080..533c1be 100644 --- a/frontend/src/routes/edit/member/[id]/+page.svelte +++ b/frontend/src/routes/edit/member/[id]/+page.svelte @@ -36,7 +36,7 @@ import EditableName from "../../EditableName.svelte"; import EditablePronouns from "../../EditablePronouns.svelte"; import ErrorAlert from "$lib/components/ErrorAlert.svelte"; - import type { PageData } from "./$types"; + import type { PageData, Snapshot } from "./$types"; import { addToast, delToast } from "$lib/toast"; import { memberNameRegex } from "$lib/api/regex"; import { charCount, renderMarkdown } from "$lib/utils"; @@ -372,6 +372,56 @@ const toggleDeleteOpen = () => (deleteOpen = !deleteOpen); let deleteName = ""; let deleteError: APIError | null = null; + + interface SnapshotData { + bio: string; + name: string; + display_name: string; + links: string[]; + names: FieldEntry[]; + pronouns: Pronoun[]; + fields: Field[]; + flags: PrideFlag[]; + unlisted: boolean; + + avatar: string | null; + newName: string; + newPronouns: string; + newLink: string; + } + + export const snapshot: Snapshot = { + capture: () => ({ + bio, + name, + display_name, + links, + names, + pronouns, + fields, + flags, + unlisted, + avatar, + newName, + newPronouns, + newLink, + }), + restore: (value) => { + bio = value.bio + name = value.name + display_name = value.display_name + links = value.links + names = value.names + pronouns = value.pronouns + fields = value.fields + flags = value.flags + unlisted = value.unlisted + avatar = value.avatar + newName = value.newName + newPronouns = value.newPronouns + newLink = value.newLink + }, + }; diff --git a/frontend/src/routes/edit/profile/+page.svelte b/frontend/src/routes/edit/profile/+page.svelte index f2ee796..d0a480e 100644 --- a/frontend/src/routes/edit/profile/+page.svelte +++ b/frontend/src/routes/edit/profile/+page.svelte @@ -35,7 +35,7 @@ import EditablePronouns from "../EditablePronouns.svelte"; import ErrorAlert from "$lib/components/ErrorAlert.svelte"; import { addToast, delToast } from "$lib/toast"; - import type { PageData } from "./$types"; + import type { PageData, Snapshot } from "./$types"; import { charCount, renderMarkdown } from "$lib/utils"; import MarkdownHelp from "../MarkdownHelp.svelte"; import prettyBytes from "pretty-bytes"; @@ -378,6 +378,59 @@ delToast(toastId); } }; + + interface SnapshotData { + bio: string; + display_name: string; + member_title: string; + links: string[]; + names: FieldEntry[]; + pronouns: Pronoun[]; + fields: Field[]; + flags: PrideFlag[]; + list_private: boolean; + custom_preferences: CustomPreferences; + + avatar: string | null; + newName: string; + newPronouns: string; + newLink: string; + } + + export const snapshot: Snapshot = { + capture: () => ({ + bio, + display_name, + member_title, + links, + names, + pronouns, + fields, + flags, + list_private, + custom_preferences, + avatar, + newName, + newPronouns, + newLink, + }), + restore: (value) => { + bio = value.bio; + display_name = value.display_name; + member_title = value.member_title; + links = value.links; + names = value.names; + pronouns = value.pronouns; + fields = value.fields; + flags = value.flags; + list_private = value.list_private; + custom_preferences = value.custom_preferences; + avatar = value.avatar; + newName = value.newName; + newPronouns = value.newPronouns; + newLink = value.newLink; + }, + };