import { useState } from 'react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Textarea } from '@/components/ui/textarea'; import { Button } from '@/components/ui/button'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { Badge } from '@/components/ui/badge'; import { Send, Sparkles, Leaf } from 'lucide-react'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useNostrPublish } from '@/hooks/useNostrPublish'; import { useAuthor } from '@/hooks/useAuthor'; import { genUserName } from '@/lib/genUserName'; import { translateToGnomeSpeak } from '@/lib/gnomeSpeak'; import { useToast } from '@/hooks/useToast'; export function GnomeComposer() { const [content, setContent] = useState(''); const [isPreviewMode, setIsPreviewMode] = useState(false); const { user } = useCurrentUser(); const { mutate: createEvent, isPending } = useNostrPublish(); const { toast } = useToast(); const author = useAuthor(user?.pubkey || ''); const metadata = author.data?.metadata; const displayName = metadata?.name ?? (user?.pubkey ? genUserName(user.pubkey) : 'Anonymous Gnome'); const profileImage = metadata?.picture; const handleSubmit = () => { if (!content.trim()) { toast({ title: "Empty woodland proclamation!", description: "Even gnomes need something to say to the forest folk.", variant: "destructive", }); return; } if (!user) { toast({ title: "Authentication required", description: "You must be logged in to share woodland wisdom.", variant: "destructive", }); return; } createEvent( { kind: 1, content: content.trim(), tags: [['t', 'gnome']] // Tag all posts as gnome content }, { onSuccess: () => { setContent(''); setIsPreviewMode(false); toast({ title: "Woodland proclamation sent! 🍄", description: "Your message has been carried by the forest winds to all the message-mushrooms.", }); }, onError: (error) => { toast({ title: "Forest spirits are troubled", description: `Failed to send your proclamation: ${error.message}`, variant: "destructive", }); } } ); }; const gnomeTranslatedContent = content ? translateToGnomeSpeak(content) : ''; if (!user) { return (
🍄

Join the Forest Council

Log in to share your woodland wisdom with fellow gnomes across the message-mushroom network!

); } return (
{displayName.slice(0, 2).toUpperCase()}
Share Woodland Wisdom 🍄 Gnome Speak

Your words will be translated into the ancient gnome tongue

{!isPreviewMode ? (