diff --git a/package.json b/package.json index 56388f7..033da98 100644 --- a/package.json +++ b/package.json @@ -39,8 +39,8 @@ "quilljs-markdown": "^1.2.0", "radix-icons-svelte": "^1.2.1", "svelte-inview": "^4.0.2", - "svelte-loading-spinners": "^0.3.6", "svelte-radix": "^1.0.1", + "svelte-sonner": "0.3.27", "tailwind-merge": "^2.2.1", "tailwind-variants": "^0.2.0", "yjs": "^13.6.12" @@ -70,6 +70,7 @@ "svelte": "^4.2.8", "svelte-awesome-icons": "^1.2.0", "svelte-check": "^3.6.2", + "svelte-loading-spinners": "^0.3.6", "svelte-quill": "^1.2.0", "tailwindcss": "^3.3.3", "tslib": "^2.6.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fb61aa8..bf7d67d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -71,12 +71,12 @@ dependencies: svelte-inview: specifier: ^4.0.2 version: 4.0.2(svelte@4.2.12) - svelte-loading-spinners: - specifier: ^0.3.6 - version: 0.3.6 svelte-radix: specifier: ^1.0.1 version: 1.1.0(svelte@4.2.12) + svelte-sonner: + specifier: 0.3.27 + version: 0.3.27(svelte@4.2.12) tailwind-merge: specifier: ^2.2.1 version: 2.2.2 @@ -160,6 +160,9 @@ devDependencies: svelte-check: specifier: ^3.6.2 version: 3.6.9(postcss@8.4.38)(svelte@4.2.12) + svelte-loading-spinners: + specifier: ^0.3.6 + version: 0.3.6 svelte-quill: specifier: ^1.2.0 version: 1.2.0 @@ -4158,7 +4161,7 @@ packages: /svelte-loading-spinners@0.3.6: resolution: {integrity: sha512-mthHQ2TwiwzTWzbFry3CBnVEfzqPOD9WkVw84OfSYzHRq6N9wgQ+yv37u81uPeuLU/ZOIPqhujpXquB1aol5ZQ==} - dev: false + dev: true /svelte-preprocess@5.1.3(postcss@8.4.38)(svelte@4.2.12)(typescript@5.4.4): resolution: {integrity: sha512-xxAkmxGHT+J/GourS5mVJeOXZzne1FR5ljeOUAMXUkfEhkLEllRreXpbl3dIYJlcJRfL1LO1uIAPpBpBfiqGPw==} @@ -4221,6 +4224,14 @@ packages: svelte: 4.2.12 dev: false + /svelte-sonner@0.3.27(svelte@4.2.12): + resolution: {integrity: sha512-+PvbuePNTyTNCepCWqKcFeu+Lo27yYuwfSc7zJvrWjCRMJrWAmccPg3j7jO1W13QoN3TySXU5Trb956VBQiM5Q==} + peerDependencies: + svelte: ^3.0.0 || ^4.0.0 || ^5.0.0-next.1 + dependencies: + svelte: 4.2.12 + dev: false + /svelte-time@0.8.2: resolution: {integrity: sha512-sBLLrWMMInx5iidGlbtlCBAu8CzSixdqOkbhizdalULXBvYMPACp0GtzmyBLEa77hbaMVySZzApIaNG4B4OVmg==} dependencies: diff --git a/src/lib/components/Button.svelte b/src/lib/components/Button.svelte index ef2f4ef..069f367 100644 --- a/src/lib/components/Button.svelte +++ b/src/lib/components/Button.svelte @@ -1,13 +1,20 @@ - diff --git a/src/lib/components/MessageInput.svelte b/src/lib/components/MessageInput.svelte index 951d817..20ae64d 100644 --- a/src/lib/components/MessageInput.svelte +++ b/src/lib/components/MessageInput.svelte @@ -4,42 +4,58 @@ import { currentUser, ndk } from '@/ndk/ndk'; import { NDKEvent, type NDKTag } from '@nostr-dev-kit/ndk'; import { Textarea } from './ui/textarea'; + import { Circle } from 'svelte-loading-spinners'; + import { toast } from 'svelte-sonner'; export let selected = true; export let content = ''; export let tags: NDKTag[] = []; export let horsenote = false; - function publish(c: string) { - if (c.length < 1) {alert("invalid note length")} - console.log(15, c) + let isPublishing = false; + + async function publish(c: string) { + if (c.length < 1) { + toast.error('Invalid note length'); + return; + } + console.log(15, c); if (!$currentUser) { - alert('could not find your event signer'); + toast.error('Could not find your event signer'); throw new Error('invalid user'); } else { + isPublishing = true; let e = new NDKEvent($ndk); e.kind = 1; e.created_at = Math.floor(new Date().getTime() / 1000); e.content = c + (horsenote ? '\nPublished with humble.horse 🐎🐎🐎' : ''); e.tags = tags; e.author = $currentUser; - console.log(e) - e.publish().then((r) => { + console.log(e); + try { + const r = await e.publish(); console.log(r); console.log(e); - }); + content = ''; + toast.success('Note published successfully!'); + } catch (error) { + console.error('Failed to publish note:', error); + toast.error('Failed to publish note. Please try again.'); + } finally { + isPublishing = false; + } } } -