// VotingPage.js import React from "react"; import { Bar } from "react-chartjs-2"; import { Chart as ChartJS, BarElement, CategoryScale, LinearScale } from "chart.js"; import { useQuery } from "react-query"; import { useParams } from "react-router-dom"; import getPollData from "../services/getPollData"; import ErrorFallback from "../components/Errors/ErrorFallback"; ChartJS.register(BarElement, CategoryScale, LinearScale); function VotingPage() { const { pollId } = useParams(); const { data: poll, isLoading, isError, refetch } = useQuery(["poll", pollId], () => getPollData(pollId), { cacheTime : 10*100*60, // 10 minutes staleTime : 20*100*60, // 20 minutes }); // Dummy chart data for visualization const chartData = { labels: poll?.data?.pollData?.options.map(option => option.name), datasets: [ { label: "Votes", data: poll?.data?.pollData?.options.map(option => option.voteCount), backgroundColor: ["#3B82F6", "#EF4444", "#10B981", "#F59E0B"], borderWidth: 1, }, ], }; if (isLoading) { return
; } if (isError){ return