commit 9db445abec1cf5367c9704d60ab6a91c88d2db32
parent a39e8157b0e3d9e5627d44f5e6671819ce955abf
Author: triesap <triesap@radroots.dev>
Date: Fri, 21 Nov 2025 02:59:41 +0000
apps-lib-pwa: migrate and refactor profile edit view from `@radroots/apps-lib`
Diffstat:
3 files changed, 117 insertions(+), 0 deletions(-)
diff --git a/apps-lib-pwa/src/lib/index.ts b/apps-lib-pwa/src/lib/index.ts
@@ -39,5 +39,6 @@ export { default as PageHeader } from "./components/navigation/page-header.svelt
export { default as PageToolbar } from "./components/navigation/page-toolbar.svelte";
export { default as FarmsAdd } from "./views/farms/farms-add.svelte";
export { default as Farms } from "./views/farms/farms.svelte";
+export { default as ProfileEdit } from "./views/profile/profile-edit.svelte";
export { default as Profile } from "./views/profile/profile.svelte";
export { default as Home } from "./views/root/home.svelte";
diff --git a/apps-lib-pwa/src/lib/utils/profile/lib.ts b/apps-lib-pwa/src/lib/utils/profile/lib.ts
@@ -0,0 +1,12 @@
+import type { ViewProfileEditFieldKey } from "$lib/types/views/profile";
+
+export const parse_view_profile_field_key = (val?: string | null): ViewProfileEditFieldKey | undefined => {
+ switch (val) {
+ case `name`:
+ case `display_name`:
+ case `about`:
+ return val;
+ default:
+ return undefined;
+ }
+};
+\ No newline at end of file
diff --git a/apps-lib-pwa/src/lib/views/profile/profile-edit.svelte b/apps-lib-pwa/src/lib/views/profile/profile-edit.svelte
@@ -0,0 +1,103 @@
+<script lang="ts">
+ import { FloatPage, LayoutPage, LayoutView, NavigationTabs } from "$lib";
+ import ButtonRoundNav from "$lib/components/button/button-round-nav.svelte";
+ import type { IViewBasis } from "$lib/types/views";
+ import type {
+ IViewProfileEditData,
+ ViewProfileEditFieldKey,
+ } from "$lib/types/views/profile";
+ import {
+ type ElementCallbackValue,
+ Flex,
+ InputExt,
+ fmt_id,
+ get_context,
+ idb_kv_init_page,
+ } from "@radroots/apps-lib";
+ import { type CallbackPromiseGeneric, handle_err } from "@radroots/utils";
+ import { onMount } from "svelte";
+
+ const { ls } = get_context(`lib`);
+
+ let {
+ basis,
+ val_field = $bindable(``),
+ }: {
+ basis: IViewBasis<{
+ data?: IViewProfileEditData;
+ on_handle_back: CallbackPromiseGeneric<{
+ field: ViewProfileEditFieldKey;
+ public_key: string;
+ }>;
+ on_handle_input: ElementCallbackValue;
+ }>;
+ val_field: string;
+ } = $props();
+
+ const param: Record<ViewProfileEditFieldKey, { placeholder: string }> = {
+ name: {
+ placeholder: `${$ls(`icu.enter_*`, { value: `profile username` })}`, //@todo
+ },
+ display_name: {
+ placeholder: `${$ls(`icu.enter_*`, {
+ value: `profile display name`,
+ })}`, //@todo
+ },
+ about: {
+ placeholder: `${$ls(`icu.enter_*`, { value: `profile bio` })}`, //@todo
+ },
+ };
+
+ onMount(async () => {
+ try {
+ if (!basis.kv_init_prevent) await idb_kv_init_page();
+ } catch (e) {
+ handle_err(e, `on_mount`);
+ }
+ });
+
+ const input_placeholder = $derived(
+ basis.data?.field ? param[basis.data.field]?.placeholder : ``,
+ );
+</script>
+
+{#if basis.data}
+ {@const { data: basis_data } = basis}
+ <LayoutView>
+ <LayoutPage>
+ <div class={`flex flex-row h-20 w-full justify-start items-center`}>
+ <Flex />
+ </div>
+ {#if basis.data.field}
+ <InputExt
+ bind:value={val_field}
+ basis={{
+ id: fmt_id(`field`),
+ sync: true,
+ classes: `pl-6 h-entry_line text-ly1-gl bg-ly1 rounded-2xl`,
+ placeholder: input_placeholder,
+ callback: basis.on_handle_input,
+ }}
+ />
+ {/if}
+ </LayoutPage>
+ </LayoutView>
+ <FloatPage
+ basis={{
+ posx: `left`,
+ }}
+ >
+ <ButtonRoundNav
+ basis={{
+ glyph: `arrow-left`,
+ callback: async () => {
+ await basis.on_handle_back({
+ field: basis_data.field,
+ public_key: basis_data.public_key,
+ });
+ },
+ }}
+ />
+ </FloatPage>
+ <NavigationTabs />
+{/if}