app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

commit 1e00836fccfcedffeb061b63eb17a384f4890d48
parent 14404c774157cc69056dae1727d6f4fc0ae88471
Author: triesap <137732411+triesap@users.noreply.github.com>
Date:   Fri, 30 Aug 2024 21:39:08 +0000

Update nav with basis params, edit `/nostr/notes`, edit `/nostr/profile`, add utils

Diffstat:
Msrc/app.css | 15+++++++++++++++
Msrc/lib/client.ts | 2--
Msrc/lib/components/layout-view.svelte | 6++++--
Msrc/lib/components/nav.svelte | 98++++++++++++++++++++++++++++++++++++++-----------------------------------------
Msrc/lib/stores.ts | 5++---
Msrc/lib/types.ts | 17++++++++++++++++-
Asrc/lib/utils.ts | 11+++++++++++
Msrc/routes/(app)/+layout.svelte | 23+----------------------
Msrc/routes/(app)/+page.svelte | 19+++----------------
Msrc/routes/(app)/nostr/+page.svelte | 34+++++++++-------------------------
Msrc/routes/(app)/nostr/notes/+page.svelte | 194++++++++++++++++++++++++++++++++++++-------------------------------------------
Msrc/routes/(app)/nostr/profile/+page.svelte | 149++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
Dsrc/routes/(app)/nostr/profile/edit/+page.svelte | 68--------------------------------------------------------------------
Msrc/routes/(app)/settings/+page.svelte | 13+++++++++++--
Msrc/routes/(conf)/conf/nostr/+page.svelte | 10+++++-----
Msrc/routes/+layout.svelte | 2++
16 files changed, 313 insertions(+), 353 deletions(-)

