From 9bbdfc1618b06a00bf9fbf988ced6b43f796070f Mon Sep 17 00:00:00 2001 From: silberengel Date: Tue, 19 Aug 2025 18:05:28 +0200 Subject: [PATCH] Added helpful text and allow for multi-tag eventinput --- src/lib/components/EventInput.svelte | 171 +++++++++++++++++++++------ src/routes/events/+page.svelte | 23 +++- 2 files changed, 155 insertions(+), 39 deletions(-) diff --git a/src/lib/components/EventInput.svelte b/src/lib/components/EventInput.svelte index 59cc3bd..3fcf610 100644 --- a/src/lib/components/EventInput.svelte +++ b/src/lib/components/EventInput.svelte @@ -24,7 +24,7 @@ import type { NDKEvent } from "$lib/utils/nostrUtils"; import { prefixNostrAddresses } from "$lib/utils/nostrUtils"; import { activeInboxRelays, activeOutboxRelays, getNdkContext } from "$lib/ndk"; - import { Button } from "flowbite-svelte"; + import { Button, Tooltip } from "flowbite-svelte"; import { goto } from "$app/navigation"; import { WebSocketPool } from "$lib/data_structures/websocket_pool"; import { anonymousRelays } from "$lib/consts"; @@ -32,7 +32,7 @@ const ndk = getNdkContext(); let kind = $state(30040); - let tags = $state<[string, string][]>([]); + let tags = $state([]); let content = $state(""); let createdAt = $state(Math.floor(Date.now() / 1000)); let loading = $state(false); @@ -136,20 +136,72 @@ }); function updateTag(index: number, key: string, value: string): void { - tags = tags.map((t, i) => (i === index ? [key, value] : t)); + tags = tags.map((t, i) => { + if (i === index) { + const newTag = [...t]; + newTag[0] = key; + if (newTag.length < 2) { + newTag.push(value); + } else { + newTag[1] = value; + } + return newTag; + } + return t; + }); } + + function updateTagValue(index: number, valueIndex: number, value: string): void { + tags = tags.map((t, i) => { + if (i === index) { + const newTag = [...t]; + newTag[valueIndex] = value; + return newTag; + } + return t; + }); + } + function addTag(): void { tags = [...tags, ["", ""]]; } + + function addTagValue(tagIndex: number): void { + tags = tags.map((t, i) => { + if (i === tagIndex) { + return [...t, ""]; + } + return t; + }); + } + + function removeTagValue(tagIndex: number, valueIndex: number): void { + tags = tags.map((t, i) => { + if (i === tagIndex) { + const newTag = t.filter((_, vi) => vi !== valueIndex); + // Ensure we always have at least the key and one value + return newTag.length >= 2 ? newTag : [newTag[0] || "", ""]; + } + return t; + }); + } + + // AI-NOTE: 2025-01-24 - Fixed tag deletion to allow removing all tags and automatically add empty row function removeTag(index: number): void { + // Remove the tag at the specified index tags = tags.filter((_, i) => i !== index); + + // If no tags remain, add an empty tag row so users can continue adding tags + if (tags.length === 0) { + tags = [["", ""]]; + } } function addExtractedTag(key: string, value: string): void { // Check if tag already exists const existingIndex = tags.findIndex(([k]) => k === key); if (existingIndex >= 0) { - // Update existing tag + // Update existing tag's first value tags = tags.map((t, i) => (i === existingIndex ? [key, value] : t)); } else { // Add new tag @@ -257,9 +309,14 @@ console.log("=== 30040 EVENT CREATION START ==="); console.log("Creating 30040 event set with content:", content); try { + // Convert multi-value tags to the format expected by build30040EventSet + const compatibleTags: [string, string][] = tags + .filter(tag => tag.length >= 2 && tag[0].trim() !== "") + .map(tag => [tag[0], tag[1] || ""] as [string, string]); + const { indexEvent, sectionEvents } = build30040EventSet( content, - tags, + compatibleTags, baseEvent, ndk, ); @@ -289,7 +346,10 @@ return; } } else { - let eventTags = [...tags]; + // Convert multi-value tags to the format expected by NDK + let eventTags = tags + .filter(tag => tag.length >= 2 && tag[0].trim() !== "") + .map(tag => [...tag]); // Keep all values // Ensure d-tag exists and has a value for addressable events if (requiresDTag(kind)) { @@ -355,7 +415,7 @@ created_at: Number( event.created_at ?? Math.floor(Date.now() / 1000), ), - tags: event.tags.map((tag) => [String(tag[0]), String(tag[1])]), + tags: event.tags.map((tag) => tag.map(String)), content: String(event.content), }; if ( @@ -510,11 +570,20 @@ {/if} {#if Number(kind) === 30040} -
- 30040 - Publication Index: - {get30040EventDescription()} +
+ Publication Index + + +
+ 30040 - Publication Index: Events that organize AsciiDoc content into structured publications with metadata tags and section references. +
+
{/if}
@@ -551,30 +620,60 @@ {/if}
- {#each tags as [key, value], i} -
- - updateTag(i, (e.target as HTMLInputElement).value, tags[i][1])} - /> - - updateTag(i, tags[i][0], (e.target as HTMLInputElement).value)} - /> - + {#each tags as tag, i} +
+
+ Tag: + + updateTag(i, (e.target as HTMLInputElement).value, tags[i][1] || "")} + /> + +
+ +
+
+ Values: + +
+ + {#each tag.slice(1) as value, valueIndex} +
+ {valueIndex + 1}: + + updateTagValue(i, valueIndex + 1, (e.target as HTMLInputElement).value)} + /> + {#if tag.length > 2} + + {/if} +
+ {/each} +
{/each}
diff --git a/src/routes/events/+page.svelte b/src/routes/events/+page.svelte index e1ed98a..5d6e436 100644 --- a/src/routes/events/+page.svelte +++ b/src/routes/events/+page.svelte @@ -536,9 +536,17 @@

- Use this page to view any event (npub, nprofile, nevent, naddr, note, - pubkey, or eventID). You can also search for events by d-tag using the - format "d:tag-name". + Search and explore Nostr events across the network. Find events by: +

+
    +
  • Event identifiers: nevent, note, naddr, npub, nprofile, pubkey, or event ID
  • +
  • NIP-05 addresses: username@domain.com
  • +
  • Profile names: Search by display name or username (use "n:" prefix for exact matches)
  • +
  • D-tags: Find events with specific d-tags using "d:tag-name"
  • +
  • T-tags: Find events tagged with specific topics using "t:topic"
  • +
+

+ The page shows primary search results, second-order references (replies, quotes, mentions), and related tagged events. Click any event to view details, comments, and relay information.

+ Publish Nostr Event +

+ Create and publish new Nostr events to the network. This form supports various event kinds including: +

+
    +
  • Kind 30040: Publication indexes that organize AsciiDoc content into structured publications
  • +
  • Kind 30041: Individual section content for publications
  • +
  • Other kinds: Standard Nostr events with custom tags and content
  • +
{/if}