import {useState} from 'react' import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; import {faChevronLeft, faChevronRight} from '@fortawesome/free-solid-svg-icons'; import {useBallot} from '@services/BallotContext'; import CandidateCard from '@components/ballot/CandidateCard' import GradeInput from '@components/ballot/GradeInput' import {CandidatePayload} from '@services/api'; import CandidateModal from '@components/CandidateModalGet'; import {useTranslation} from 'next-i18next'; interface TitleInterface { name: string; } const TitleName = ({name}: TitleInterface) => { return (
{name}
) } const BallotMobile = ({hasVoted}) => { const {t} = useTranslation(); const [ballot, _] = useBallot(); const [offset, setOffset] = useState(0); const numGrades = ballot.election.grades.length; const [candidate, setCandidate] = useState(null); const moveRight = (right: boolean) => { if (right) setOffset(o => o - 247); else setOffset(o => o + 247); } return (
{hasVoted &&
{t("vote.already-voted")}
}
{ballot.election.candidates.map((candidate, candidateId) => { return (
{candidateId !== 0 ?
moveRight(false)} >
: null} setCandidate(candidate)} candidate={candidate} /> {candidateId !== ballot.election.candidates.length - 1 ?
moveRight(true)}>
: null}
{ballot.election.grades.sort((a, b) => b.value - a.value).map((_, gradeId) => { console.assert(gradeId < numGrades); return ( ); })}
); })} setCandidate(null)} candidate={candidate} />
) } export default BallotMobile