Skip to content

Commit

Permalink
Fix election counter
Browse files Browse the repository at this point in the history
  • Loading branch information
ottaviano committed Nov 5, 2024
1 parent 092cabd commit f157b57
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 90 deletions.
24 changes: 14 additions & 10 deletions assets/services/utils/countdownClock.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ function initializeTimer(element, refreshPage) {
const container = findOne(element, '.clock-container');

const interval = 1000;
const diffTime = element.dataset.eventTimestamp - element.dataset.nowTimestamp;
let duration = moment.duration(diffTime * 1000, 'milliseconds');
let diffTime = (element.dataset.eventTimestamp - element.dataset.nowTimestamp) * 1000;

if (0 < diffTime) {
const days = document.createElement('span');
Expand Down Expand Up @@ -36,16 +35,21 @@ function initializeTimer(element, refreshPage) {
let s;
s = h = m = d = 0;

const diff = duration.asMilliseconds() - interval;
diffTime -= interval;

if (0 < diff) {
duration = moment.duration(diff, 'milliseconds');
if (0 < diffTime) {
let delta = diffTime / 1000;

const durationObj = moment.duration(duration);
d = durationObj.asDays();
h = durationObj.hours();
m = durationObj.minutes();
s = durationObj.seconds();
d = Math.floor(delta / 86400);
delta -= d * 86400;

h = Math.floor(delta / 3600) % 24;
delta -= h * 3600;

m = Math.floor(delta / 60) % 60;
delta -= m * 60;

s = delta % 60;
} else if (refreshPage) {
window.location.reload();
}
Expand Down
6 changes: 0 additions & 6 deletions front/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,6 @@ class App {
});
}

runCountdownClock(clockSelector, refreshPage = false) {
import('services/utils/countdownClock').catch((error) => { throw error; }).then((module) => {
module.default(clockSelector, refreshPage);
});
}

runCommitteeCandidacy(slug, submitButtonSelector, wrapperSelector) {
import('pages/committee_candidacy').catch((error) => { throw error; }).then((module) => {
module.default(this.get('api'), slug, submitButtonSelector, wrapperSelector);
Expand Down
2 changes: 0 additions & 2 deletions front/components/CandidaciesListWidget.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import moment from 'moment';
import Modal from './Modal';
import Loader from './Loader';
import ReqwestApiClient from '../services/api/ReqwestApiClient';
Expand Down Expand Up @@ -58,7 +57,6 @@ export default class CandidaciesListWidget extends Modal {
<div className='text--smallest'>
Déclaré{'female' === candidacy.gender ? 'e ' : ' '}
candidat{'female' === candidacy.gender ? 'e ' : ' '}
le {moment(candidacy.created_at).format('DD/MM/YYYY')}
</div>
</div>
</div>;
Expand Down
64 changes: 0 additions & 64 deletions front/services/utils/countdownClock.js

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"js-cookie": "^3.0.5",
"lodash": "^4.17.21",
"mini-css-extract-plugin": "^2.9.0",
"moment": "^2.30.1",
"postcss": "^8.4.38",
"postcss-loader": "^8.1.1",
"prop-types": "^15.8.1",
Expand Down
2 changes: 0 additions & 2 deletions templates/committee/show.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@
App.runCandidacyModal('#candidacies-list-modal--trigger');
{% endif %}
{% endif %}
App.runCountdownClock('.em-countdown-clock', true);
});
</script>
{% endblock %}
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4081,11 +4081,6 @@ minimist@^1.2.0, minimist@^1.2.6:
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"
integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==

moment@^2.30.1:
version "2.30.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.30.1.tgz#f8c91c07b7a786e30c59926df530b4eac96974ae"
integrity sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==

ms@^2.1.1, ms@^2.1.3:
version "2.1.3"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
Expand Down

0 comments on commit f157b57

Please sign in to comment.