Skip to content

Commit

Permalink
Fix #232: Total bar not updating on day change
Browse files Browse the repository at this point in the history
  • Loading branch information
araujoarthur0 authored and thamara committed Jun 22, 2020
1 parent 908965c commit 862229f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Fix: [#211] Adjusted preferences window size to fit the whole content
- Fix: [#233] Fixes crash when opening the waiver for a day
- Fix: [#229] Count Today in totals no longer causes problem in the month balance
- Fix: [#232] Total bar not updating on day change
- Fix: [#239] Punch button is disabled when current day is waived
- Fix: [#240] Waiver using electron dialog instead of js confirm/alert
- Fix: [#244] Waiver opens with filled date when clicking from calendar
Expand Down
27 changes: 27 additions & 0 deletions js/classes/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,19 @@ class Calendar {
this._draw();
}

/**
* Every day change, if the calendar is showing the same month as that of the previous day,
* this function is called to redraw the calendar.
* @param {int} oldDayDate not used in MonthCalendar, just DayCalendar
* @param {int} oldMonthDate
* @param {int} oldYearDate
*/
refreshOnDayChange(oldDayDate, oldMonthDate, oldYearDate) {
if (this._getCalendarMonth() === oldMonthDate && this._getCalendarYear() === oldYearDate) {
this._goToCurrentDate();
}
}

/*
* Display next month.
*/
Expand Down Expand Up @@ -1119,6 +1132,20 @@ class DayCalendar extends Calendar {
}
}

/**
* Every day change, if the calendar is showing the same date as that of the previous date,
* this function is called to redraw the calendar.
* @param {int} oldDayDate
* @param {int} oldMonthDate
* @param {int} oldYearDate
*/
refreshOnDayChange(oldDayDate, oldMonthDate, oldYearDate) {
let date = new Date(oldYearDate, oldMonthDate, oldDayDate);
if (this._isCalendarOnDate(date)) {
this._goToCurrentDate();
}
}

/*
* Updates the monthly time balance.
*/
Expand Down
5 changes: 4 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,12 @@ function refreshOnDayChange() {
var today = new Date();
if (today > launchDate)
{
let oldDate = launchDate.getDate();
let oldMonth = launchDate.getMonth();
let oldYear = launchDate.getFullYear();
launchDate = today;
// Reload only the calendar itself to avoid a flash
win.webContents.executeJavaScript('calendar.redraw()');
win.webContents.executeJavaScript(`calendar.refreshOnDayChange(${oldDate},${oldMonth},${oldYear})`);
}
}

Expand Down

0 comments on commit 862229f

Please sign in to comment.