feat(frontend): store pending profile changes in sessionStorage

This commit is contained in:
sam 2025-02-24 17:37:49 +01:00
parent 92bf933c10
commit d1faf1ddee
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
11 changed files with 117 additions and 4 deletions

View file

@ -2,14 +2,16 @@
import type { RawApiError } from "$api/error";
import IconButton from "$components/IconButton.svelte";
import { t } from "$lib/i18n";
import ephemeralState from "$lib/state.svelte";
import FormStatusMarker from "./FormStatusMarker.svelte";
type Props = {
stateKey: string;
currentLinks: string[];
save(links: string[]): Promise<void>;
form: { ok: boolean; error: RawApiError | null } | null;
};
let { currentLinks, save, form }: Props = $props();
let { stateKey, currentLinks, save, form }: Props = $props();
let links = $state(currentLinks);
let newEntry = $state("");
@ -37,6 +39,12 @@
links = [...links, newEntry];
newEntry = "";
};
ephemeralState(
stateKey,
() => links,
(data) => (links = data),
);
</script>
<h4>

View file

@ -4,16 +4,18 @@
import FlagSearch from "$components/editor/FlagSearch.svelte";
import IconButton from "$components/IconButton.svelte";
import { t } from "$lib/i18n";
import ephemeralState from "$lib/state.svelte";
import FlagButton from "./FlagButton.svelte";
import FormStatusMarker from "./FormStatusMarker.svelte";
type Props = {
stateKey: string;
profileFlags: PrideFlag[];
allFlags: PrideFlag[];
save(flags: string[]): Promise<void>;
form: { ok: boolean; error: RawApiError | null } | null;
};
let { profileFlags, allFlags, save, form }: Props = $props();
let { stateKey, profileFlags, allFlags, save, form }: Props = $props();
let flags = $state(profileFlags);
@ -40,6 +42,12 @@
};
const saveChanges = () => save(flags.map((f) => f.id));
ephemeralState(
stateKey,
() => flags,
(data) => (flags = data),
);
</script>
<div class="row">