From cd0fae0c2c579d7db9b12c5334d0e7868c4be5fb Mon Sep 17 00:00:00 2001 From: Clement G Date: Mon, 20 Apr 2020 18:05:54 +0200 Subject: [PATCH 1/3] feat(footer): remove an extra dash --- src/components/layouts/Footer.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/layouts/Footer.jsx b/src/components/layouts/Footer.jsx index fa95260..82098fb 100644 --- a/src/components/layouts/Footer.jsx +++ b/src/components/layouts/Footer.jsx @@ -33,7 +33,6 @@ class Footer extends Component { style={linkStyle}> {t('Who are we?')} - -
From 38b35fed4c5e39f4103966aaf2aa26fe372f7e2c Mon Sep 17 00:00:00 2001 From: Clement G Date: Mon, 20 Apr 2020 19:37:22 +0200 Subject: [PATCH 2/3] fix(sorting-grade): add a value to make sorting grade easier --- src/Util.jsx | 36 ++++++++++++++++++++++----------- src/components/views/Result.jsx | 14 +++++++------ src/components/views/Vote.jsx | 17 ++++++++-------- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/Util.jsx b/src/Util.jsx index d3f5c31..e4b800d 100644 --- a/src/Util.jsx +++ b/src/Util.jsx @@ -1,33 +1,45 @@ import i18n from './i18n.jsx'; const colors = [ - '#6f0214', - '#b20616', - '#ff5d00', - '#ffb200', - '#6bca24', - '#019812', '#015411', + '#019812', + '#6bca24', + '#ffb200', + '#ff5d00', + '#b20616', + '#6f0214', ]; const gradeNames = [ - 'To reject', - 'Insufficient', - 'Passable', - 'Fair', - 'Good', - 'Very good', 'Excellent', + 'Very good', + 'Good', + 'Fair', + 'Passable', + 'Insufficient', + 'To reject', +]; + +const gradeValues = [ + 6, + 5, + 4, + 3, + 2, + 1, + 0 ]; export const grades = gradeNames.map((name, i) => ({ label: name, color: colors[i], + value: gradeValues[i] })); export const i18nGrades = () => { return gradeNames.map((name, i) => ({ label: i18n.t(name), color: colors[i], + value: gradeValues[i] })); }; diff --git a/src/components/views/Result.jsx b/src/components/views/Result.jsx index f615225..b579564 100644 --- a/src/components/views/Result.jsx +++ b/src/components/views/Result.jsx @@ -11,7 +11,7 @@ import { CardBody, Table, } from 'reactstrap'; -import {i18nGrades} from '../../Util'; +import {grades, i18nGrades} from '../../Util'; import {AppContext} from '../../AppContext'; import {errorMessage, Error} from '../../Errors'; @@ -166,7 +166,9 @@ class Result extends Component { render() { const {errorMessage, candidates, electionGrades} = this.state; const {t} = this.props; - const grades = i18nGrades(); + const offsetGrade = grades.length-(this.state.numGrades); + const i18nGradesObject = i18nGrades(); + if (errorMessage && errorMessage !== '') { return ; @@ -207,10 +209,10 @@ class Result extends Component { - {grades[candidate.grade].label} + {i18nGradesObject.slice(0).reverse()[candidate.grade+offsetGrade].label} {/* {(100 * candidate.score).toFixed(1)}% @@ -252,7 +254,7 @@ class Result extends Component { - {gradeIds.map((id, i) => { + {gradeIds.slice(0).reverse().map((id, i) => { const value = candidate.profile[id]; if (value > 0) { let percent = @@ -359,7 +361,7 @@ class Result extends Component { return ( - {gradeIds.map((id, i) => { + {gradeIds.slice(0).reverse().map((id, i) => { const value = candidate.profile[id]; const percent = ( (value / numVotes) * diff --git a/src/components/views/Vote.jsx b/src/components/views/Vote.jsx index 30e38e5..b65810f 100644 --- a/src/components/views/Vote.jsx +++ b/src/components/views/Vote.jsx @@ -6,7 +6,7 @@ import {toast, ToastContainer} from 'react-toastify'; import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; import {faCheck} from '@fortawesome/free-solid-svg-icons'; import {resolve} from 'url'; -import {i18nGrades} from '../../Util'; +import {i18nGrades,grades} from '../../Util'; import {AppContext} from '../../AppContext'; import {errorMessage} from '../../Errors'; @@ -169,6 +169,7 @@ class Vote extends Component { render() { const {t} = this.props; const {redirectTo, candidates, electionGrades} = this.state; + const offsetGrade = grades.length-this.state.numGrades; if (redirectTo) { return ; @@ -220,7 +221,7 @@ class Vote extends Component {
{this.state.electionGrades.map((grade, gradeId) => { - console.assert(gradeId < this.state.numGrades) + console.assert(gradeId < this.state.numGrades) return (
{i + 1}