feat(frontend): fields editor
This commit is contained in:
parent
7c52ab759c
commit
f435ad4cf5
7 changed files with 319 additions and 166 deletions
|
@ -0,0 +1,32 @@
|
|||
<script lang="ts">
|
||||
import { apiRequest } from "$api";
|
||||
import ApiError, { type RawApiError } from "$api/error";
|
||||
import { mergePreferences, type User } from "$api/models/user";
|
||||
import FieldsEditor from "$components/editor/FieldsEditor.svelte";
|
||||
import log from "$lib/log";
|
||||
import type { PageData } from "./$types";
|
||||
|
||||
type Props = { data: PageData };
|
||||
let { data }: Props = $props();
|
||||
|
||||
let fields = $state(data.user.fields);
|
||||
let ok: { ok: boolean; error: RawApiError | null } | null = $state(null);
|
||||
let allPreferences = $derived(mergePreferences(data.user.custom_preferences));
|
||||
|
||||
const update = async () => {
|
||||
try {
|
||||
const resp = await apiRequest<User>("PATCH", "/users/@me", {
|
||||
body: { fields },
|
||||
token: data.token,
|
||||
});
|
||||
fields = resp.fields;
|
||||
ok = { ok: true, error: null };
|
||||
} catch (e) {
|
||||
ok = { ok: false, error: null };
|
||||
log.error("Could not update fields:", e);
|
||||
if (e instanceof ApiError) ok.error = e.obj;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<FieldsEditor {fields} {ok} {allPreferences} {update} />
|
Loading…
Add table
Add a link
Reference in a new issue