Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Update On Elapsed on listpage #115

Merged
merged 86 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
3924663
remove unnecessary await from displayCountdowns()
RDjarbeng Dec 22, 2022
9b75d6e
add list refresh after cd elapses
RDjarbeng Dec 22, 2022
42d872d
remove .then from displayAndStartCount use normal try catch
RDjarbeng Dec 22, 2022
ff50db8
Move listpage element ids to different file
RDjarbeng Dec 25, 2022
2c7f8cc
move listpage sorting to different file
RDjarbeng Dec 25, 2022
b4edcbe
move listpage ui functions to another folder
RDjarbeng Dec 25, 2022
3b89014
move listpage ui functions to another folder
RDjarbeng Dec 25, 2022
e420432
move listpage ui functions to another folder
RDjarbeng Dec 25, 2022
b72ca77
move sort and ui functions to different folder
RDjarbeng Dec 25, 2022
cd95d0f
correct path from trigger context menu
RDjarbeng Dec 25, 2022
321cc1a
clock ui functions, update imports
RDjarbeng Dec 25, 2022
c14cc76
clock ui functions, update imports
RDjarbeng Dec 25, 2022
74ca86d
update imports after moving list functions
RDjarbeng Dec 25, 2022
20681ff
update imports after moving list functions
RDjarbeng Dec 25, 2022
f5ffa7f
remove unnecessary await
RDjarbeng Dec 25, 2022
d01c785
rename displayAndStart() to displayAndUpdatecount
RDjarbeng Dec 25, 2022
40fa1ae
move button getters from form update
RDjarbeng Dec 25, 2022
713268a
move handleFormUpdate() to formUpdate.js, update imports
RDjarbeng Dec 25, 2022
ad80460
update comments
RDjarbeng Dec 25, 2022
fcff0c6
move listpage event listener to different file, export delete functio…
RDjarbeng Dec 25, 2022
7cbdd59
format listevent listener
RDjarbeng Dec 26, 2022
7471372
update imports use new update local item
RDjarbeng Dec 26, 2022
cb03ff4
use update local item to update state of the countdowns
RDjarbeng Dec 26, 2022
f48894c
move fetchArrayOfCountdowns to different file
RDjarbeng Dec 26, 2022
b7ac132
move fetchArrayOfCountdowns to different file
RDjarbeng Dec 26, 2022
c339507
add base path to vite preview
RDjarbeng Dec 26, 2022
7dec8f8
move fetchArrayOfCountdowns() to different file
RDjarbeng Dec 26, 2022
9d53079
Merge branch 'fixUpdateOnElapse' of https://github.com/RDjarbeng/coun…
RDjarbeng Dec 26, 2022
2fcdddd
move isTargetElementOnCountdownItem() to different file
RDjarbeng Dec 26, 2022
3e536cc
update params for isClassOnTargetElement()
RDjarbeng Dec 26, 2022
2d295f3
move isTargetElementOnContextMenu and isClassOnTargetElement to list…
RDjarbeng Dec 26, 2022
b5be2d7
move setMainClockCountdown to listeventlistener
RDjarbeng Dec 26, 2022
20b4f1b
Rename Listpage...IDS to listpage....Classes
RDjarbeng Dec 26, 2022
a36efaf
update imports after function move
RDjarbeng Dec 26, 2022
3e72f84
Move sortTitleEventHandler to different file
RDjarbeng Dec 26, 2022
6d35d68
Create separate file for listEventHandlers
RDjarbeng Dec 26, 2022
497d510
remove unused async await
RDjarbeng Dec 26, 2022
592cb15
move sort functions to sort.js
RDjarbeng Dec 26, 2022
5cde586
add listeners for sort to html imports
RDjarbeng Dec 26, 2022
5246420
remove displayandAddListeners from listfunctions
RDjarbeng Dec 26, 2022
18955b0
remove addSortUI and listeners
RDjarbeng Dec 26, 2022
5cfb8df
fix imports
RDjarbeng Dec 26, 2022
e8d6672
Implement conditional rendering of sortUI
RDjarbeng Dec 26, 2022
4bfb0e4
remove unused imports
RDjarbeng Dec 26, 2022
328bb05
add strings for css selectors to separate file
RDjarbeng Dec 27, 2022
c82b143
Merge remote-tracking branch 'origin/vitePWA' into fixUpdateOnElapse
RDjarbeng Dec 27, 2022
988da10
move setcountdown status to different file
RDjarbeng Dec 27, 2022
6c1e799
stop loading listpage from within formupdate.js
RDjarbeng Dec 27, 2022
c43a739
Add getArrayOfCountdownStatus for other functions to use to interface
RDjarbeng Dec 27, 2022
d79043a
add listener function to refresh page after form submit
RDjarbeng Dec 27, 2022
b6299ff
add check for null for arrayofCountdowns first
RDjarbeng Dec 27, 2022
36458e9
use new array status function
RDjarbeng Dec 27, 2022
c6f10c8
remove export of fetchArrayOfCountdowns method
RDjarbeng Dec 27, 2022
54ccc89
move fetchArrayOfCountdowns to listfunctions
RDjarbeng Dec 27, 2022
8b5dc6f
delete fetch array of countdowns file
RDjarbeng Dec 27, 2022
bc43544
update imports for fetchArrayOfCountdowns and getCountdownString
RDjarbeng Dec 27, 2022
fc28b49
update imports remove fetchArrayOfCountdowns
RDjarbeng Dec 27, 2022
68ffff4
update imports
RDjarbeng Dec 27, 2022
296c676
set delete to refresh page
RDjarbeng Dec 27, 2022
77c19f1
resolve error due to variable name
RDjarbeng Dec 27, 2022
3ab15a9
correct var name
RDjarbeng Dec 27, 2022
f1d112c
comment out unused function
RDjarbeng Dec 27, 2022
21bc4c3
addEvent handlers and sortui to reregister on form submission
RDjarbeng Dec 27, 2022
0d16b6d
update imports
RDjarbeng Dec 27, 2022
3a32f68
change getArrayOfCountdownStatus to always fetch from storage
RDjarbeng Dec 27, 2022
d8a1b24
add remove sortUI function
RDjarbeng Dec 27, 2022
6f830d5
add todo
RDjarbeng Dec 27, 2022
2def88d
remove listEventListener import
RDjarbeng Dec 27, 2022
e479eb3
use addSortUI instead, without duplicate listeners
RDjarbeng Dec 27, 2022
a7ef2e2
move getArrayOfCountdownStatus into event listener
RDjarbeng Dec 27, 2022
6c6fdfd
add remove sortUI function
RDjarbeng Dec 27, 2022
9eec631
import and use remove sortUI function
RDjarbeng Dec 27, 2022
589195b
add comments
RDjarbeng Dec 28, 2022
9925b77
let countdown function call getdistance()
RDjarbeng Dec 28, 2022
26c8d1c
add getLocalIsoString function to always use user timezone
RDjarbeng Dec 28, 2022
c48fec6
rename function to getLocalIsoStringFromDateInput
RDjarbeng Dec 28, 2022
1013535
use getLocalIsoStringFromDateInput instead of toISOString
RDjarbeng Dec 28, 2022
6c57f4f
change time refresh interval to 500ms
RDjarbeng Dec 28, 2022
f7a8d2d
move updateCountdownItemFromForm()
RDjarbeng Dec 28, 2022
b765743
move updateCountdownItemFromForm()
RDjarbeng Dec 28, 2022
0b7379a
add small todo about toISOString()
RDjarbeng Dec 28, 2022
2f08467
move handleHomePageFormSubmission
RDjarbeng Dec 28, 2022
93dea93
set update to use updateArrayOfCountdownState, move handleHomePageFor…
RDjarbeng Dec 28, 2022
f093716
update imports
RDjarbeng Dec 28, 2022
a5aa9b5
remove unused console.log
RDjarbeng Dec 28, 2022
5b7c82a
replay toISOstring in updateRepeatCountdown for new function getLocal…
RDjarbeng Dec 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion html/countdown-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
<script src="/js/loadCustomUI.js" type="module"></script>
<script src="/js/formupdate.js" type="module" async></script>
<script src="/js/displayCountdowns.js" type="module"></script>
<script src="/js/serviceWorkerUpdate.js" type="module"></script>
<!-- <script src="/js/listpage/addListEventListeners.js" type="module"></script> -->
<script src="/js/serviceWorkerUpdate.js" type= "module"></script>

