commit c5800d2b82cf13f3be4170cc6e38d351cedbeaf6
parent 9014496d467d9e3f6a2b22ec5b1e459c7efd68ee
Author: triesap <137732411+triesap@users.noreply.github.com>
Date: Thu, 10 Apr 2025 22:01:15 +0000
apps-lib: add nostr sync retry handler, nostr stores. fix missing input value component id attribute
Diffstat:
4 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/apps-lib/src/lib/components/lib/input-value.svelte b/apps-lib/src/lib/components/lib/input-value.svelte
@@ -12,6 +12,7 @@
value: string;
} = $props();
+ const id = $derived(basis?.id ? basis.id : null);
const layer = $derived(
typeof basis?.layer === `boolean`
? parse_layer(0)
@@ -59,6 +60,7 @@
el: ev.currentTarget,
});
}}
+ {id}
type="text"
class={`${fmt_cl(basis?.classes)} el-input ${classes_layer} el-re`}
placeholder={basis?.placeholder || ``}
diff --git a/apps-lib/src/lib/index.ts b/apps-lib/src/lib/index.ts
@@ -95,6 +95,7 @@ export * from "./store/client.js"
export * from "./store/component.js"
export * from "./store/layout.js"
export * from "./store/ndk.js"
+export * from "./store/nostr.js"
export * from "./types/component.js"
export * from "./types/interface.js"
export * from "./types/lib.js"
diff --git a/apps-lib/src/lib/store/client.ts b/apps-lib/src/lib/store/client.ts
@@ -42,10 +42,3 @@ const fn_carousel_num = (num_i: number, num_min: number) => {
export const carousel_num = fn_carousel_num(1, 1);
export const envelope_visible = writable<boolean>(false);
export const envelope_tilt = writable<boolean>(true);
-
-export const nostr_ndk_configured = writable<boolean>(false);
-export const nostr_relays_poll_documents = writable<boolean>(false);
-export const nostr_relays_poll_documents_count = writable<number>(0);
-export const nostr_relays_connected = writable<string[]>([]);
-export const nostr_sync_prevent = writable<boolean>(false);
-
diff --git a/apps-lib/src/lib/store/nostr.ts b/apps-lib/src/lib/store/nostr.ts
@@ -0,0 +1,38 @@
+import { get_store } from "$root";
+import { writable } from "svelte/store";
+
+export const nostr_ndk_configured = writable<boolean>(false);
+export const nostr_sync_prevent = writable<boolean>(false);
+export const nostr_sync_attempts = writable(0);
+export const nostr_sync_attempts_max = writable(8);
+export const nostr_sync_failure = writable(true);
+/*
+export const nostr_relays_poll_documents = writable<boolean>(false);
+export const nostr_relays_poll_documents_count = writable<number>(0);
+export const nostr_relays_connected = writable<string[]>([]);
+*/
+
+export const nostr_sync_retry_handler = async (callback: () => Promise<any>) => {
+ let current_count = 0;
+ const attempts_max = get_store(nostr_sync_attempts_max);
+
+ nostr_sync_attempts.set(0);
+ nostr_sync_failure.set(false);
+
+ const exe = async () => {
+ if (get_store(nostr_sync_failure)) return;
+ console.log(`[nostr_sync] running... ${current_count}`)
+ try {
+ await callback();
+ } catch (e) {
+ current_count += 1;
+ nostr_sync_attempts.set(current_count);
+ if (current_count < attempts_max) {
+ await new Promise((res) => setTimeout(res, 500));
+ await exe();
+ } else nostr_sync_failure.set(true);
+ }
+ };
+
+ await exe();
+};
+\ No newline at end of file