RRadio.tsx 910 Bytes
Newer Older
1
2
import React, { useState } from "react";
import { Pie } from "../charts/pies/Pie";
Yoon, Daeki's avatar
Yoon, Daeki committed
3
import { IQuestionData } from "../types";
4
import chartImg1 from "../icons/chartImg1.png";
5
6

type Props = {
Yoon, Daeki's avatar
Yoon, Daeki committed
7
  question: IQuestionData;
8
9
};

10
export const RRadio = ({ question }: Props) => {
11
12
  const [dataset, setDataset] = useState([50, 30, 12, 5, 3]);

13
14
15
16
  const result = question.answers.reduce((acc: any, cur: any) => {
    acc[cur] = (acc[cur] || 0) + 1;
    return acc;
  }, {});
Yoon, Daeki's avatar
Yoon, Daeki committed
17
  // console.log(result);
18
19
20

  return (
    <div className="m-5">
21
      <img src={chartImg1} />
Yoon, Daeki's avatar
Yoon, Daeki committed
22
23
      {question.content.choices.map((choice: any, index: number) => (
        <div key={index} className="">
24
25
26
27
28
29
          <span className="font-bold">{choice.text}</span>
          <span className="ml-3">
            - {result[choice.text] ? result[choice.text] : 0}
          </span>
        </div>
      ))}
30
      <Pie data={dataset} />
31
32
33
    </div>
  );
};