import { Button } from "@/components/ui/button"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { Input } from "@/components/ui/input"; import { useState, useCallback } from "react"; import { Hash, AtSign, Code, Link, Image, Zap, Sparkles } from "lucide-react"; import { useProfileSearch } from "@/hooks/useProfileSearch"; import type { ProfileSearchResult } from "@/services/profile-search"; import { nip19 } from "nostr-tools"; export interface PowerToolsProps { /** Callback when a tool action is triggered */ onInsert?: (text: string) => void; /** Callback when a mention is added */ onAddMention?: (pubkey: string) => void; } /** * Power tools for quick formatting and insertions * * Provides quick access to: * - Hashtags * - Mentions * - Formatting (code, links) * - Quick snippets */ export function PowerTools({ onInsert, onAddMention }: PowerToolsProps) { const [hashtagInput, setHashtagInput] = useState(""); const [mentionQuery, setMentionQuery] = useState(""); const [mentionResults, setMentionResults] = useState( [], ); const { searchProfiles } = useProfileSearch(); // Handle hashtag insert const handleHashtagInsert = useCallback(() => { if (!hashtagInput.trim()) return; const tag = hashtagInput.trim().replace(/^#/, ""); onInsert?.(`#${tag} `); setHashtagInput(""); }, [hashtagInput, onInsert]); // Handle mention search const handleMentionSearch = useCallback( async (query: string) => { setMentionQuery(query); if (query.trim()) { const results = await searchProfiles(query); setMentionResults(results.slice(0, 5)); } else { setMentionResults([]); } }, [searchProfiles], ); // Handle mention select const handleMentionSelect = useCallback( (result: ProfileSearchResult) => { try { const npub = nip19.npubEncode(result.pubkey); onInsert?.(`nostr:${npub} `); onAddMention?.(result.pubkey); setMentionQuery(""); setMentionResults([]); } catch (error) { console.error("Failed to encode npub:", error); } }, [onInsert, onAddMention], ); return (
{/* Hashtag Tool */}
Add Hashtag
setHashtagInput(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter") { handleHashtagInsert(); } }} className="text-sm" />
{/* Mention Tool */}
Add Mention
handleMentionSearch(e.target.value)} className="text-sm" /> {/* Results */} {mentionResults.length > 0 && (
{mentionResults.map((result) => ( ))}
)}
{/* Code Snippet */} {/* Link */}
); }