From 727b9e5518c711976153193ccba02d4711f621b5 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Guhur Date: Thu, 16 Apr 2020 15:17:41 +0200 Subject: [PATCH] avoid code duplciation --- src/components/views/CreateElection.jsx | 139 +++++++++++++----------- 1 file changed, 76 insertions(+), 63 deletions(-) diff --git a/src/components/views/CreateElection.jsx b/src/components/views/CreateElection.jsx index e85e496..40452fe 100644 --- a/src/components/views/CreateElection.jsx +++ b/src/components/views/CreateElection.jsx @@ -13,7 +13,7 @@ import { Card, CardBody, } from 'reactstrap'; -import { withTranslation } from 'react-i18next'; +import {withTranslation} from 'react-i18next'; import {toast, ToastContainer} from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; @@ -61,6 +61,15 @@ const DragHandle = sortableHandle(({children}) => ( {children} )); +const displayClockOptions = () => + Array(24) + .fill(1) + .map((x, i) => ( + + )); + const SortableCandidate = sortableElement(({candidate, sortIndex, form, t}) => (
  • @@ -78,7 +87,7 @@ const SortableCandidate = sortableElement(({candidate, sortIndex, form, t}) => ( onKeyPress={event => form.handleKeypressOnCandidateLabel(event, sortIndex) } - placeholder={t("Candidate/proposal name...")} + placeholder={t('Candidate/proposal name...')} tabIndex={sortIndex + 1} innerRef={ref => (form.candidateInputs[sortIndex] = ref)} maxLength="250" @@ -87,14 +96,15 @@ const SortableCandidate = sortableElement(({candidate, sortIndex, form, t}) => (
    -
    {t("Delete?")}
    +
    {t('Delete?')}
    - {t("Are you sure to delete")} - {' '} + {t('Are you sure to delete')}{' '} {candidate.label !== '' ? ( "{candidate.label}" ) : ( - {t("the row")} {sortIndex + 1} + + {t('the row')} {sortIndex + 1} + )}{' '} ?
    @@ -109,7 +119,9 @@ const SortableCandidate = sortableElement(({candidate, sortIndex, form, t}) => ( - {t("Write here your question or introduce simple your election (250 characters max.)")} + {t( + 'Write here your question or introduce simple your election (250 characters max.)', + )}
    @@ -126,7 +138,7 @@ const SortableCandidatesContainer = sortableContainer(({items, form, t}) => { sortIndex={index} candidate={candidate} form={form} - t={t} + t={t} /> ))} @@ -139,7 +151,9 @@ class CreateElection extends Component { super(props); // default value : start at the last hour const now = new Date(); - const start = new Date(now.getTime() - minutes(now) - seconds(now) - ms(now)); + const start = new Date( + now.getTime() - minutes(now) - seconds(now) - ms(now), + ); const {title} = queryString.parse(this.props.location.search); this.state = { @@ -263,7 +277,7 @@ class CreateElection extends Component { handleSendWithoutCandidate = () => { const {t} = this.props; - toast.error(t("Please add at least 2 candidates."), { + toast.error(t('Please add at least 2 candidates.'), { position: toast.POSITION.TOP_CENTER, }); }; @@ -283,17 +297,17 @@ class CreateElection extends Component {
    -

    {t("Start an election")}

    +

    {t('Start an election')}


    - + - {t("Write here your question or introduce simple your election (250 characters max.)")} + {t( + 'Write here your question or introduce simple your election (250 characters max.)', + )}
    - {t("For example:")}{' '} - {t("For the role of my representative, I judge this candidate...")} + {t('For example:')}{' '} + + {t( + 'For the role of my representative, I judge this candidate...', + )} +
    - + this.addCandidate(event)}> - {t("Add a proposal")} + {t('Add a proposal')} - {t("Advanced options")} + {t('Advanced options')} @@ -358,7 +378,7 @@ class CreateElection extends Component { - + - {Array(24) - .fill(1) - .map((x, i) => ( - - ))} + {displayClockOptions()}
    - + - {Array(24) - .fill(1) - .map((x, i) => ( - - ))} + {displayClockOptions()}
    - +