index.js 1 KB
Newer Older
zhanghaozhe committed
1 2 3 4 5 6 7 8 9 10
import React from 'react';
import './index.scss'
import classnames from 'classnames'

const Navigation = ({questions, answer, handleClick, isAnalysis}) => {
  return (
    <div className="navigation">
      <ul>
        {
          !!questions.length && questions.map((item, index) => {
zhanghaozhe committed
11 12
            const userSelectIndex = item.options.findIndex(item => item.user_select)
            const rightAnswerIndex = item.options.findIndex(item => item.is_ans)
zhanghaozhe committed
13 14 15
            return <li key={index} onClick={handleClick.bind(this, index)}
                       className={classnames({
                         active: answer && answer[item.id],
zhanghaozhe committed
16 17 18
                         correct: isAnalysis && userSelectIndex === rightAnswerIndex,
                         error: isAnalysis && userSelectIndex >= 0 && userSelectIndex !== rightAnswerIndex,
                         unselect: isAnalysis && userSelectIndex < 0,
zhanghaozhe committed
19 20 21 22 23 24 25 26 27
                       })}>{index + 1}</li>
          })
        }
      </ul>
    </div>
  );
};

export default Navigation;