Skip to content

Commit

Permalink
fix/multiple zero removel & code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Iskren1990 committed Sep 25, 2020
1 parent 1274968 commit d25825f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
6 changes: 3 additions & 3 deletions scripts/animations.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { elements } from './elements.js';
import { setLeadingZero } from './utils.js';
import { formatTimeContent } from './utils.js';
// import { showProgress } from './progress-bars.js';

let animationId;
Expand All @@ -17,10 +17,10 @@ function startUpdateSeconds(elapsedTime) {

if (seconds > 0) {
const changedSeconds = seconds - 1;
elements.time.seconds().textContent = setLeadingZero(changedSeconds);
elements.time.seconds().textContent = formatTimeContent(changedSeconds);
} else if (minutes > 0) {
const changedMinutes = minutes - 1;
elements.time.minutes().textContent = setLeadingZero(changedMinutes);
elements.time.minutes().textContent = formatTimeContent(changedMinutes);
elements.time.seconds().textContent = 59;
}
// showProgress(minutes, seconds, countdownTime);
Expand Down
10 changes: 5 additions & 5 deletions scripts/modal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { elements } from './elements.js';
import { setLeadingZero } from './utils.js';
import { formatTimeContent } from './utils.js';
import { isStartedYet } from './controls.js';

const { closeButton, form, modalOverlay, modal, suggestions } = elements.modal;
Expand Down Expand Up @@ -27,13 +27,13 @@ function setTheTimer(e) {

e.preventDefault();

const [minutesVal, secondsVal] = [...document.querySelectorAll('form input')].map((e) => setLeadingZero(e.value));
const [minutesVal, secondsVal] = [...document.querySelectorAll('form input')].map((e) => formatTimeContent(e.value));

const suggestedPick = e.suggestedPick ? setLeadingZero(e.suggestedPick) : false;
const timeFromForm = (minutesVal > 0 ? minutesVal : "00");
const suggestedPick = e.suggestedPick ? formatTimeContent(e.suggestedPick) : false;
const timeFromForm = formatTimeContent(minutesVal);

minutes().textContent = suggestedPick || timeFromForm;
seconds().textContent = (secondsVal > 0 ? secondsVal : "00");
seconds().textContent = formatTimeContent(secondsVal);

toggleModal();

Expand Down
12 changes: 4 additions & 8 deletions scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,16 @@ export function manageQueryString(search) {
const queries = parseQueryString(search);
if (queries) {
const { m, s } = extractTimeQuery(queries);
elements.time.minutes().textContent = formatTextContent(m);
elements.time.seconds().textContent = formatTextContent(s);
elements.time.minutes().textContent = formatTimeContent(m);
elements.time.seconds().textContent = formatTimeContent(s);

if (queries.on === "true") { elements.info.timerState().click(); }
if (queries.mod === "false") { elements.modal.closeButton().click(); }
}
}

export function setLeadingZero(value) {
return Number(value) > 9 ? value : `0${value}`;
}

export function formatTextContent(textContent) {
return textContent || '00';
export function formatTimeContent(value) {
return Number(value).toString().padStart(2, 0);
}

export function manageAudio() {
Expand Down

0 comments on commit d25825f

Please sign in to comment.