|
|
|
@ -1,20 +1,32 @@
|
|
|
|
|
import {MouseEvent} from 'react'
|
|
|
|
|
import {MouseEvent, useState} from 'react'
|
|
|
|
|
import {useRouter} from 'next/router';
|
|
|
|
|
import {useTranslation} from 'next-i18next';
|
|
|
|
|
import Button from '@components/Button';
|
|
|
|
|
import {Col, Row, Container} from 'reactstrap';
|
|
|
|
|
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
|
|
|
|
|
import {faCalendarDays, faCheck} from '@fortawesome/free-solid-svg-icons';
|
|
|
|
|
import {faCheck, faChevronLeft, faChevronRight} from '@fortawesome/free-solid-svg-icons';
|
|
|
|
|
import {useBallot, BallotTypes, BallotProvider} from '@services/BallotContext';
|
|
|
|
|
import CandidateCard from '@components/ballot/CandidateCard'
|
|
|
|
|
import TitleBar from '@components/ballot/TitleBar'
|
|
|
|
|
import GradeInput from '@components/ballot/GradeInput'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface TitleInterface {
|
|
|
|
|
name: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TitleName = ({name}: TitleInterface) => {
|
|
|
|
|
return (
|
|
|
|
|
<div className="fw-bold text-white w-75 p-4">
|
|
|
|
|
{name}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const BallotMobile = () => {
|
|
|
|
|
const {t} = useTranslation();
|
|
|
|
|
|
|
|
|
|
const [ballot, dispatch] = useBallot();
|
|
|
|
|
const [ballot, _] = useBallot();
|
|
|
|
|
const [offset, setOffset] = useState(0);
|
|
|
|
|
|
|
|
|
|
const numGrades = ballot.election.grades.length;
|
|
|
|
|
const disabled = ballot.votes.length !== ballot.election.candidates.length;
|
|
|
|
@ -25,40 +37,61 @@ const BallotMobile = () => {
|
|
|
|
|
router.push(`/confirm/${ballot.election.id}`);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const moveRight = (right: boolean) => {
|
|
|
|
|
if (right) setOffset(o => o - 247);
|
|
|
|
|
else setOffset(o => o + 247);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="w-100 h-100 display-block display-lg-none">
|
|
|
|
|
<div className="w-100 h-100 d-flex flex-column justify-content-center align-items-center">
|
|
|
|
|
<h1 className="mb-5">{ballot.election.name}</h1>
|
|
|
|
|
<div className="w-100 h-100 d-block d-lg-none">
|
|
|
|
|
|
|
|
|
|
<TitleName name={ballot.election.name} />
|
|
|
|
|
<div className="w-100 d-flex">
|
|
|
|
|
{ballot.election.candidates.map((candidate, candidateId) => {
|
|
|
|
|
return (
|
|
|
|
|
<div key={candidateId} className="bg-white justify-content-between d-flex my-4 py-2 px-3">
|
|
|
|
|
<CandidateCard candidate={candidate} />
|
|
|
|
|
<div className="d-flex">
|
|
|
|
|
<div key={candidateId} className="bg-white flex-column d-flex my-4 mx-2 py-4 px-3 candidate-vote" style={{"left": offset === 0 ? 0 : offset + 30}}>
|
|
|
|
|
<div className="d-flex align-items-center mb-1">
|
|
|
|
|
{candidateId !== 0 ?
|
|
|
|
|
<div className="me-2"
|
|
|
|
|
onClick={() => moveRight(false)}
|
|
|
|
|
>
|
|
|
|
|
<FontAwesomeIcon color="#0A004C" icon={faChevronLeft} />
|
|
|
|
|
</div> : null}
|
|
|
|
|
<CandidateCard candidate={candidate} />
|
|
|
|
|
|
|
|
|
|
{candidateId !== ballot.election.candidates.length - 1 ?
|
|
|
|
|
<div className="ms-2" onClick={() => moveRight(true)}><FontAwesomeIcon color="#0A004C" icon={faChevronRight} /></div> : null}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="d-flex mt-2 flex-column">
|
|
|
|
|
{ballot.election.grades.map((_, gradeId) => {
|
|
|
|
|
console.assert(gradeId < numGrades);
|
|
|
|
|
return (
|
|
|
|
|
<GradeInput key={gradeId} gradeId={gradeId} candidateId={candidateId} />
|
|
|
|
|
<GradeInput
|
|
|
|
|
key={gradeId}
|
|
|
|
|
gradeId={gradeId}
|
|
|
|
|
candidateId={candidateId}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
<Container className="my-5 d-md-flex d-grid justify-content-md-center">
|
|
|
|
|
<Button
|
|
|
|
|
outline={true}
|
|
|
|
|
color="secondary"
|
|
|
|
|
className="bg-blue"
|
|
|
|
|
onClick={handleSubmit}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
icon={faCheck}
|
|
|
|
|
position="left"
|
|
|
|
|
>
|
|
|
|
|
{t('vote.submit')}
|
|
|
|
|
</Button>
|
|
|
|
|
</Container>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<Container className="my-5 d-md-flex d-grid justify-content-md-center">
|
|
|
|
|
<Button
|
|
|
|
|
outline={true}
|
|
|
|
|
color="secondary"
|
|
|
|
|
className="bg-blue"
|
|
|
|
|
onClick={handleSubmit}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
icon={faCheck}
|
|
|
|
|
position="left"
|
|
|
|
|
>
|
|
|
|
|
{t('vote.submit')}
|
|
|
|
|
</Button>
|
|
|
|
|
</Container>
|
|
|
|
|
</div >
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|