commit 12b5e18a17259322b22e48da2f96f6e202378aa7
parent 0830aeaadb118857a2f88d87804d9a4fa2521062
Author: triesap <137732411+triesap@users.noreply.github.com>
Date: Thu, 3 Oct 2024 12:23:31 +0000
Add nostr relay document polling counter, edit nostr relay routes
Diffstat:
4 files changed, 83 insertions(+), 34 deletions(-)
diff --git a/src/lib/conf.ts b/src/lib/conf.ts
@@ -23,6 +23,9 @@ export const _conf = {
title: `Radroots`,
description: `Creating networks between farmers, communities and small businesses that give customers greater access to natural foods and grow circular economies where profits are more fairly distributed. Radroots is built on the Nostr protocol and released under a copyleft open source license to provide transparency and give users the option to offer feedback and add or request new features.`
},
+ nostr: {
+ relay_polling_count_max: 10,
+ },
delay: {
load: 321,
notify: 123,
diff --git a/src/routes/(app)/models/nostr-relay/+page.svelte b/src/routes/(app)/models/nostr-relay/+page.svelte
@@ -111,18 +111,18 @@
nostr_relay.id,
)
? `bg-layer-1-glyph-hl/60 group-active:opacity-40`
- : `bg-amber-700/80 group-active:opacity-40`,
+ : `bg-yellow-600/90 group-active:opacity-40`,
glyph: {
classes: $nostr_relays_connected.includes(
nostr_relay.id,
)
- ? `text-white group-active:opacity-60 fade-in`
- : `text-amber-200 group-active:opacity-60 fade-in`,
+ ? `text-white/80 group-active:opacity-60 fade-in`
+ : `text-yellow-100/80 group-active:opacity-60 fade-in`,
key: $nostr_relays_connected.includes(
nostr_relay.id,
)
? `check`
- : `x`,
+ : `exclamation-mark`,
weight: `bold`,
dim: `xs-`,
},
@@ -173,7 +173,7 @@
args: {
layer: 1,
title: {
- value: `${$t(`icu.connected_*`, { value: `${$t(`common.relays`)}` })}`,
+ value: `${$t(`icu.nostr_*`, { value: `${$t(`common.relays`)}` })}`,
},
list: tr_list_relays,
},
diff --git a/src/routes/(app)/models/nostr-relay/view/+page.svelte b/src/routes/(app)/models/nostr-relay/view/+page.svelte
@@ -54,6 +54,20 @@
$: {
app_blur.set(show_edit);
}
+
+ const relay_connect = async (): Promise<void> => {
+ try {
+ } catch (e) {
+ console.log(`(error) relay_connect `, e);
+ }
+ };
+
+ const relay_disconnect = async (): Promise<void> => {
+ try {
+ } catch (e) {
+ console.log(`(error) relay_disconnect `, e);
+ }
+ };
</script>
<LayoutView>
@@ -96,19 +110,33 @@
hide_active: true,
touch: {
label: {
- left: [
- $nostr_relays_connected.includes(
- ld.nostr_relay.id,
- )
- ? {
+ left: $nostr_relays_connected.includes(
+ ld.nostr_relay.id,
+ )
+ ? [
+ {
+ glyph: {
+ classes: `text-success`,
+ key: `globe`,
+ },
+ },
+ {
classes: `text-success font-[500]`,
value: `${$t(`common.connected`)}`,
- }
- : {
- classes: `text-red-500 font-[500]`,
+ },
+ ]
+ : [
+ {
+ glyph: {
+ classes: `text-yellow-700/80`,
+ key: `globe-x`,
+ },
+ },
+ {
+ classes: `text-yellow-700/80 font-[500] capitalize`,
value: `${$t(`common.not_connected`)}`,
},
- ],
+ ],
},
},
},
@@ -289,25 +317,34 @@
},
}}
/>
-<EnvelopeButtons
- basis={{
- visible: show_edit,
- buttons: [
- {
- classes: `text-envelopeButtonCancel text-layer-1-glyph-hl`,
- label: `${$t(`common.cancel`)}`,
- callback: async () => {
- show_edit = false;
+{#if ld}
+ <EnvelopeButtons
+ basis={{
+ visible: show_edit,
+ buttons: [
+ {
+ classes: `text-envelopeButtonCancel text-layer-1-glyph-hl`,
+ label: `${$t(`common.cancel`)}`,
+ callback: async () => {
+ show_edit = false;
+ },
},
- },
- {
- classes: `text-envelopeButtonLabel text-red-400`,
- label: `${$t(`common.disconnect`)}`,
- callback: async () => {
- alert(`@todo!`);
- show_edit = false;
+ {
+ classes: $nostr_relays_connected.includes(ld.nostr_relay.id)
+ ? `text-envelopeButtonLabel text-red-400`
+ : `text-envelopeButtonLabel text-success`,
+ label: $nostr_relays_connected.includes(ld.nostr_relay.id)
+ ? `${$t(`icu.disconnect_*`, { value: `${$t(`common.relay`)}` })}`
+ : `${$t(`icu.connect_*`, { value: `${$t(`common.relay`)}` })}`,
+ callback: async () => {
+ if (!ld) return;
+ if ($nostr_relays_connected.includes(ld.nostr_relay.id))
+ await relay_disconnect();
+ else await relay_connect();
+ show_edit = false;
+ },
},
- },
- ],
- }}
-/>
+ ],
+ }}
+ />
+{/if}
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
@@ -25,6 +25,7 @@
ndk_user,
nostr_relays_connected,
nostr_relays_poll_documents,
+ nostr_relays_poll_documents_count,
route,
sleep,
theme_set,
@@ -183,6 +184,14 @@
const fetch_relay_documents = async (): Promise<void> => {
try {
+ if (
+ $nostr_relays_poll_documents_count >=
+ _conf.nostr.relay_polling_count_max
+ )
+ return;
+ nostr_relays_poll_documents_count.set(
+ $nostr_relays_poll_documents_count + 1,
+ );
const nostr_relays = await lc.db.nostr_relay_get({
list: ["on_key", { public_key: $app_nostr_key }],
});