feat(frontend): member fields and flags editors, fix user fields editor
This commit is contained in:
parent
2a0df335bc
commit
b0a286dd9f
4 changed files with 68 additions and 1 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.member.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/members/${data.member.id}`, {
|
||||
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 bind:fields {ok} {allPreferences} {update} />
|
|
@ -0,0 +1,7 @@
|
|||
import { apiRequest } from "$api";
|
||||
import type { PrideFlag } from "$api/models/user";
|
||||
|
||||
export const load = async ({ fetch, cookies }) => {
|
||||
const flags = await apiRequest<PrideFlag[]>("GET", "/users/@me/flags", { fetch, cookies });
|
||||
return { flags };
|
||||
};
|
|
@ -0,0 +1,28 @@
|
|||
<script lang="ts">
|
||||
import { fastRequest } from "$api";
|
||||
import type { RawApiError } from "$api/error";
|
||||
import ApiError from "$api/error";
|
||||
import ProfileFlagsEditor from "$components/editor/ProfileFlagsEditor.svelte";
|
||||
import log from "$lib/log";
|
||||
import type { PageData } from "./$types";
|
||||
|
||||
type Props = { data: PageData };
|
||||
let { data }: Props = $props();
|
||||
|
||||
let form: { ok: boolean; error: RawApiError | null } | null = $state(null);
|
||||
|
||||
const save = async (flags: string[]) => {
|
||||
try {
|
||||
await fastRequest("PATCH", `/users/@me/members/${data.member.id}`, {
|
||||
body: { flags },
|
||||
token: data.token,
|
||||
});
|
||||
form = { ok: true, error: null };
|
||||
} catch (e) {
|
||||
log.error("Could not update profile flags for member %s:", data.member.id, e);
|
||||
if (e instanceof ApiError) form = { ok: false, error: e.obj };
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<ProfileFlagsEditor profileFlags={data.member.flags} allFlags={data.flags} {save} {form} />
|
|
@ -29,4 +29,4 @@
|
|||
};
|
||||
</script>
|
||||
|
||||
<FieldsEditor {fields} {ok} {allPreferences} {update} />
|
||||
<FieldsEditor bind:fields {ok} {allPreferences} {update} />
|
||||
|
|
Loading…
Reference in a new issue