From 1e907771d35a71c11d5d51cea1101b3587097fcd Mon Sep 17 00:00:00 2001 From: limina1 Date: Fri, 25 Jul 2025 18:02:14 -0400 Subject: [PATCH] feat: publish array of notes --- src/routes/new/compose/+page.svelte | 42 ++++++++++++++++------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/routes/new/compose/+page.svelte b/src/routes/new/compose/+page.svelte index 5c5ff5c..73eb646 100644 --- a/src/routes/new/compose/+page.svelte +++ b/src/routes/new/compose/+page.svelte @@ -4,15 +4,15 @@ import ZettelEditor from "$lib/components/ZettelEditor.svelte"; import { goto } from "$app/navigation"; import { nip19 } from "nostr-tools"; - import { publishZettel } from "$lib/services/publisher"; + import { publishMultipleZettels } from "$lib/services/publisher"; let content = $state(""); let showPreview = $state(false); let isPublishing = $state(false); - let publishResult = $state<{ - success: boolean; - eventId?: string; - error?: string; + let publishResults = $state<{ + successCount: number; + total: number; + errors: string[]; } | null>(null); // Handle content changes from ZettelEditor @@ -27,20 +27,23 @@ async function handlePublish() { isPublishing = true; - publishResult = null; + publishResults = null; - const result = await publishZettel({ + const results = await publishMultipleZettels({ content, - onSuccess: (eventId) => { - publishResult = { success: true, eventId }; - const nevent = nip19.neventEncode({ id: eventId }); - goto(`/events?id=${nevent}`); - }, onError: (error) => { - publishResult = { success: false, error }; + // Only used for catastrophic errors + publishResults = { successCount: 0, total: 0, errors: [error] }; }, }); + const successCount = results.filter(r => r.success).length; + const errors = results.filter(r => !r.success && r.error).map(r => r.error!); + publishResults = { + successCount, + total: results.length, + errors, + }; isPublishing = false; } @@ -81,16 +84,19 @@ - {#if publishResult} - {#if publishResult.success} + {#if publishResults} + {#if publishResults.successCount === publishResults.total} Success! - Event published successfully. Event ID: {publishResult.eventId} + {publishResults.successCount} events published. {:else} - Error! - {publishResult.error} + Some events failed to publish. + {publishResults.successCount} of {publishResults.total} events published.
+ {#each publishResults.errors as error} +
{error}
+ {/each}
{/if} {/if}