-
- {t('Keep these links carefully')}
-
+
+ {t("Keep these links carefully")}
@@ -99,10 +94,11 @@ class CreateSuccess extends Component {
+ to={"/vote/" + this.props.match.params.slug}
+ className="btn btn-success"
+ >
- {t('Participate now!')}
+ {t("Participate now!")}
diff --git a/src/components/views/Home.jsx b/src/components/views/Home.jsx
index 7b84127..a70ecdd 100644
--- a/src/components/views/Home.jsx
+++ b/src/components/views/Home.jsx
@@ -1,14 +1,12 @@
import React, { Component } from "react";
-import { withTranslation } from 'react-i18next';
+import { withTranslation } from "react-i18next";
import { Container, Row, Col, Button, Input } from "reactstrap";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faRocket } from "@fortawesome/free-solid-svg-icons";
import { Redirect } from "react-router-dom";
import logoLine from "../../logos/logo-line-white.svg";
-
class Home extends Component {
-
constructor(props) {
super(props);
this.state = {
@@ -29,7 +27,7 @@ class Home extends Component {
};
render() {
- const {t} = this.props;
+ const { t } = this.props;
const redirect = this.state.redirect;
if (redirect) {
@@ -53,7 +51,9 @@ class Home extends Component {
- {t("Simple and free: organize an election with Majority Judgment.")}
+ {t(
+ "Simple and free: organize an election with Majority Judgment."
+ )}
@@ -77,7 +77,7 @@ class Home extends Component {
className="btn btn-block btn-secondary mt-2"
>
- {t("Start")}
+ {t("Start")}
diff --git a/src/components/views/Result.jsx b/src/components/views/Result.jsx
index 2bcd73a..9fb1e63 100644
--- a/src/components/views/Result.jsx
+++ b/src/components/views/Result.jsx
@@ -1,6 +1,6 @@
-import React, {Component} from 'react';
-import {withTranslation} from 'react-i18next';
-import {resolve} from 'url';
+import React, { Component } from "react";
+import { withTranslation } from "react-i18next";
+import { resolve } from "url";
import {
Container,
Row,
@@ -9,12 +9,11 @@ import {
Card,
CardHeader,
CardBody,
- Table,
-} from 'reactstrap';
-import {i18nGrades} from '../../Util';
-import {AppContext} from '../../AppContext';
-import {errorMessage, Error} from '../../Errors';
-
+ Table
+} from "reactstrap";
+import { i18nGrades } from "../../Util";
+import { AppContext } from "../../AppContext";
+import { errorMessage, Error } from "../../Errors";
class Result extends Component {
static contextType = AppContext;
@@ -34,7 +33,7 @@ class Result extends Component {
collapseGraphics: false,
collapseProfiles: false,
electionGrades: i18nGrades(),
- errorMessage: '',
+ errorMessage: ""
};
}
@@ -42,7 +41,7 @@ class Result extends Component {
if (!response.ok) {
response.json().then(response => {
this.setState(state => ({
- errorMessage: errorMessage(response, this.props.t),
+ errorMessage: errorMessage(response, this.props.t)
}));
});
throw Error(response);
@@ -55,22 +54,22 @@ class Result extends Component {
id: c.id,
name: c.name,
profile: c.profile,
- grade: c.grade,
+ grade: c.grade
}));
- this.setState(state => ({candidates: candidates}));
+ this.setState(state => ({ candidates: candidates }));
return response;
};
detailsToState = response => {
const numGrades = response.num_grades;
const colSizeGradeLg = Math.floor(
- (12 - this.state.colSizeCandidateLg) / numGrades,
+ (12 - this.state.colSizeCandidateLg) / numGrades
);
const colSizeGradeMd = Math.floor(
- (12 - this.state.colSizeCandidateMd) / numGrades,
+ (12 - this.state.colSizeCandidateMd) / numGrades
);
const colSizeGradeXs = Math.floor(
- (12 - this.state.colSizeCandidateXs) / numGrades,
+ (12 - this.state.colSizeCandidateXs) / numGrades
);
this.setState(state => ({
title: response.title,
@@ -90,7 +89,7 @@ class Result extends Component {
12 - colSizeGradeXs * numGrades > 0
? 12 - colSizeGradeXs * numGrades
: 12,
- electionGrades: i18nGrades().slice(0, numGrades),
+ electionGrades: i18nGrades().slice(0, numGrades)
}));
return response;
};
@@ -98,38 +97,38 @@ class Result extends Component {
componentDidMount() {
// get details of the election
const electionSlug = this.props.match.params.slug;
- if (electionSlug === 'dev') {
+ if (electionSlug === "dev") {
const dataTest = [
{
- name: 'BB',
+ name: "BB",
id: 1,
score: 1.0,
profile: [1, 1, 0, 0, 0, 0, 0],
- grade: 1,
+ grade: 1
},
{
- name: 'CC',
+ name: "CC",
id: 2,
score: 1.0,
profile: [0, 0, 2, 0, 0, 0, 0],
- grade: 2,
+ grade: 2
},
{
- name: 'AA',
+ name: "AA",
id: 0,
score: 1.0,
profile: [1, 1, 0, 0, 0, 0, 0],
- grade: 1,
- },
+ grade: 1
+ }
];
- this.setState({candidates: dataTest});
+ this.setState({ candidates: dataTest });
} else {
const detailsEndpoint = resolve(
this.context.urlServer,
this.context.routesServer.getElection.replace(
- new RegExp(':slug', 'g'),
- electionSlug,
- ),
+ new RegExp(":slug", "g"),
+ electionSlug
+ )
);
fetch(detailsEndpoint)
@@ -142,9 +141,9 @@ class Result extends Component {
const resultsEndpoint = resolve(
this.context.urlServer,
this.context.routesServer.getResultsElection.replace(
- new RegExp(':slug', 'g'),
- electionSlug,
- ),
+ new RegExp(":slug", "g"),
+ electionSlug
+ )
);
fetch(resultsEndpoint)
@@ -156,21 +155,20 @@ class Result extends Component {
}
toggleGraphics = () => {
- this.setState(state => ({collapseGraphics: !state.collapseGraphics}));
+ this.setState(state => ({ collapseGraphics: !state.collapseGraphics }));
};
toggleProfiles = () => {
- this.setState(state => ({collapseProfiles: !state.collapseProfiles}));
+ this.setState(state => ({ collapseProfiles: !state.collapseProfiles }));
};
render() {
- const {errorMessage, candidates, electionGrades} = this.state;
- const {t} = this.props;
+ const { errorMessage, candidates, electionGrades } = this.state;
+ const { t } = this.props;
const i18nGradesObject = i18nGrades();
- const offsetGrade = i18nGradesObject.length-(this.state.numGrades);
-
+ const offsetGrade = i18nGradesObject.length - this.state.numGrades;
- if (errorMessage && errorMessage !== '') {
+ if (errorMessage && errorMessage !== "") {
return ;
}
@@ -192,26 +190,29 @@ class Result extends Component {
- {t('Results of the election:')}
+ {t("Results of the election:")}
- {t('Number of votes:')}
- {' ' + numVotes}
+ {t("Number of votes:")}
+ {" " + numVotes}
{candidates.map((candidate, i) => {
- const gradeValue=candidate.grade+offsetGrade;
+ const gradeValue = candidate.grade + offsetGrade;
return (
-
{candidate.name}
+ backgroundColor: electionGrades.slice(0).reverse()[
+ candidate.grade
+ ].color,
+ color: "#fff"
+ }}
+ >
{i18nGradesObject.slice(0).reverse()[gradeValue].label}
{/*
@@ -230,10 +231,11 @@ class Result extends Component {
- {t('Graph')}
+ "m-0 panel-title " +
+ (this.state.collapseGraphics ? "collapsed" : "")
+ }
+ >
+ {t("Graph")}
@@ -241,42 +243,46 @@ class Result extends Component {
-
+
{candidates.map((candidate, i) => {
return (
- {i + 1} |
+ {i + 1} |
{/*candidate.label*/}
-
+
- {gradeIds.slice(0).reverse().map((id, i) => {
- const value = candidate.profile[id];
- if (value > 0) {
- let percent =
- (value * 100) / numVotes + '%';
- if (i === 0) {
- percent = 'auto';
+ {gradeIds
+ .slice(0)
+ .reverse()
+ .map((id, i) => {
+ const value = candidate.profile[id];
+ if (value > 0) {
+ let percent =
+ (value * 100) / numVotes + "%";
+ if (i === 0) {
+ percent = "auto";
+ }
+ return (
+
+
+ |
+ );
+ } else {
+ return null;
}
- return (
-
-
- |
- );
- } else {
- return null;
- }
- })}
+ })}
@@ -292,7 +298,7 @@ class Result extends Component {
{candidates.map((candidate, i) => {
return (
- {i > 0 ? ', ' : ''}
+ {i > 0 ? ", " : ""}
{i + 1}: {candidate.name}
);
@@ -308,8 +314,9 @@ class Result extends Component {
className="badge badge-light mr-2 mt-2"
style={{
backgroundColor: grade.color,
- color: '#fff',
- }}>
+ color: "#fff"
+ }}
+ >
{grade.label}
);
@@ -327,10 +334,11 @@ class Result extends Component {
- {t('Preference profile')}
+ "m-0 panel-title " +
+ (this.state.collapseProfiles ? "collapsed" : "")
+ }
+ >
+ {t("Preference profile")}
@@ -347,9 +355,10 @@ class Result extends Component {
className="badge badge-light"
style={{
backgroundColor: grade.color,
- color: '#fff',
- }}>
- {grade.label}{' '}
+ color: "#fff"
+ }}
+ >
+ {grade.label}{" "}
);
@@ -361,14 +370,17 @@ class Result extends Component {
return (
{i + 1} |
- {gradeIds.slice(0).reverse().map((id, i) => {
- const value = candidate.profile[id];
- const percent = (
- (value / numVotes) *
- 100
- ).toFixed(1);
- return {percent} % | ;
- })}
+ {gradeIds
+ .slice(0)
+ .reverse()
+ .map((id, i) => {
+ const value = candidate.profile[id];
+ const percent = (
+ (value / numVotes) *
+ 100
+ ).toFixed(1);
+ return {percent} % | ;
+ })}
);
})}
@@ -379,7 +391,7 @@ class Result extends Component {
{candidates.map((candidate, i) => {
return (
- {i > 0 ? ', ' : ''}
+ {i > 0 ? ", " : ""}
{i + 1}: {candidate.name}
);
diff --git a/src/components/views/UnknownElection.jsx b/src/components/views/UnknownElection.jsx
index cf2e35c..65b2423 100644
--- a/src/components/views/UnknownElection.jsx
+++ b/src/components/views/UnknownElection.jsx
@@ -13,7 +13,7 @@ class UnknownElection extends Component {
}
render() {
- const {t} = this.props;
+ const { t } = this.props;
return (
@@ -23,14 +23,18 @@ class UnknownElection extends Component {
- {t("Oops! This election does not exist or it is not available anymore.")}
+
+ {t(
+ "Oops! This election does not exist or it is not available anymore."
+ )}
+
{t("You can start another election.")}
- {t("Go back to homepage")}
+ {t("Go back to homepage")}
diff --git a/src/components/views/Vote.jsx b/src/components/views/Vote.jsx
index 238859e..12503e1 100644
--- a/src/components/views/Vote.jsx
+++ b/src/components/views/Vote.jsx
@@ -1,14 +1,14 @@
-import React, {Component} from 'react';
-import {Redirect} from 'react-router-dom';
-import {withTranslation} from 'react-i18next';
-import {Button, Col, Container, Row} from 'reactstrap';
-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 {AppContext} from '../../AppContext';
-import {errorMessage} from '../../Errors';
+import React, { Component } from "react";
+import { Redirect } from "react-router-dom";
+import { withTranslation } from "react-i18next";
+import { Button, Col, Container, Row } from "reactstrap";
+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 { AppContext } from "../../AppContext";
+import { errorMessage } from "../../Errors";
const shuffle = array => array.sort(() => Math.random() - 0.5);
@@ -29,7 +29,7 @@ class Vote extends Component {
colSizeGradeXs: 1,
redirectTo: null,
electionGrades: i18nGrades(),
- errorMsg: "",
+ errorMsg: ""
};
}
@@ -37,9 +37,9 @@ class Vote extends Component {
if (!response.ok) {
response.json().then(response => {
console.log(response);
- const {t} = this.props;
+ const { t } = this.props;
this.setState(state => ({
- errorMsg: errorMessage(response, t)
+ errorMsg: errorMessage(response, t)
}));
});
throw Error(response);
@@ -51,18 +51,18 @@ class Vote extends Component {
const numGrades = response.num_grades;
const candidates = response.candidates.map((c, i) => ({
id: i,
- label: c,
+ label: c
}));
shuffle(candidates);
const colSizeGradeLg = Math.floor(
- (12 - this.state.colSizeCandidateLg) / numGrades,
+ (12 - this.state.colSizeCandidateLg) / numGrades
);
const colSizeGradeMd = Math.floor(
- (12 - this.state.colSizeCandidateMd) / numGrades,
+ (12 - this.state.colSizeCandidateMd) / numGrades
);
const colSizeGradeXs = Math.floor(
- (12 - this.state.colSizeCandidateXs) / numGrades,
+ (12 - this.state.colSizeCandidateXs) / numGrades
);
this.setState(state => ({
@@ -83,7 +83,7 @@ class Vote extends Component {
colSizeCandidateXs:
12 - colSizeGradeXs * numGrades > 0
? 12 - colSizeGradeXs * numGrades
- : 12,
+ : 12
}));
return response;
};
@@ -94,9 +94,9 @@ class Vote extends Component {
const detailsEndpoint = resolve(
this.context.urlServer,
this.context.routesServer.getElection.replace(
- new RegExp(':slug', 'g'),
- electionSlug,
- ),
+ new RegExp(":slug", "g"),
+ electionSlug
+ )
);
fetch(detailsEndpoint)
.then(this.handleErrors)
@@ -107,33 +107,33 @@ class Vote extends Component {
handleGradeClick = event => {
let data = {
- id: parseInt(event.currentTarget.getAttribute('data-id')),
- value: parseInt(event.currentTarget.value),
+ id: parseInt(event.currentTarget.getAttribute("data-id")),
+ value: parseInt(event.currentTarget.value)
};
//remove candidate
let ratedCandidates = this.state.ratedCandidates.filter(
- ratedCandidate => ratedCandidate.id !== data.id,
+ ratedCandidate => ratedCandidate.id !== data.id
);
ratedCandidates.push(data);
- this.setState({ratedCandidates});
+ this.setState({ ratedCandidates });
};
handleSubmitWithoutAllRate = () => {
- const {t} = this.props;
- toast.error(t('You have to judge every candidate/proposal!'), {
- position: toast.POSITION.TOP_CENTER,
+ const { t } = this.props;
+ toast.error(t("You have to judge every candidate/proposal!"), {
+ position: toast.POSITION.TOP_CENTER
});
};
handleSubmit = event => {
event.preventDefault();
- const {ratedCandidates} = this.state;
+ const { ratedCandidates } = this.state;
const electionSlug = this.props.match.params.slug;
const token = this.props.location.search.substr(7);
const endpoint = resolve(
this.context.urlServer,
- this.context.routesServer.voteElection,
+ this.context.routesServer.voteElection
);
const gradesById = {};
@@ -147,29 +147,29 @@ class Vote extends Component {
const payload = {
election: electionSlug,
- grades_by_candidate: gradesByCandidate,
+ grades_by_candidate: gradesByCandidate
};
- if (token !== '') {
- payload['token'] = token;
+ if (token !== "") {
+ payload["token"] = token;
}
fetch(endpoint, {
- method: 'POST',
- headers: {'Content-Type': 'application/json'},
- body: JSON.stringify(payload),
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify(payload)
})
.then(this.handleErrors)
.then(result =>
- this.setState({redirectTo: '/vote-success/' + electionSlug}),
+ this.setState({ redirectTo: "/vote-success/" + electionSlug })
)
.catch(error => error);
};
render() {
- const {t} = this.props;
- const {candidates, errorMsg, redirectTo} = this.state;
+ const { t } = this.props;
+ const { candidates, errorMsg, redirectTo } = this.state;
const grades = i18nGrades();
- const offsetGrade = grades.length-this.state.numGrades;
+ const offsetGrade = grades.length - this.state.numGrades;
const electionGrades = grades.slice(0, this.state.numGrades);
if (redirectTo) {
@@ -177,15 +177,15 @@ class Vote extends Component {
}
if (errorMsg !== "") {
- return(
-
+ return (
+
{errorMsg}
-
- );
+
+ );
}
return (
@@ -201,7 +201,8 @@ class Vote extends Component {
+ lg={this.state.colSizeCandidateLg}
+ >
{electionGrades.map((grade, gradeId) => {
@@ -212,10 +213,12 @@ class Vote extends Component {
lg={this.state.colSizeGradeLg}
key={gradeId}
className="text-center p-0"
- style={{lineHeight: 2}}>
+ style={{ lineHeight: 2 }}
+ >
+ style={{ backgroundColor: grade.color, color: "#fff" }}
+ >
{grade.label}
@@ -229,81 +232,95 @@ class Vote extends Component {
+ lg={this.state.colSizeCandidateLg}
+ >
{candidate.label}
{electionGrades.map((grade, gradeId) => {
- console.assert(gradeId < this.state.numGrades)
- const gradeValue = grade.value-offsetGrade;
+ console.assert(gradeId < this.state.numGrades);
+ const gradeValue = grade.value - offsetGrade;
return (
+ className="text-lg-center"
+ >
-
- )
+ );
})}
);
@@ -316,14 +333,15 @@ class Vote extends Component {
) : (
)}
diff --git a/src/components/views/VoteSuccess.jsx b/src/components/views/VoteSuccess.jsx
index beeedb6..be70f3f 100644
--- a/src/components/views/VoteSuccess.jsx
+++ b/src/components/views/VoteSuccess.jsx
@@ -1,6 +1,6 @@
import React, { Component } from "react";
import { Col, Container, Row } from "reactstrap";
-import {withTranslation} from 'react-i18next';
+import { withTranslation } from "react-i18next";
import logoLine from "../../logos/logo-line-white.svg";
import { Link } from "react-router-dom";
import { AppContext } from "../../AppContext";
@@ -9,7 +9,7 @@ import Paypal from "../banner/Paypal";
class VoteSuccess extends Component {
static contextType = AppContext;
render() {
- const {t} = this.props;
+ const { t } = this.props;
return (
@@ -21,16 +21,16 @@ class VoteSuccess extends Component {
{t("Your participation was recorded with success!")}
{t("Thanks for your participation.")}
-
+
- {t("Go back to homepage")}
+ {t("Go back to homepage")}
diff --git a/src/components/wait/index.jsx b/src/components/wait/index.jsx
index da53765..9765a71 100644
--- a/src/components/wait/index.jsx
+++ b/src/components/wait/index.jsx
@@ -1,9 +1,8 @@
-import React from 'react';
-import Loader from '../loader';
+import React from "react";
+import Loader from "../loader";
const Wait = () => {
-return ();
+ return ;
};
-
export default Wait;
diff --git a/src/i18n.jsx b/src/i18n.jsx
index 2272b52..12f099c 100644
--- a/src/i18n.jsx
+++ b/src/i18n.jsx
@@ -1,29 +1,28 @@
-import i18n from 'i18next';
-import XHR from 'i18next-xhr-backend';
-import LanguageDetector from 'i18next-browser-languagedetector';
-import { initReactI18next } from 'react-i18next';
-
+import i18n from "i18next";
+import XHR from "i18next-xhr-backend";
+import LanguageDetector from "i18next-browser-languagedetector";
+import { initReactI18next } from "react-i18next";
i18n
.use(XHR)
.use(LanguageDetector)
.use(initReactI18next) // bind react-i18next to the instance
.init({
- fallbackLng: 'en',
+ fallbackLng: "en",
debug: true,
saveMissing: true, // send not translated keys to endpoint
defaultValue: "__STRING_NOT_TRANSLATED__",
- keySeparator: '>',
- nsSeparator: '|',
- backend: {
- loadPath: '/locale/i18n/{{lng}}/resource.json',
- // path to post missing resources
- },
+ keySeparator: ">",
+ nsSeparator: "|",
+ backend: {
+ loadPath: "/locale/i18n/{{lng}}/resource.json"
+ // path to post missing resources
+ },
interpolation: {
- escapeValue: false, // not needed for react!!
- },
+ escapeValue: false // not needed for react!!
+ }
// react i18next special options (optional)
// override if needed - omit if ok with defaults
@@ -39,5 +38,4 @@ i18n
*/
});
-
export default i18n;
diff --git a/src/scss/_app.scss b/src/scss/_app.scss
index cf2f189..1d06019 100644
--- a/src/scss/_app.scss
+++ b/src/scss/_app.scss
@@ -154,7 +154,7 @@ li.sortable {
border-radius: 50%;
}
-.checkround.checkround-gray{
+.checkround.checkround-gray {
border-color: $gray-600;
}
@@ -319,22 +319,21 @@ li.sortable {
padding: 0.25em !important;
}
-
/** flag selector **/
.flag-select > button {
- height:35px;
+ height: 35px;
}
-.flag-select__options{
- width:65px;
- text-align:center;
+.flag-select__options {
+ width: 65px;
+ text-align: center;
background-color: $mv-light-color !important;
}
-.flag-select__options .flag-select__option{
- padding:0;
- margin:0;
+.flag-select__options .flag-select__option {
+ padding: 0;
+ margin: 0;
}
-.flag-select__options .flag-select__option__icon{
- top:0;
+.flag-select__options .flag-select__option__icon {
+ top: 0;
}
|