Skip to content

Commit

Permalink
delete the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
georgi-s committed May 27, 2024
1 parent fb2092b commit 871b654
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 130 deletions.
52 changes: 1 addition & 51 deletions src/components/forms/lists/answerList.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,3 @@
// import * as React from "react";
// import { Button } from "@/components/ui/button";
// import {
// Drawer,
// DrawerClose,
// DrawerContent,
// DrawerDescription,
// DrawerFooter,
// DrawerHeader,
// DrawerTitle,
// DrawerTrigger,
// } from "@/components/ui/drawer";
// import BarChart from "@/components/ui/barchart"; // Importiere die BarChart-Komponente

// export default function ListAnswer({ questionId }: { questionId: string }) {
// console.log("Question ID:", questionId);
// return (
// <Drawer>
// <DrawerTrigger asChild>
// <Button variant="outline">View Data</Button>
// </DrawerTrigger>
// <DrawerContent>
// <div className="mx-auto w-full max-w-sm">
// <DrawerHeader>
// <DrawerTitle></DrawerTitle>
// <DrawerDescription></DrawerDescription>
// </DrawerHeader>
// <div className="p-4 pb-0">
// <div className="flex items-center justify-center space-x-2">
// <div className="flex-1 text-center">
// <BarChart questionId={questionId} />
// <div className="text-7xl font-bold tracking-tighter"></div>
// <div className="text-[0.70rem] uppercase text-muted-foreground"></div>
// </div>
// </div>
// <div className="mt-3 h-[120px]"></div>
// </div>
// <DrawerFooter>
// <Button>Submit</Button>
// <DrawerClose asChild>
// <Button variant="outline">Cancel</Button>
// </DrawerClose>
// </DrawerFooter>
// </div>
// </DrawerContent>
// </Drawer>
// );
// }
"use client";
import React from "react";
import { Button } from "@/components/ui/button";
Expand All @@ -59,11 +11,9 @@ import {
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer";
import BarChart from "@/components/ui/barchart"; // Importiere die BarChart-Komponente
import BarChart from "@/components/ui/barchart";

export default function ListAnswer({ questionId }: { questionId: string }) {
console.log("Question ID in ListAnswer:", questionId); // Debugging

return (
<Drawer>
<DrawerTrigger asChild>
Expand Down
79 changes: 0 additions & 79 deletions src/components/ui/barchart.tsx
Original file line number Diff line number Diff line change
@@ -1,79 +1,3 @@
// "use client";
// import { useRef, useEffect, useState } from "react";
// import { Chart, ChartConfiguration } from "chart.js/auto";
// import { getAnswers } from "@/lib/api/answerClient";
// import { Answer } from "@prisma/client";

// export default function BarChart({ questionId }: { questionId: string }) {
// const chartRef = useRef<HTMLCanvasElement>(null);
// const [chartInstance, setChartInstance] = useState<Chart | null>(null);
// const [answers, setAnswers] = useState<Answer[]>([]);

// useEffect(() => {
// async function fetchAnswers() {
// try {
// const data = await getAnswers(questionId);
// console.log("Fetched data:", data);
// setAnswers(data);
// } catch (error) {
// console.error("Error fetching answers:", error);
// }
// }
// fetchAnswers();
// }, [questionId]);

// useEffect(() => {
// if (chartRef.current && answers.length > 0) {
// const context = chartRef.current.getContext("2d");
// if (context) {
// if (chartInstance) {
// chartInstance.destroy();
// }

// const valueCounts: Record<number, number> = {};
// answers.forEach((answer) => {
// valueCounts[answer.value] = (valueCounts[answer.value] || 0) + 1;
// });

// const labels: string[] = Object.keys(valueCounts)
// .map(Number)
// .map(String);
// const data: number[] = Object.values(valueCounts);

// const config: ChartConfiguration<"bar", number[], unknown> = {
// type: "bar",
// data: {
// labels,
// datasets: [
// {
// label: "Anzahl der Antworten",
// data,
// backgroundColor: "rgba(75, 192, 192, 0.2)",
// borderColor: "rgba(75, 192, 192, 1)",
// borderWidth: 1,
// },
// ],
// },
// options: {
// scales: {
// y: {
// beginAtZero: true,
// },
// },
// },
// };

// const newChart = new Chart(context, config);
// setChartInstance(newChart);
// }
// }
// // eslint-disable-next-line react-hooks/exhaustive-deps
// }, [answers]);

// return (
// <canvas ref={chartRef} style={{ width: "100%", height: "400px" }}></canvas>
// );
// }
"use client";
import { useRef, useEffect, useState } from "react";
import { Chart, ChartConfiguration } from "chart.js/auto";
Expand All @@ -89,7 +13,6 @@ export default function BarChart({ questionId }: { questionId: string }) {
async function fetchAnswers() {
try {
const data = await getAnswers(questionId);
console.log("Fetched data:", data); // Debugging
setAnswers(data);
} catch (error) {
console.error("Error fetching answers:", error);
Expand Down Expand Up @@ -139,8 +62,6 @@ export default function BarChart({ questionId }: { questionId: string }) {
},
};

console.log("Creating new chart with config:", config); // Debugging

const newChart = new Chart(context, config);
setChartInstance(newChart);
}
Expand Down

0 comments on commit 871b654

Please sign in to comment.