1- import { Poll } from "@/types/Poll" ;
2- import { GetAllPolls , GetPollById } from "@/services/pollServices" ;
1+ import { GetPollById } from "@/services/pollServices" ;
32import StatisticsComponent from "@/components/poll/statistics/StatisticsComponent" ;
43
54export default async function PollStatistics ( { params } : {
@@ -17,121 +16,4 @@ export default async function PollStatistics({ params }: {
1716 poll ? < StatisticsComponent poll = { poll } /> : < p > There is no poll with given id.</ p >
1817 }
1918 </ >
20- }
21-
22- // export default function PollStatistics() {
23- // const [pollData, setPollData] = useState<PollResults>();
24- // const params = useParams();
25- // const pollId = params?.pollId as string | null;
26-
27- // const { notifySuccess, notifyError } = useNotificationStore((state) => state);
28-
29- // useEffect(() => {
30- // if (pollId) {
31- // fetchPollData();
32- // }
33-
34- // const es = new EventSource(`${process.env.NEXT_PUBLIC_API_URL}/socket/create-client`);
35-
36- // es.onopen = () => {
37- // console.log("connected succesfully.");
38- // }
39-
40- // es.addEventListener("poll_results", (event) => {
41- // const poll = JSON.parse(event.data);
42- // if (poll.pollId === pollId) {
43- // setPollData(poll);
44- // }
45- // });
46-
47- // }, [pollId]);
48-
49- // const fetchPollData = async () => {
50- // try {
51- // const response = await GetResults(pollId);
52- // setPollData(response);
53- // notifySuccess("Fetched results for the given poll.");
54- // } catch (error) {
55- // if (axios.isAxiosError(error) && error.response) {
56- // const message = error.response.data;
57- // notifyError(message);
58- // return;
59- // }
60- // notifyError("Failed to fetch poll data");
61- // console.error("Failed to fetch poll data:", error);
62- // }
63- // };
64-
65- // if (!pollData) {
66- // return <p className="w-full h-[80vh] flex justify-center items-center">Loading...</p>;
67- // }
68-
69- // const COLORS = pollData ? generateColors(pollData.options.length) : [];
70-
71- // const chartData = pollData?.options?.map((option) => ({
72- // name: option.text,
73- // value: option.votes,
74- // }));
75-
76- // return (
77-
78- // <div className="w-full flex justify-center">
79- // <div className="w-fit max-w-4xl p-6 m-5 bg-white rounded-xl shadow-lg space-y-6">
80- // <div className="flex flex-row gap-6 justify-between items-center ">
81- // <div className="flex-1 flex flex-col items-start gap-3">
82- // <h1 className="mx-[10px] text-2xl font-semibold text-left text-gray-800">{pollData.title}</h1>
83- // <div className="mx-[10px] text-gray-600 flex flex-col gap-2">
84- // <p className="text-sm">
85- // Total Votes:{" "}
86- // <span className="font-medium text-black">{pollData.totalVotes}</span>
87- // </p>
88- // <p className="text-sm">
89- // Time Elapsed:{" "}
90- // <span className="font-medium text-black">{pollData.timeElapsed}</span>
91- // </p>
92- // </div>
93- // <ViewPollComponent pollId={pollData.pollId} />
94- // </div>
95-
96- // <div className="flex-1 bg-gray-50 rounded-xl p-4 shadow-inner flex justify-center items-center">
97- // <ResponsiveContainer width="90%" height={200}>
98- // <PieChart>
99- // <Pie
100- // data={chartData}
101- // dataKey="value"
102- // nameKey="name"
103- // cx="50%"
104- // cy="50%"
105- // outerRadius={50}
106- // fill="#8884d8"
107- // label
108- // >
109- // {chartData?.map((entry, index) => (
110- // <Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
111- // ))}
112- // </Pie>
113- // <Tooltip />
114- // </PieChart>
115- // </ResponsiveContainer>
116- // </div>
117-
118- // </div>
119- // <div className="bg-gray-50 p-6 rounded-xl shadow-inner">
120- // <h2 className="text-xl font-medium font-sans text-gray-800 mb-4">Options Breakdown</h2>
121- // <ul className="list-disc ml-6 space-y-3">
122- // {pollData?.options?.map((option, index) => (
123- // <li key={index} className="text-gray-700 text-sm">
124- // <span className="font-medium text-black">{option.text}</span>:{" "}
125- // {option.votes} votes
126- // <span className="text-gray-500 ml-2">
127- // ({option.percentage.toFixed(2)}%)
128- // </span>
129- // </li>
130- // ))}
131- // </ul>
132- // </div>
133- // </div>
134- // </div>
135- // );
136-
137- // }
19+ }
0 commit comments