feat(frontend): store pending profile changes in sessionStorage
This commit is contained in:
parent
92bf933c10
commit
d1faf1ddee
11 changed files with 117 additions and 4 deletions
|
@ -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>
|
||||
|
|
|
@ -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">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue