commit 8df7cbb480582dae558304105845c5b383e6f4a9
parent f72d78acf49cde274c26790beaee84da4d815df3
Author: triesap <137732411+triesap@users.noreply.github.com>
Date: Wed, 20 Nov 2024 12:54:18 +0000
Edit config add nostr client, add/edit utils.
Diffstat:
3 files changed, 44 insertions(+), 55 deletions(-)
diff --git a/src/lib/conf.ts b/src/lib/conf.ts
@@ -1,7 +1,5 @@
import { PUBLIC_RADROOTS_NOSTR_PUBKEY } from "$env/static/public";
-import type { NumberTuple } from "@radroots/utils";
-//import tailwindConfig from '../..//tailwind.config';
-//export const tw = tailwindConfig;
+import type { NostrTagClient, NumberTuple } from "@radroots/utils";
export const ks = {
cfg_init: {
@@ -20,6 +18,7 @@ export const ks = {
export const root_symbol = "»--`--,---";
+
export const ascii = {
bullet: '•',
dash: `—`
@@ -66,6 +65,12 @@ export const cfg = {
}
};
+export const nostr_client: NostrTagClient = {
+ name: root_symbol,
+ pubkey: cfg.nostr.relay_pubkey,
+ relay: cfg.nostr.relay_url
+};
+
export const scroll_args: {
into_view: ScrollIntoViewOptions
} = {
diff --git a/src/lib/utils/nostr.ts b/src/lib/utils/nostr.ts
@@ -1,5 +1,5 @@
import { db, dialog } from "$lib/client";
-import { cfg, root_symbol } from "$lib/conf";
+import { nostr_client, root_symbol } from "$lib/conf";
import { NDKKind } from "@nostr-dev-kit/ndk";
import { app_nostr_key, ndk, ndk_user, nostr_sync_prevent, t } from "@radroots/svelte-lib";
import { fmt_tags_basis_nip99, ndk_event, nevent_encode, num_str } from "@radroots/utils";
@@ -56,11 +56,7 @@ export const nostr_sync = async (): Promise<void> => {
content: ``,
tags: await fmt_tags_basis_nip99({
d_tag: trade_product.id,
- client: {
- name: root_symbol,
- pubkey: cfg.nostr.relay_pubkey,
- relay: cfg.nostr.relay_url
- },
+ client: nostr_client,
listing: {
title: trade_product.title,
summary: trade_product.summary,
@@ -107,4 +103,10 @@ export const nostr_sync = async (): Promise<void> => {
} catch (e) {
console.log(`(error) nostr_sync `, e);
}
-};
-\ No newline at end of file
+};
+
+export const nostr_tags_basis = (): string[][] => {
+ const tags: string[][] = [];
+ for (const tag of [`app/0.0.0`]) tags.push([root_symbol, tag])
+ return tags;
+};
diff --git a/src/routes/(app)/test/+page.svelte b/src/routes/(app)/test/+page.svelte
@@ -1,57 +1,40 @@
<script lang="ts">
- import type { NostrEventPageStore } from "$lib/types";
- import { type NDKFilter, NDKKind } from "@nostr-dev-kit/ndk";
- import {
- app_nostr_key,
- LayoutView,
- Nav,
- ndk,
- t,
- } from "@radroots/svelte-lib";
- import { onDestroy } from "svelte";
+ import { nostr_tags_basis } from "$lib/utils/nostr";
+ import { NDKKind } from "@nostr-dev-kit/ndk";
+ import { LayoutView, Nav, ndk, ndk_user, t } from "@radroots/svelte-lib";
+ import { ndk_event } from "@radroots/utils";
- let events_store: NostrEventPageStore;
-
- $: {
- let authors = [$app_nostr_key];
- let ndk_filter: NDKFilter = {
- kinds: [NDKKind.Classified],
- ...{ authors },
- };
-
- fetch_events(ndk_filter).then(() => {
- events_store?.startSubscription();
- });
- }
-
- const fetch_events = async (filter: NDKFilter): Promise<void> => {
+ const post = async (): Promise<void> => {
try {
- events_store = $ndk.storeSubscribe(filter, {
- closeOnEose: true,
- groupable: false,
- autoStart: false,
+ const tags = nostr_tags_basis();
+
+ const ev = await ndk_event({
+ $ndk,
+ $ndk_user,
+ basis: {
+ kind: NDKKind.Text,
+ content: `testing radroots at ${new Date().toISOString()}`,
+ tags,
+ },
});
- if (events_store) events_store.onEose(() => {});
+ if (ev) await ev.publish();
+ console.log(JSON.stringify(ev, null, 4), `ev`);
} catch (e) {
- console.log(`(error) fetch_events `, e);
+ console.log(`(error) post `, e);
}
};
-
- onDestroy(() => events_store?.unsubscribe());
</script>
<LayoutView>
- <div class={`flex flex-col w-full px-4 gap-4 justify-start items-center`}>
- {#if $events_store?.length}
- {#each $events_store as ev, ev_i (ev.id)}
- <p class={`font-sans font-[400] text-layer-0-glyph break-all`}>
- {JSON.stringify(ev.content)}
- </p>
- <p class={`font-sans font-[400] text-layer-0-glyph break-all`}>
- {JSON.stringify(ev.tags)}
- </p>
- {/each}
- {/if}
+ <div class={`flex flex-col w-full px-4 gap-4 justify-center items-center`}>
+ <button
+ class={`flex flex-row justify-center items-center`}
+ on:click={async () => {
+ await post();
+ }}
+ >
+ post
+ </button>
</div>
</LayoutView>