import { useEffect, useState } from "react"; import { Button } from "@/components/ui/button"; import { TestimonialCard } from "@/components/TestimonialCard"; import { supabase } from "@/integrations/supabase/client"; import { ArrowLeft, Users } from "lucide-react"; import { useNavigate } from "react-router-dom"; import { formatDistanceToNow } from "date-fns"; interface Signature { id: string; name: string; comment: string | null; created_at: string; } const Testimonies = () => { const [signatures, setSignatures] = useState([]); const [totalCount, setTotalCount] = useState(0); const [isLoading, setIsLoading] = useState(true); const navigate = useNavigate(); useEffect(() => { fetchSignatures(); // Set up realtime subscription for new signatures const channel = supabase .channel('schema-db-changes') .on( 'postgres_changes', { event: 'INSERT', schema: 'public', table: 'petition_signatures' }, (payload) => { const newSignature = payload.new as Signature; setSignatures(prev => [newSignature, ...prev]); setTotalCount(prev => prev + 1); } ) .subscribe(); return () => { supabase.removeChannel(channel); }; }, []); const fetchSignatures = async () => { try { // Get total count const { count } = await supabase .from('petition_signatures') .select('*', { count: 'exact', head: true }); setTotalCount(count || 0); // Get signatures with comments const { data, error } = await supabase .from('petition_signatures') .select('*') .not('comment', 'is', null) .order('created_at', { ascending: false }); if (error) throw error; setSignatures(data || []); } catch (error) { console.error('Error fetching signatures:', error); } finally { setIsLoading(false); } }; return (
{/* Header */}
{totalCount} Signatures
{/* Content */}

Community Testimonies

Real stories from residents affected by the closure of Victoria Way Carpark

{isLoading ? (

Loading testimonies...

) : signatures.length === 0 ? (

No testimonies yet. Be the first to share your story!

) : (
{signatures.map((signature) => ( ))}
)}
{/* Footer */}
); }; export default Testimonies;