diff --git a/src/app.css b/src/app.css @@ -21,6 +21,21 @@ -ms-overflow-style: none; scrollbar-width: none; } + + @keyframes fade-in { + from { + opacity: 0; + } + + to { + opacity: 1; + } + } + + .fade-in { + opacity: 0; + animation: fade-in 250ms ease-in-out forwards; + } } @layer base { diff --git a/src/lib/client.ts b/src/lib/client.ts @@ -1,5 +1,3 @@ import { ClientCapacitor } from "@radroots/client"; -import { NostrTools } from "../../../../packages/utils"; export const cl = new ClientCapacitor(); -export const nt = new NostrTools(); diff --git a/src/lib/components/layout-view.svelte b/src/lib/components/layout-view.svelte @@ -7,13 +7,15 @@ lg:'pt-16' }; - let { children }: PropChildren = $props(); + let { children, basis }: PropChildren & { basis?: { fade?: boolean; }} = $props(); let el: HTMLElement | null; let classes_nav = $derived($app_nav_visible ? `pt-h_nav_${$app_layout}` : `${styles[$app_layout]}`) let classes_tabs = $derived($app_tabs_visible ? `pb-h_tabs_${$app_layout}` : ``) + let classes_fade = $derived(basis?.fade ? `fade-in` : ``) + const scrollChange = (): void => { if (Math.max(el?.scrollTop || 0, 0) > 10) app_nav_blur.set(true); else app_nav_blur.set(false); @@ -31,7 +33,7 @@ <div bind:this={el} - class={`absolute top-0 left-0 flex flex-col h-[100vh] w-full overflow-y-scroll scroll-hide ${classes_nav} ${classes_tabs}`} + class={`absolute top-0 left-0 flex flex-col h-[100vh] w-full overflow-y-scroll scroll-hide ${classes_nav} ${classes_tabs} ${classes_fade}`} > {@render children()} </div> diff --git a/src/lib/components/nav.svelte b/src/lib/components/nav.svelte @@ -1,53 +1,25 @@ <script lang="ts"> import { goto } from "$app/navigation"; - import { - app_layout, - app_nav_blur, - app_nav_prev, - app_nav_title, - } from "$lib/stores"; - import { - encode_qp, - fill as Fill, - glyph as Glyph, - } from "@radroots/svelte-lib"; + import { app_layout, app_nav_blur, app_nav_visible } from "$lib/stores"; + import type { INavBasis } from "$lib/types"; + import { restart } from "$lib/utils"; + import { fill as Fill, glyph as Glyph } from "@radroots/svelte-lib"; + + let { + basis, + }: { + basis: INavBasis; + } = $props(); let el: HTMLElement | null; let el_inner: HTMLElement | null; - let previous_route = $state(``); - let previous_param = $state(``); - let previous_label = $state(``); - - let title_label = $state(``); - - app_nav_prev.subscribe((app_nav_prev) => { - console.log(JSON.stringify(app_nav_prev, null, 4), `app_nav_prev`); - if (app_nav_prev.length) { - const previous = app_nav_prev[app_nav_prev.length - 1]; - if (previous) { - previous_route = previous.route; - if (previous.label) previous_label = previous.label; - if (previous.params) - previous_param = encode_qp(previous.params); - } - } + $effect(() => { + app_nav_visible.set(true); + return () => { + app_nav_visible.set(false); + }; }); - - app_nav_title.subscribe((app_nav_title) => { - if (!app_nav_title) return; - title_label = app_nav_title.label; - }); - - const handle_previous = async (): Promise<void> => { - try { - const url = `${previous_route || `/`}${previous_param || ``}`; - app_nav_prev.set($app_nav_prev.slice(0, -1)); - await goto(url); - } catch (e) { - console.log(`(error) handle_previous `, e); - } - }; </script> <div @@ -64,7 +36,7 @@ <button class={`col-span-4 flex flex-row h-full pl-2 justify-start items-center`} onclick={async () => { - await handle_previous(); + await goto(basis.prev.route); }} > <Glyph @@ -75,11 +47,11 @@ classes: `text-layer-1-glyph-hl group-active:opacity-70 transition-opacity`, }} /> - {#if previous_label} + {#if basis.prev.label} <p class={`font-sans text-navPrevious text-layer-1-glyph-hl group-active:opacity-60 transition-opacity`} > - {previous_label} + {basis.prev.label} </p> {:else} <Fill /> @@ -88,10 +60,19 @@ <div class={`col-span-4 flex flex-row h-full justify-center items-center`} > - {#if title_label} - <p class={`font-sans text-navCurrent text-layer-1-glyph`}> - {title_label} - </p> + {#if basis.title} + <button + class={`flex flex-row justify-center items-center`} + onclick={async () => { + await restart(); + }} + > + <p + class={`font-sans text-navCurrent text-layer-1-glyph`} + > + {basis.title.label} + </p> + </button> {:else} <Fill /> {/if} @@ -99,7 +80,22 @@ <div class={`col-span-4 flex flex-row h-full justify-end items-center`} > - <Fill /> + {#if basis.option} + <button + class={`col-span-4 flex flex-row h-full pr-6 justify-end items-center`} + onclick={async () => { + await basis.option?.callback(); + }} + > + <p + class={`font-sans text-navPrevious text-layer-1-glyph-hl group-active:opacity-60 transition-opacity`} + > + {basis.option.label} + </p> + </button> + {:else} + <Fill /> + {/if} </div> </div> </div> diff --git a/src/lib/stores.ts b/src/lib/stores.ts @@ -1,7 +1,6 @@ import type { AppLayoutKey } from "@radroots/svelte-lib"; import { type ColorMode, type ThemeKey } from "@radroots/theme"; import { writable } from "svelte/store"; -import type { NavParamPrev, NavParamTitle } from "./types"; export const app_thc = writable<ColorMode>(`light`); export const app_thm = writable<ThemeKey>(`os`); @@ -22,5 +21,5 @@ export const app_pwa_polyfills = writable<boolean>(false); export const app_sqlite = writable<boolean>(false); export const app_nav_visible = writable<boolean>(false); -export const app_nav_prev = writable<NavParamPrev>([]); -export const app_nav_title = writable<NavParamTitle | false>(false); +//export const app_nav_prev = writable<NavParamPrev>([]); +//export const app_nav_title = writable<NavParamTitle | false>(false); diff --git a/src/lib/types.ts b/src/lib/types.ts @@ -1,6 +1,20 @@ -import type { NavigationPreviousParam } from "@radroots/svelte-lib"; +import type { CallbackPromise, NavigationPreviousParam } from "@radroots/svelte-lib"; export type NavParamPrev = NavigationPreviousParam[]; export type NavParamTitle = { label: string; }; + +export type INavBasis = { + prev: { + label?: string; + route: string; + }; + title?: { + label: string; + }; + option?: { + label: string; + callback: CallbackPromise; + }; +}; +\ No newline at end of file diff --git a/src/lib/utils.ts b/src/lib/utils.ts @@ -0,0 +1,10 @@ +import { cl } from "./client"; + +export const restart = async (): Promise<void> => { + try { + await cl.window.splash_show(); + location.reload(); + } catch (e) { + console.log(`(error) restart `, e); + } +}; +\ No newline at end of file diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte @@ -1,17 +1,13 @@ <script lang="ts"> import { goto } from "$app/navigation"; - import Nav from "$lib/components/nav.svelte"; import Tabs from "$lib/components/tabs.svelte"; - import { app_layout, app_nav_prev, app_nav_title, app_nav_visible, app_tab_active, app_tabs_visible } from "$lib/stores"; + import { app_layout, app_tab_active, app_tabs_visible } from "$lib/stores"; import { type PropChildren } from "@radroots/svelte-lib"; let { children }: PropChildren = $props(); </script> {@render children()} -{#if $app_nav_visible } - <Nav /> -{/if} {#if $app_tabs_visible} <Tabs basis={{ @@ -35,16 +31,6 @@ icon: `network`, callback: async (tab_i) => { app_tab_active.set(tab_i); - app_nav_prev.set([ - ...$app_nav_prev, - { - label: `Home`, - route: `/` - } - ]); - app_nav_title.set({ - label: `Nostr`, - }); await goto("/nostr"); }, }, @@ -52,13 +38,6 @@ icon: `bell-simple`, callback: async (tab_i) => { app_tab_active.set(tab_i); - $app_nav_prev.push( { - label: `Home`, - route: `/` - }); - app_nav_title.set({ - label: `Settings`, - }); await goto("/settings"); }, }, diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte @@ -1,25 +1,19 @@ <script lang="ts"> import { goto } from "$app/navigation"; import { cl } from "$lib/client"; - import { - app_nav_prev, - app_nav_title, - app_nav_visible, - app_tab_active, - app_tabs_visible, - } from "$lib/stores"; + import { app_tab_active, app_tabs_visible } from "$lib/stores"; import { NDKKind } from "@nostr-dev-kit/ndk"; import { ndk, ndk_event, ndk_user, t } from "@radroots/svelte-lib"; $effect(() => { - app_nav_visible.set(false); + //app_nav_visible.set(false); app_tabs_visible.set(true); app_tab_active.set(0); }); const nostr_note_pub = async (): Promise<void> => { try { - const content = `hello from radroots`; + const content = `posting from radroots`; const ev = await ndk_event({ $ndk, $ndk_user, @@ -49,13 +43,6 @@ <button class={`button-simple`} onclick={async () => { - $app_nav_prev.push({ - label: `Home`, - route: `/`, - }); - app_nav_title.set({ - label: `Models`, - }); await goto(`/models/location-gcs`); }} > diff --git a/src/routes/(app)/nostr/+page.svelte b/src/routes/(app)/nostr/+page.svelte @@ -2,12 +2,8 @@ import { goto } from "$app/navigation"; import LayoutTrellis from "$lib/components/layout-trellis.svelte"; import LayoutView from "$lib/components/layout-view.svelte"; - import { app_nav_prev, app_nav_title, app_nav_visible } from "$lib/stores"; + import Nav from "$lib/components/nav.svelte"; import { trellis as Trellis } from "@radroots/svelte-lib"; - - $effect(() => { - app_nav_visible.set(true); - }); </script> <LayoutView> @@ -31,16 +27,6 @@ ], }, callback: async () => { - app_nav_prev.set([ - ...$app_nav_prev, - { - label: `Nostr`, - route: `/nostr`, - }, - ]); - app_nav_title.set({ - label: `Profile`, - }); await goto(`/nostr/profile`); }, }, @@ -56,16 +42,6 @@ ], }, callback: async () => { - app_nav_prev.set([ - ...$app_nav_prev, - { - label: `Nostr`, - route: `/nostr`, - }, - ]); - app_nav_title.set({ - label: `Notes`, - }); await goto(`/nostr/notes`); }, }, @@ -76,3 +52,11 @@ /> </LayoutTrellis> </LayoutView> +<Nav + basis={{ + prev: { + label: `Home`, + route: `/`, + }, + }} +/> diff --git a/src/routes/(app)/nostr/notes/+page.svelte b/src/routes/(app)/nostr/notes/+page.svelte @@ -2,120 +2,102 @@ import { cl } from "$lib/client"; import LayoutTrellis from "$lib/components/layout-trellis.svelte"; import LayoutView from "$lib/components/layout-view.svelte"; - import { app_nav_visible, app_nostr_key } from "$lib/stores"; - import { - NDKEvent, - NDKKind, - type NDKFilter, - type NDKSubscriptionOptions, - } from "@nostr-dev-kit/ndk"; - import { - locale, - ndk, - time_fmt_nostr_event, - trellis as Trellis, - } from "@radroots/svelte-lib"; + import Nav from "$lib/components/nav.svelte"; + import { app_nostr_key } from "$lib/stores"; + import { NDKEvent, NDKKind } from "@nostr-dev-kit/ndk"; + import { ndk, trellis as Trellis } from "@radroots/svelte-lib"; + import { writable } from "svelte/store"; - $effect(() => { - app_nav_visible.set(true); - }); - - const ndk_filter: NDKFilter = { - kinds: [NDKKind.Text], - authors: [$app_nostr_key], - }; - - const ndk_opts: NDKSubscriptionOptions = { - closeOnEose: false, - }; - - let ndk_events = $state<NDKEvent[]>([]); + let ndk_sub = $derived( + $ndk.subscribe( + { + kinds: [NDKKind.Text], + authors: [$app_nostr_key], + }, + { + closeOnEose: false, + }, + ), + ); + const events_list = writable<NDKEvent[]>([]); - const ndk_sub = $ndk.subscribe(ndk_filter, ndk_opts); + events_list.subscribe((events_list) => { + console.log( + `events_list `, + JSON.stringify(events_list.map((i) => i.content)), + ); + }); ndk_sub.on("event", (event) => { - ndk_events.push(event); - ndk_events.sort( - (a, b) => - parseInt(cl.nostr.ev.first_tag_value(b, "published_at")) - - parseInt(cl.nostr.ev.first_tag_value(a, "published_at")), - ); - ndk_events = ndk_events; + events_list.set([...$events_list, event]); }); </script> -<LayoutView> +<LayoutView basis={{ fade: true }}> <LayoutTrellis> - {#if ndk_events.length} - {#each ndk_events as ev, ev_i (ev.id)} - <Trellis - basis={{ - args: { - layer: 1, - title: - ev_i === 0 - ? { - value: `Notes`, - } - : undefined, - list: [ - { - hide_active: true, - touch: { - label: { - left: [ - { - value: ev.content, - }, - ], - }, - callback: async () => {}, - }, - }, - { - hide_active: true, - touch: { - label: { - left: [ - { - value: `Published: ${time_fmt_nostr_event($locale, ev.created_at)}`, - }, - ], - }, - callback: async () => {}, - }, - }, - ], - }, - }} - /> - {/each} - {:else} - <Trellis - basis={{ - args: { - layer: 1, - title: { - value: `Notes`, - }, - list: [ - { - hide_active: true, - touch: { - label: { - left: [ - { - value: `No text notes`, - }, - ], - }, - callback: async () => {}, - }, - }, - ], + <Trellis + basis={{ + args: { + layer: 1, + title: { + value: `Nostr Profile`, }, - }} - /> - {/if} + list: $events_list.length + ? $events_list.map((ev) => ({ + hide_active: true, + touch: { + label: { + left: [ + { + value: ev.content, + }, + ], + }, + callback: async () => {}, + }, + })) + : [ + { + touch: { + label: { + left: [ + { + value: `Add Note`, + }, + ], + }, + end: { + icon: { + key: `caret-right`, + }, + }, + callback: async () => { + await cl.dialog.alert(`Todo!`); + }, + }, + }, + ], + }, + }} + /> </LayoutTrellis> </LayoutView> +<Nav + basis={{ + prev: { + label: `Nostr`, + route: `/nostr`, + }, + title: { + label: `Notes`, + }, + option: $events_list.length + ? { + label: `Edit`, + callback: async () => { + await cl.dialog.alert(`Todo!`); + }, + } + : undefined, + }} +/> diff --git a/src/routes/(app)/nostr/profile/+page.svelte b/src/routes/(app)/nostr/profile/+page.svelte @@ -1,51 +1,91 @@ <script lang="ts"> - import { goto } from "$app/navigation"; import { cl } from "$lib/client"; import LayoutTrellis from "$lib/components/layout-trellis.svelte"; import LayoutView from "$lib/components/layout-view.svelte"; - import { - app_nav_prev, - app_nav_title, - app_nav_visible, - app_nostr_key, - } from "$lib/stores"; + import Nav from "$lib/components/nav.svelte"; + import { restart } from "$lib/utils"; import { NDKEvent, NDKKind, type NDKFilter, type NDKSubscriptionOptions, } from "@nostr-dev-kit/ndk"; - import { ndk, trellis as Trellis } from "@radroots/svelte-lib"; - - $effect(() => { - app_nav_visible.set(true); - }); + import { + ndk, + ndk_event, + ndk_user, + t, + trellis as Trellis, + } from "@radroots/svelte-lib"; + import { writable } from "svelte/store"; const ndk_filter: NDKFilter = { kinds: [NDKKind.Metadata], - authors: [$app_nostr_key], + // authors: [$app_nostr_key], }; - const ndk_opts: NDKSubscriptionOptions = { closeOnEose: false, }; + const ndk_sub = $ndk.subscribe(ndk_filter, ndk_opts); - let ndk_events = $state<NDKEvent[]>([]); + const events_list = writable<NDKEvent[]>([]); - const ndk_sub = $ndk.subscribe(ndk_filter, ndk_opts); + events_list.subscribe((events_list) => { + console.log( + `events_list `, + JSON.stringify(events_list.map((i) => i.content)), + ); + }); ndk_sub.on("event", (event) => { - ndk_events.push(event); - ndk_events.sort( - (a, b) => - parseInt(cl.nostr.ev.first_tag_value(b, "published_at")) - - parseInt(cl.nostr.ev.first_tag_value(a, "published_at")), + events_list.set( + [...$events_list, event].sort( + (a, b) => + parseInt(cl.nostr.ev.first_tag_value(b, "published_at")) - + parseInt(cl.nostr.ev.first_tag_value(a, "published_at")), + ), ); - ndk_events = ndk_events; }); + + const nostr_metadata_publish = async (): Promise<void> => { + try { + const profile_name = await cl.dialog.prompt({ + title: `Profile Name`, + message: `What is your profile name.`, + input_placeholder: `Enter profile name`, + }); + if (profile_name === false) return; + + const display_name = await cl.dialog.prompt({ + title: `Display Name`, + message: `What is your display name.`, + input_placeholder: `Enter display name`, + }); + if (display_name === false) return; + + const content = { + name: profile_name, + display_name, + }; + const ev = await ndk_event({ + $ndk, + $ndk_user, + basis: { + kind: NDKKind.Metadata, + content: JSON.stringify(content), + }, + }); + if (ev) { + await ev.publish(); + await restart(); + } + } catch (e) { + console.log(`(error) nostr_metadata_pub `, e); + } + }; </script> -<LayoutView> +<LayoutView basis={{ fade: true }}> <LayoutTrellis> <Trellis basis={{ @@ -54,23 +94,23 @@ title: { value: `Nostr Profile`, }, - list: ndk_events.length - ? Object.entries(JSON.parse(ndk_events[0].content)).map( - ([entry_key, entry_val]) => ({ - hide_active: true, - touch: { - label: { - left: [ - { - value: `${entry_key}: ${entry_val}`, - classes: `capitalize`, - }, - ], - }, - callback: async () => {}, + list: $events_list.length + ? Object.entries( + JSON.parse($events_list[0].content), + ).map(([entry_key, entry_val]) => ({ + hide_active: true, + touch: { + label: { + left: [ + { + value: `${$t(`common.${entry_key}`, { default: `${entry_key.replace(`_`, ` `)}` })}: ${entry_val}`, + classes: `capitalize`, + }, + ], }, - }), - ) + callback: async () => {}, + }, + })) : [ { touch: { @@ -87,17 +127,7 @@ }, }, callback: async () => { - app_nav_prev.set([ - ...$app_nav_prev, - { - label: `Profile`, - route: `/nostr/profile`, - }, - ]); - app_nav_title.set({ - label: `Add Profile`, - }); - await goto(`/nostr/profile/edit`); + await nostr_metadata_publish(); }, }, }, @@ -107,3 +137,22 @@ /> </LayoutTrellis> </LayoutView> +<Nav + basis={{ + prev: { + label: `Nostr`, + route: `/nostr`, + }, + title: { + label: `Profile`, + }, + option: $events_list.length + ? { + label: `Edit`, + callback: async () => { + await nostr_metadata_publish(); + }, + } + : undefined, + }} +/> diff --git a/src/routes/(app)/nostr/profile/edit/+page.svelte b/src/routes/(app)/nostr/profile/edit/+page.svelte @@ -1,68 +0,0 @@ -<script lang="ts"> - import { goto } from "$app/navigation"; - import { cl } from "$lib/client"; - import { app_nav_prev } from "$lib/stores"; - import { NDKKind } from "@nostr-dev-kit/ndk"; - import { ndk, ndk_event, ndk_user } from "@radroots/svelte-lib"; - - $effect(() => { - (async () => { - try { - const profile_name = await cl.dialog.prompt({ - title: `Profile Name`, - message: `What is your profile name.`, - input_placeholder: `Enter profile name`, - }); - if (profile_name === false) { - await goto(`/`); - return; - } - - const display_name = await cl.dialog.prompt({ - title: `Display Name`, - message: `What is your display name.`, - input_placeholder: `Enter display name`, - }); - if (display_name === false) { - await goto(`/`); - return; - } - - await nostr_metadata_pub({ - profile_name, - display_name, - }); - } catch (e) {} - })(); - }); - - const nostr_metadata_pub = async (opts: { - profile_name: string; - display_name: string; - }): Promise<void> => { - try { - const { profile_name: name, display_name } = opts; - const content = { - name, - display_name, - }; - const ev = await ndk_event({ - $ndk, - $ndk_user, - basis: { - kind: NDKKind.Metadata, - content: JSON.stringify(content), - }, - }); - console.log(JSON.stringify(ev, null, 4), `ev`); - if (ev) await ev.publish(); - cl.dialog.alert(`Published content ${JSON.stringify(content)}`); - app_nav_prev.set([]); - await goto(`/`); - } catch (e) { - console.log(`(error) nostr_metadata_pub `, e); - } - }; -</script> - -<div></div> diff --git a/src/routes/(app)/settings/+page.svelte b/src/routes/(app)/settings/+page.svelte @@ -2,15 +2,16 @@ import { cl } from "$lib/client"; import LayoutTrellis from "$lib/components/layout-trellis.svelte"; import LayoutView from "$lib/components/layout-view.svelte"; + import Nav from "$lib/components/nav.svelte"; import { _cf } from "$lib/conf"; - import { app_nav_visible, app_tabs_visible, app_thc } from "$lib/stores"; + import { app_tabs_visible, app_thc } from "$lib/stores"; import { toggle_color_mode, trellis as Trellis, } from "@radroots/svelte-lib"; $effect(() => { - app_nav_visible.set(true); + //app_nav_visible.set(true); app_tabs_visible.set(false); }); </script> @@ -295,3 +296,11 @@ /> </LayoutTrellis> </LayoutView> +<Nav + basis={{ + prev: { + label: `Home`, + route: `/`, + }, + }} +/> diff --git a/src/routes/(conf)/conf/nostr/+page.svelte b/src/routes/(conf)/conf/nostr/+page.svelte @@ -1,15 +1,15 @@ <script lang="ts"> - import { goto } from "$app/navigation"; - import { cl, nt } from "$lib/client"; + import { cl } from "$lib/client"; import { _cf } from "$lib/conf"; + import { restart } from "$lib/utils"; </script> <div class={`flex flex-col w-full pt-16 justify-center items-center`}> <button class={`flex flex-row justify-center items-center text-white`} onclick={async () => { - const sk_hex = nt.generate_key(); - const pk_hex = nt.public_key(sk_hex); + const sk_hex = cl.nostr.lib.generate_key(); + const pk_hex = cl.nostr.lib.public_key(sk_hex); const new_key_added = await cl.keystore.set( `nostr:key:${pk_hex}`, sk_hex, @@ -20,7 +20,7 @@ pk_hex, ); if (key_pref_added) { - await goto(`/`); + await restart(); } } }} diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte @@ -94,6 +94,7 @@ if (!app_config) return; app_sqlite.set(!!(await cl.db.connect(PUBLIC_DATABASE_NAME))); const active_nostr_pk = await cl.preferences.get(_cf.pref_key_active); + console.log(`active npub `, cl.nostr.lib.npub(active_nostr_pk)) const active_nostr_sk = await cl.keystore.get(`nostr:key:${active_nostr_pk}`); if(typeof active_nostr_sk === `string` && active_nostr_sk && active_nostr_pk) app_nostr_key.set(active_nostr_pk); else { @@ -110,6 +111,7 @@ app_render.subscribe(async (app_render) => { try { if (!app_render) return; + await goto(`/`); await sleep(321); } catch (e) { console.log(`(app_render) error `, e);