diff --git a/src/components/article/ArticleView.tsx b/src/components/article/ArticleView.tsx index 6100dfd..7cc6e13 100644 --- a/src/components/article/ArticleView.tsx +++ b/src/components/article/ArticleView.tsx @@ -4,7 +4,8 @@ import { renderMarkdown } from "../../lib/markdown"; import { useUIStore } from "../../stores/ui"; import { useUserStore } from "../../stores/user"; import { useBookmarkStore } from "../../stores/bookmark"; -import { fetchArticle, publishReaction } from "../../lib/nostr"; +import { fetchArticle, publishReaction, publishRepost, publishNote } from "../../lib/nostr"; +import { nip19 } from "@nostr-dev-kit/ndk"; import { useProfile } from "../../hooks/useProfile"; import { ZapModal } from "../zap/ZapModal"; @@ -73,6 +74,9 @@ export function ArticleView() { const [error, setError] = useState(null); const [showZap, setShowZap] = useState(false); const [reacted, setReacted] = useState(false); + const [reposted, setReposted] = useState(false); + const [showComment, setShowComment] = useState(false); + const [commentText, setCommentText] = useState(""); const { isBookmarked, addBookmark, removeBookmark } = useBookmarkStore(); const naddr = pendingArticleNaddr ?? ""; @@ -197,6 +201,28 @@ export function ArticleView() { else addBookmark(event.id); }; + const handleRepost = async () => { + if (!event || reposted) return; + setReposted(true); + try { + await publishRepost(event); + } catch { + setReposted(false); + } + }; + + const handleComment = async () => { + if (!event || !commentText.trim()) return; + const dTag = event.tags.find((t) => t[0] === "d")?.[1] ?? ""; + const naddrStr = nip19.naddrEncode({ identifier: dTag, pubkey: event.pubkey, kind: 30023 }); + const text = `${commentText.trim()}\n\nnostr:${naddrStr}`; + try { + await publishNote(text); + setCommentText(""); + setShowComment(false); + } catch { /* ignore */ } + }; + return (
{/* Header */} @@ -226,6 +252,31 @@ export function ArticleView() { ⚡ zap {authorName} )} + {event && loggedIn && ( + + )} + {event && loggedIn && ( + + )} {naddr && (
+ {/* Comment box */} + {showComment && event && ( +
+ setCommentText(e.target.value)} + onKeyDown={(e) => e.key === "Enter" && handleComment()} + placeholder="Write a comment about this article..." + className="flex-1 bg-bg-raised border border-border rounded-sm px-3 py-1.5 text-[12px] text-text placeholder:text-text-dim focus:outline-none focus:border-accent" + autoFocus + /> + +
+ )} + {/* Body */}
{/* Reading progress bar */} @@ -346,6 +419,27 @@ export function ArticleView() { {bookmarked ? "▪ saved" : "▫ save"} )} + {loggedIn && ( + + )} + {loggedIn && ( + + )} {loggedIn && ( +
+
+
{name}
+
audio · play in wrystr
+
+ ); })}