import { Megaphone, ThumbsUp, ThumbsDown, RefreshCw, ExternalLink, Calendar, Eye, } from 'lucide-react'; import { cn, formatDate, formatNumber } from '@/lib/utils'; import { useTelegram } from '@/hooks/useTelegram'; import { useAnnouncements, useAnnouncementReaction } from '@/hooks/useSupabase'; import { useAuth } from '@/contexts/AuthContext'; export function AnnouncementsSection() { const { hapticImpact, hapticNotification, openLink } = useTelegram(); const { isAuthenticated } = useAuth(); const { data: announcements, isLoading, refetch, isRefetching } = useAnnouncements(); const reactionMutation = useAnnouncementReaction(); const handleReaction = (id: string, reaction: 'like' | 'dislike') => { if (!isAuthenticated) { hapticNotification('error'); // Show alert or toast here if UI library allows, for now using browser alert for clarity in dev // In production better to use a Toast component if (window.Telegram?.WebApp) { window.Telegram.WebApp.showAlert('Ji bo dengdanê divê tu têketî bî'); } else { window.alert('Ji bo dengdanê divê tu têketî bî'); } return; } hapticImpact('light'); reactionMutation.mutate( { announcementId: id, reaction }, { onSuccess: () => hapticNotification('success') } ); }; const handleRefresh = () => { hapticImpact('medium'); refetch(); }; return (
{/* Header */}

Ragihandin

{/* Content */}
{isLoading ? (
{[1, 2, 3].map((i) => (
))}
) : (
{announcements?.map((announcement) => (
{/* Image */} {announcement.image_url && (
)}
{/* Title */}

{announcement.title}

{/* Content */}

{announcement.content}

{/* Link */} {announcement.link_url && ( )} {/* Meta */}
{formatDate(announcement.created_at)} {formatNumber(announcement.views)}
{/* Actions */}
))}
)}
); }