index.js 1.17 KB
Newer Older
zhanghaozhe committed
1 2 3
import React from "react"
import "./index.scss"
import classnames from "classnames"
zhanghaozhe committed
4

zhanghaozhe committed
5
const Navigation = ({ questions, answer, handleClick, isAnalysis }) => {
zhanghaozhe committed
6 7 8
  return (
    <div className="navigation">
      <ul>
zhanghaozhe committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
        {!!questions.length &&
          questions.map((item, index) => {
            const userSelectIndex = item.options.findIndex(
              (item) => item.user_select
            )
            const rightAnswerIndex = item.options.findIndex(
              (item) => item.is_ans
            )
            return (
              <li
                key={index}
                onClick={handleClick.bind(this, index)}
                className={classnames({
                  active: answer && answer[item.id],
                  correct: isAnalysis && userSelectIndex === rightAnswerIndex,
                  error:
                    isAnalysis &&
                    userSelectIndex >= 0 &&
                    userSelectIndex !== rightAnswerIndex,
                  unselect: isAnalysis && userSelectIndex < 0,
                })}
              >
                {index + 1}
              </li>
            )
          })}
zhanghaozhe committed
35 36
      </ul>
    </div>
zhanghaozhe committed
37 38
  )
}
zhanghaozhe committed
39

zhanghaozhe committed
40
export default Navigation