import { useState } from 'react'; import { Bell, BellOff, Loader2, Check } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { LoginArea } from '@/components/auth/LoginArea'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useNewsletterSubscription } from '@/hooks/useNewsletterSubscription'; import { useToast } from '@/hooks/useToast'; import { cn } from '@/lib/utils'; /** * Opt-in / opt-out of the SkateSpots newsletter mailbox. When subscribed, new * issues surface in the notification bell's "News" tab. Logged-out users see a * login prompt instead. */ export function NewsletterSubscribeButton({ className }: { className?: string }) { const { user } = useCurrentUser(); const { isSubscribed, isLoading, setSubscribed, isUpdating } = useNewsletterSubscription(); const { toast } = useToast(); const [justSubscribed, setJustSubscribed] = useState(false); if (!user) { return (

Log in with Nostr to get new drops in your mailbox.

); } const handleToggle = async () => { try { const next = !isSubscribed; await setSubscribed(next); if (next) { setJustSubscribed(true); setTimeout(() => setJustSubscribed(false), 2500); toast({ title: "You're subscribed! 🛹", description: 'New drops will land in your notification bell under "News".', }); } else { toast({ title: 'Unsubscribed', description: 'You can still read every issue here anytime.', }); } } catch (err) { toast({ title: 'Something went wrong', description: err instanceof Error ? err.message : 'Please try again.', variant: 'destructive', }); } }; if (isLoading) { return ( ); } if (isSubscribed) { return ( ); } return ( ); }