diff --git a/src/components/PostViewer.tsx b/src/components/PostViewer.tsx index 7e79ca9..c81cebb 100644 --- a/src/components/PostViewer.tsx +++ b/src/components/PostViewer.tsx @@ -1,5 +1,5 @@ import { useState, useRef, useCallback, useMemo, useEffect } from "react"; -import { Paperclip, Send, Loader2, Check, X } from "lucide-react"; +import { Paperclip, Send, Loader2, Check, X, RotateCcw } from "lucide-react"; import { toast } from "sonner"; import { Button } from "./ui/button"; import { Checkbox } from "./ui/checkbox"; @@ -10,6 +10,7 @@ import { useBlossomUpload } from "@/hooks/useBlossomUpload"; import { RichEditor, type RichEditorHandle } from "./editor/RichEditor"; import type { BlobAttachment, EmojiTag } from "./editor/MentionEditor"; import { RelayLink } from "./nostr/RelayLink"; +import { Kind1Renderer } from "./nostr/kinds"; import pool from "@/services/relay-pool"; import eventStore from "@/services/event-store"; import { EventFactory } from "applesauce-core/event-factory"; @@ -42,6 +43,7 @@ export function PostViewer() { const [selectedRelays, setSelectedRelays] = useState>(new Set()); const [isEditorEmpty, setIsEditorEmpty] = useState(true); const [lastPublishedEvent, setLastPublishedEvent] = useState(null); + const [showPublishedPreview, setShowPublishedPreview] = useState(false); // Get active account's write relays from Grimoire state const writeRelays = useMemo(() => { @@ -357,16 +359,14 @@ export function PostViewer() { // Add to event store for immediate local availability eventStore.add(event); - // Clear editor on success - editorRef.current?.clear(); - // Clear draft from localStorage if (pubkey) { const draftKey = `${DRAFT_STORAGE_KEY}-${pubkey}`; localStorage.removeItem(draftKey); } - // Don't clear lastPublishedEvent here - keep it for potential retries + // Show published preview + setShowPublishedPreview(true); toast.success( `Published to ${selected.length} relay${selected.length > 1 ? "s" : ""}`, @@ -399,6 +399,15 @@ export function PostViewer() { [openUpload], ); + // Reset form to compose another post + const handleReset = useCallback(() => { + setShowPublishedPreview(false); + setLastPublishedEvent(null); + updateRelayStates(); + editorRef.current?.clear(); + editorRef.current?.focus(); + }, [updateRelayStates]); + // Show login prompt if not logged in if (!canSign) { return ( @@ -417,51 +426,74 @@ export function PostViewer() { return (
- {/* Editor */} -
- -
+ {!showPublishedPreview ? ( + <> + {/* Editor */} +
+ +
- {/* Action buttons */} -
- + {/* Action buttons */} +
+ - +
+ + ) : ( + <> + {/* Published event preview */} + {lastPublishedEvent && ( +
+ +
)} - -
+ + {/* Reset button */} +
+ +
+ + )} {/* Relay selection */}