Log training sessions onto the selected day, not always today
The Log button stamps the selected day at the current time of day, so a forgotten session can be back-filled from that day's view. The snackbar says which day it landed on when it isn't today; Undo/Add note still work on it.
This commit is contained in:
+13
-2
@@ -1711,8 +1711,19 @@
|
||||
logBtn.textContent = "Log";
|
||||
logBtn.addEventListener("click", (e) => {
|
||||
e.stopPropagation();
|
||||
const ev = addEvent("training", "", Date.now(), { exerciseId: ex.id });
|
||||
showSnackbar(`${ex.name} logged`, ev);
|
||||
// Log onto the selected day (at the current time of day), so a session
|
||||
// that was forgotten yesterday can be back-filled from that day's view.
|
||||
const day = selectedDay();
|
||||
const onToday = ymd(day) === ymd(new Date());
|
||||
let at = Date.now();
|
||||
if (!onToday) {
|
||||
const now = new Date();
|
||||
at = new Date(day.getFullYear(), day.getMonth(), day.getDate(),
|
||||
now.getHours(), now.getMinutes(), now.getSeconds()).getTime();
|
||||
}
|
||||
const ev = addEvent("training", "", at, { exerciseId: ex.id });
|
||||
const dayStr = day.toLocaleDateString(undefined, { month: "short", day: "numeric" });
|
||||
showSnackbar(onToday ? `${ex.name} logged` : `${ex.name} logged for ${dayStr}`, ev);
|
||||
});
|
||||
|
||||
row.appendChild(main);
|
||||
|
||||
Reference in New Issue
Block a user