From ebf75d3b5eb8ccbe137b5ac1b3926fbb46be84f2 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Fri, 2 Apr 2021 14:59:20 -0400 Subject: [PATCH 1/5] gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1377554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp From 195754cc4e9c9489e47492f395791958fe9cd854 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Fri, 2 Apr 2021 14:59:41 -0400 Subject: [PATCH 2/5] post to local api --- app.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app.js b/app.js index fe419de..76164a2 100644 --- a/app.js +++ b/app.js @@ -89,6 +89,18 @@ const updateSavedPreviousSeconds = () => { savedPreviousSeconds += getAccumulatedSeconds(Date.now(), startTime); } +const postToAPI = ()=>{ + if(savedPreviousSeconds > 0){ + fetch('http://localhost:8000/api/sessions',{ + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({seconds:savedPreviousSeconds}) + }); + } +} + document.querySelector('code').innerHTML = formatSeconds(savedPreviousSeconds); document.querySelector('small').innerHTML = formatMinuteBlocks(savedPreviousSeconds); if(savedPreviousSeconds !== 0){ @@ -100,6 +112,7 @@ document.querySelector('#start').addEventListener('click', start) document.querySelector('#stop').addEventListener('click', stop) document.querySelector('#reset').addEventListener('click', (event) => { + postToAPI(); savedPreviousSeconds = 0; document.querySelector('code').innerHTML = formatSeconds(savedPreviousSeconds); document.querySelector('small').innerHTML = formatMinuteBlocks(savedPreviousSeconds); @@ -122,6 +135,7 @@ window.onbeforeunload = function(){ } window.localStorage.setItem('savedPreviousSeconds', savedPreviousSeconds); if(savedPreviousSeconds > 0){ + postToAPI(); return 'Good bye'; } } From f4e5ba8bc63c7a1fa45c333eb8515d32840636c5 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Fri, 2 Apr 2021 15:00:15 -0400 Subject: [PATCH 3/5] formatting --- app.js | 104 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/app.js b/app.js index 76164a2..cec6903 100644 --- a/app.js +++ b/app.js @@ -27,66 +27,66 @@ let windowInterval; const previousSessionAccumulatedSeconds = parseInt(window.localStorage.getItem('savedPreviousSeconds')); if(previousSessionAccumulatedSeconds){ - savedPreviousSeconds = previousSessionAccumulatedSeconds + savedPreviousSeconds = previousSessionAccumulatedSeconds } const padDigits = (value) => { - if(value < 10){ - return '0'+value; - } else { - return value; - } + if(value < 10){ + return '0'+value; + } else { + return value; + } } const getMinutes = (seconds) => { - return Math.floor( seconds / 60 ); + return Math.floor( seconds / 60 ); } const formatSeconds = (total) => { - const minutes = getMinutes(total); - const seconds = total - minutes*60; - return `${minutes}:${padDigits(seconds)}`; + const minutes = getMinutes(total); + const seconds = total - minutes*60; + return `${minutes}:${padDigits(seconds)}`; } const formatMinuteBlocks = (seconds) => { - const minutes = getMinutes(seconds); - const fiveMins = Math.floor(minutes/5); - const tenMins = Math.floor(minutes/10); - return `5 minute blocks: ${fiveMins}
10 minute blocks: ${tenMins}`; + const minutes = getMinutes(seconds); + const fiveMins = Math.floor(minutes/5); + const tenMins = Math.floor(minutes/10); + return `5 minute blocks: ${fiveMins}
10 minute blocks: ${tenMins}`; } const getAccumulatedSeconds = (newerTime, olderTime) => { - return Math.floor((newerTime-olderTime)/1000); + return Math.floor((newerTime-olderTime)/1000); } const displayTime = () => { - const totalSeconds = getAccumulatedSeconds(Date.now(),startTime) + savedPreviousSeconds; - document.querySelector('code').innerHTML = formatSeconds(totalSeconds); - document.querySelector('small').innerHTML = formatMinuteBlocks(totalSeconds); + const totalSeconds = getAccumulatedSeconds(Date.now(),startTime) + savedPreviousSeconds; + document.querySelector('code').innerHTML = formatSeconds(totalSeconds); + document.querySelector('small').innerHTML = formatMinuteBlocks(totalSeconds); } const start = (event) => { - startTime = Date.now(); - running = true; - document.querySelector('body').classList.add('running'); - document.querySelector('#start').disabled=true; - document.querySelector('#stop').disabled=false; - document.querySelector('#reset').disabled=true; - windowInterval = window.setInterval(displayTime,1000) + startTime = Date.now(); + running = true; + document.querySelector('body').classList.add('running'); + document.querySelector('#start').disabled=true; + document.querySelector('#stop').disabled=false; + document.querySelector('#reset').disabled=true; + windowInterval = window.setInterval(displayTime,1000) }; const stop = (event) => { - updateSavedPreviousSeconds(); - running = false; - document.querySelector('body').classList.remove('running'); - document.querySelector('#start').disabled=false; - document.querySelector('#stop').disabled=true; - document.querySelector('#reset').disabled=false; - window.clearInterval(windowInterval) + updateSavedPreviousSeconds(); + running = false; + document.querySelector('body').classList.remove('running'); + document.querySelector('#start').disabled=false; + document.querySelector('#stop').disabled=true; + document.querySelector('#reset').disabled=false; + window.clearInterval(windowInterval) }; const updateSavedPreviousSeconds = () => { - savedPreviousSeconds += getAccumulatedSeconds(Date.now(), startTime); + savedPreviousSeconds += getAccumulatedSeconds(Date.now(), startTime); } const postToAPI = ()=>{ @@ -104,7 +104,7 @@ const postToAPI = ()=>{ document.querySelector('code').innerHTML = formatSeconds(savedPreviousSeconds); document.querySelector('small').innerHTML = formatMinuteBlocks(savedPreviousSeconds); if(savedPreviousSeconds !== 0){ - document.querySelector('#reset').disabled=false; + document.querySelector('#reset').disabled=false; } document.querySelector('#start').addEventListener('click', start) @@ -113,29 +113,29 @@ document.querySelector('#stop').addEventListener('click', stop) document.querySelector('#reset').addEventListener('click', (event) => { postToAPI(); - savedPreviousSeconds = 0; - document.querySelector('code').innerHTML = formatSeconds(savedPreviousSeconds); - document.querySelector('small').innerHTML = formatMinuteBlocks(savedPreviousSeconds); - document.querySelector('#reset').disabled=true; + savedPreviousSeconds = 0; + document.querySelector('code').innerHTML = formatSeconds(savedPreviousSeconds); + document.querySelector('small').innerHTML = formatMinuteBlocks(savedPreviousSeconds); + document.querySelector('#reset').disabled=true; }) document.querySelector('body').addEventListener('keyup', (event) => { - if(event.keyCode === 32){ - if(running){ - stop(); - } else { - start(); - } - } + if(event.keyCode === 32){ + if(running){ + stop(); + } else { + start(); + } + } }) window.onbeforeunload = function(){ - if(running){ - updateSavedPreviousSeconds(); - } - window.localStorage.setItem('savedPreviousSeconds', savedPreviousSeconds); - if(savedPreviousSeconds > 0){ + if(running){ + updateSavedPreviousSeconds(); + } + window.localStorage.setItem('savedPreviousSeconds', savedPreviousSeconds); + if(savedPreviousSeconds > 0){ postToAPI(); - return 'Good bye'; - } + return 'Good bye'; + } } From d337d1bdb723fdbfc254de0904e589ce7905d359 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Fri, 2 Apr 2021 15:22:23 -0400 Subject: [PATCH 4/5] using heroku api --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index cec6903..0b7b033 100644 --- a/app.js +++ b/app.js @@ -91,7 +91,7 @@ const updateSavedPreviousSeconds = () => { const postToAPI = ()=>{ if(savedPreviousSeconds > 0){ - fetch('http://localhost:8000/api/sessions',{ + fetch('https://shrouded-depths-07664.herokuapp.com/api/sessions',{ method: 'POST', headers: { 'Content-Type': 'application/json' From 74f87c6c5eb6ae5779ce30d49384e2521ced8c17 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Fri, 15 Oct 2021 23:10:55 -0400 Subject: [PATCH 5/5] Update app.js --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index 0b7b033..587bf85 100644 --- a/app.js +++ b/app.js @@ -52,7 +52,7 @@ const formatMinuteBlocks = (seconds) => { const minutes = getMinutes(seconds); const fiveMins = Math.floor(minutes/5); const tenMins = Math.floor(minutes/10); - return `5 minute blocks: ${fiveMins}
10 minute blocks: ${tenMins}`; + return `seconds: ${seconds}
5 minute blocks: ${fiveMins}
10 minute blocks: ${tenMins}`; } const getAccumulatedSeconds = (newerTime, olderTime) => {