From 9454f90b343b36313ef540a81711d8f8084c596e Mon Sep 17 00:00:00 2001 From: Pierre-Louis Guhur Date: Mon, 28 Nov 2022 21:57:16 +0100 Subject: [PATCH] feat: ballot --- components/admin/CandidateModalDel.tsx | 1 + components/ballot/BallotDesktop.tsx | 8 +-- components/ballot/BallotMobile.tsx | 83 ++++++++++++++++++-------- components/ballot/CandidateCard.tsx | 2 +- components/ballot/GradeInput.tsx | 32 +++++++++- pages/vote/[pid]/[[...tid]].tsx | 4 +- services/ElectionContext.tsx | 17 +++++- styles/scss/_vote.scss | 8 +++ 8 files changed, 118 insertions(+), 37 deletions(-) diff --git a/components/admin/CandidateModalDel.tsx b/components/admin/CandidateModalDel.tsx index a287a81..478d99b 100644 --- a/components/admin/CandidateModalDel.tsx +++ b/components/admin/CandidateModalDel.tsx @@ -23,6 +23,7 @@ const CandidateModal = ({isOpen, position, toggle}) => { const removeCandidate = () => { dispatch({type: 'candidate-rm', position: position}); + toggle(); }; return ( diff --git a/components/ballot/BallotDesktop.tsx b/components/ballot/BallotDesktop.tsx index 2cb0694..9d3e0b1 100644 --- a/components/ballot/BallotDesktop.tsx +++ b/components/ballot/BallotDesktop.tsx @@ -38,13 +38,13 @@ const BallotDesktop = () => { }; return ( -
+
-
+

{ballot.election.name}

{ballot.election.candidates.map((candidate, candidateId) => { return ( -
+
{ballot.election.grades.map((_, gradeId) => { @@ -70,7 +70,7 @@ const BallotDesktop = () => { {t('vote.submit')} -
+
) } diff --git a/components/ballot/BallotMobile.tsx b/components/ballot/BallotMobile.tsx index 306c884..d93d6f7 100644 --- a/components/ballot/BallotMobile.tsx +++ b/components/ballot/BallotMobile.tsx @@ -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 ( +
+ {name} +
+ ) +} + 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 ( -
-
-

{ballot.election.name}

+
+ + +
{ballot.election.candidates.map((candidate, candidateId) => { return ( -
- -
+
+
+ {candidateId !== 0 ? +
moveRight(false)} + > + +
: null} + + + {candidateId !== ballot.election.candidates.length - 1 ? +
moveRight(true)}>
: null} +
+
{ballot.election.grades.map((_, gradeId) => { console.assert(gradeId < numGrades); return ( - + ); })}
); })} - - -
-
+ + + +
) } diff --git a/components/ballot/CandidateCard.tsx b/components/ballot/CandidateCard.tsx index 9ac9463..e265ddb 100644 --- a/components/ballot/CandidateCard.tsx +++ b/components/ballot/CandidateCard.tsx @@ -8,7 +8,7 @@ interface CandidateCardInterface { } const CandidateCard = ({candidate}: CandidateCardInterface) => { const {t} = useTranslation(); - return (
+ return (
{ + return (<> + {active ? +
+ +
: null} +
+ {name} +
+ ) +} interface GradeInputInterface { gradeId: number; candidateId: number; @@ -20,14 +34,26 @@ const GradeInput = ({gradeId, candidateId}: GradeInputInterface) => { const active = ballot.votes.some(b => b.gradeId === gradeId && b.candidateId === candidateId) const color = active ? getGradeColor(gradeId, numGrades) : '#C3BFD8'; - return ( + return (<>
- {grade.name} + +
+
+
+ ) } diff --git a/pages/vote/[pid]/[[...tid]].tsx b/pages/vote/[pid]/[[...tid]].tsx index a9701a7..dd0be68 100644 --- a/pages/vote/[pid]/[[...tid]].tsx +++ b/pages/vote/[pid]/[[...tid]].tsx @@ -52,7 +52,7 @@ const GoToBallotConfirm = ({electionId, token}) => { - +