</body>

Expand Down
7 changes: 4 additions & 3 deletions js/appfunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { setInnerHtmlForNotNull, addZeros } from "./functions.js";
* @param {{dayNumber: HTMLElement, hourNumber: HTMLElement, minNumber: HTMLElement, secNumber: HTMLElement}}domElements should contain elements for day, hour, minutes, second
* @param {Number} [duration=800] specifies how long the animation lasts in milliseconds
*/
export async function waitForAnimationUpdate(clock, domElements, duration, interval) {
await stepIncreaseAndStart(clock, domElements, duration);
return startClockAndReset(clock, domElements, interval);
export async function waitForAnimationUpdate(clock, domElements, duration, interval ) {
await stepIncreaseAndStart(clock , domElements, duration );
// todo:fix this undefined function,delete
// return startClockAndReset(clock , domElements, interval);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions js/clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ export class Clock {
return this.endDate.getTime() - new Date().getTime();
}
/**
* Calls the function to populate/refresh the time values in the clock
* Calls the function to populate/refresh the time values in the clock, used for reset
*/
countDown = () => {
var distance = this.getDistance()
// account for case of the countdown being reached, reset
if (this.getDistance() >= 0) {
// console.log('Running the count');
// Time calculations for days, hours, minutes and seconds
this.calculateTimeValues(this.getDistance())
this.calculateTimeValues()
} else {
// clear date values
this.resetMethod();
Expand All @@ -49,7 +48,8 @@ export class Clock {
this.clearCounter();
}

calculateTimeValues(distance) {
calculateTimeValues() {
let distance = this.getDistance();
this.days = Math.floor(distance / (1000 * 60 * 60 * 24));
this.hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
this.minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
Expand Down Expand Up @@ -98,7 +98,7 @@ export class Anniversary extends Clock {
// console.log('calling reset', this.endDate.getFullYear()<= new Date().getFullYear(), 'first cond', this.getDistance<0);
while (this.endDate.getFullYear() <= new Date().getFullYear() && this.getDistance() < 0) {
// this.endDate.
console.log(this.endDate, 'End date triggering');
console.log(this.endDate, 'Repeat End date triggering');
this.endDate.setFullYear(this.endDate.getFullYear() + 1)
// console.log('Anniversary done', this);
}
Expand Down
21 changes: 19 additions & 2 deletions js/displayCountdowns.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
import { loadListPage } from "./listFunctions.js";
import { popAndAddFormOnList } from "./formupdate.js";
import { addEventHandlers } from "./listpage/listEventListener.js";
import { loadListPage } from "./listpage/listFunctions.js";
import { addSortUIAndListeners } from "./listpage/list_sort/sort.js";
import { addSortUI } from "./listpage/list_ui/addSortUI.js";
// import { addEventHandlers } from "./listEventListener";

// begin displaycountdown.js
loadListPage();
loadListPage();
addEventHandlers();
addSortUIAndListeners()
const handleSubmissionAndLoadListpage=()=>{
popAndAddFormOnList();
loadListPage();
// addEventHandlers();
addSortUI();
}
//get button for create countdown
const createButton = document.getElementsByClassName("new-item")[0];
createButton.addEventListener("click", handleSubmissionAndLoadListpage);
13 changes: 1 addition & 12 deletions js/form.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import { popForm, closeFormPopUp, FORM_DOM_IDS, saveCountdownForm } from './formfunctions.js'
import { addClickListenersWithoutDuplicates } from './functions.js';
import { handleHomePageFormSubmission } from './formupdate.js';

const popAndAddFormSubmission = () => {
popForm()
handleHomePageFormSubmission();
}

function handleHomePageFormSubmission() {
const submitbutton = document.getElementById(FORM_DOM_IDS.form_submitButton);
addClickListenersWithoutDuplicates(submitbutton, (e) => {
e.preventDefault();
submitbutton.disabled = true;
saveCountdownForm();
// testing
window.location.href = "/html/countdown-list.html";
closeFormPopUp();
})
}


// todo: remove dynamic seting of css
Expand Down
19 changes: 15 additions & 4 deletions js/formfunctions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { errorHandler } from './error.js';
import { addZeros } from './functions.js'
import { fetchArrayOfCountdowns } from './listFunctions.js';
import { getArrayOfCountdownStatus } from './listpage/listFunctions.js';
import { getLocalIsoStringFromDateInput } from './timefunctions.js';

export const FORM_DOM_IDS = {
form_TextInput: 'countdownText',
Expand Down Expand Up @@ -119,7 +120,7 @@ export function setDateAttributes() {
}

export function saveNewCountdownToLocalStorage(countItem) {
let countdown = fetchArrayOfCountdowns();
let countdown = getArrayOfCountdownStatus();
if (countdown !== null) { //countdowns already exist
countdown.push(countItem);
// console.log(countdown);
Expand Down Expand Up @@ -169,15 +170,25 @@ export function getCdFromFormInputs() {
let userDate = dateInput.value;
// get text field values, with auto values
let userText = getUserText(userTextField);

userDate = new Date(userDate).toISOString();
console.log('Entered',userDate);
console.log('To locale',new Date(userDate).toLocaleString());
// userDate = new Date(userDate).toISOString();
userDate = getLocalIsoStringFromDateInput(userDate);
console.log('Stored',userDate);
let countItem = { text: userText, date: userDate, dateModified: new Date() };
if (repeatCheck) {
countItem.repeat = repeatCheck.checked;
}
return countItem;
}

export function updateCountdownItemFromForm(){
let countItem =getCdFromFormInputs();
//todo: use other ID apart from toISOString
countItem.dateModified= new Date().toISOString();
return countItem;
}

export const checkRepeat=(repeatCheckBox)=> repeatCheckBox.checked

export function saveCountdownForm() {
Expand Down
38 changes: 32 additions & 6 deletions js/formupdate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { popForm, closeFormPopUp, saveCountdownForm, FORM_DOM_IDS } from './formfunctions.js'
import { errorHandler } from './error.js';
import { loadListPage, updateArrayOfCountdownState } from './listFunctions.js';
const popAndAddFormOnList = () => {
import { closeFormPopUp, FORM_DOM_IDS, popForm, saveCountdownForm, updateCountdownItemFromForm } from './formfunctions.js';
import { updateArrayOfCountdownState, updateLocalItem } from './listpage/listFunctions.js';
import { addClickListenersWithoutDuplicates } from './functions.js';
import { removeClockAndText } from './listpage/list_ui/updateListpageClockAndText.js';
export const popAndAddFormOnList = () => {
popForm()
handleListpageFormSubmission();
}
Expand All @@ -14,7 +16,7 @@ function handleListpageFormSubmission() {
submitbutton.disabled = true;
saveCountdownForm();
updateArrayOfCountdownState();
loadListPage();
// loadListPage();
closeFormPopUp();
})
}else{
Expand All @@ -23,7 +25,33 @@ function handleListpageFormSubmission() {
}
}

export function handleFormUpdate() {
// todo: update list with custom fired events
const submitbutton = document.getElementById(FORM_DOM_IDS.form_submitButton);
submitbutton.addEventListener('click', (e) => {
e.preventDefault();
submitbutton.disabled = true;

const modifiedTimeAsID = document.getElementById(FORM_DOM_IDS.form_modifiedTime).value;
updateLocalItem(updateCountdownItemFromForm(), modifiedTimeAsID);
updateArrayOfCountdownState();
closeFormPopUp();
removeClockAndText();

})
}

export function handleHomePageFormSubmission() {
const submitbutton = document.getElementById(FORM_DOM_IDS.form_submitButton);
addClickListenersWithoutDuplicates(submitbutton, (e) => {
e.preventDefault();
submitbutton.disabled = true;
saveCountdownForm();
// testing
window.location.href = "/html/countdown-list.html";
closeFormPopUp();
})
}


// todo: remove dynamic seting of css, @nyakotey
Expand All @@ -35,5 +63,3 @@ function handleListpageFormSubmission() {
// }

// DOM Elements
const createButton = document.getElementsByClassName("new-item")[0];
createButton.addEventListener("click", popAndAddFormOnList);
Loading