From ceb41d2a336925b328bc5c6357e08380292a095a Mon Sep 17 00:00:00 2001 From: henri-mabiti Date: Fri, 29 Nov 2024 14:11:13 -0300 Subject: [PATCH] fix: feature today sum --- package-lock.json | 4 ++-- package.json | 2 +- src/tracker.ts | 14 +++++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 464c6e4..b05ad75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "simple-time-tracker", - "version": "1.0.3", + "version": "1.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "simple-time-tracker", - "version": "1.0.3", + "version": "1.1.0", "license": "MIT", "devDependencies": { "@types/node": "^16.11.6", diff --git a/package.json b/package.json index bacd403..3b86147 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-time-tracker", - "version": "1.0.3", + "version": "1.1.0", "description": "Multi-purpose time trackers for your notes!", "main": "main.js", "scripts": { diff --git a/src/tracker.ts b/src/tracker.ts index eaf8952..da359ab 100644 --- a/src/tracker.ts +++ b/src/tracker.ts @@ -101,9 +101,12 @@ export function displayTracker(tracker: Tracker, element: HTMLElement, getFile: let total = totalDiv.createEl("span", { cls: "simple-time-tracker-timer-time", text: "0s" }); totalDiv.createEl("span", { text: "Total" }); + let totalTodayDiv; + let totalToday: HTMLElement; + if (settings.showToday) { - let totalTodayDiv = timer.createEl("div", { cls: "simple-time-tracker-timer" }) - let totalToday = totalTodayDiv.createEl("span", { cls: "simple-time-tracker-timer-time", text: "0s" }) + totalTodayDiv = timer.createEl("div", { cls: "simple-time-tracker-timer" }) + totalToday = totalTodayDiv.createEl("span", { cls: "simple-time-tracker-timer-time", text: "0s" }) totalTodayDiv.createEl("span", { text: "Today" }) } @@ -131,14 +134,14 @@ export function displayTracker(tracker: Tracker, element: HTMLElement, getFile: } - setCountdownValues(tracker, current, total, currentDiv, settings); + setCountdownValues(tracker, current, total, totalToday, currentDiv, settings); let intervalId = window.setInterval(() => { // we delete the interval timer when the element is removed if (!element.isConnected) { window.clearInterval(intervalId); return; } - setCountdownValues(tracker, current, total, currentDiv, settings); + setCountdownValues(tracker, current, total, totalToday, currentDiv, settings); }, 1000); } @@ -322,7 +325,7 @@ function removeEntry(entries: Entry[], toRemove: Entry): boolean { return false; } -function setCountdownValues(tracker: Tracker, current: HTMLElement, total: HTMLElement, currentDiv: HTMLDivElement, settings: SimpleTimeTrackerSettings): void { +function setCountdownValues(tracker: Tracker, current: HTMLElement, total: HTMLElement, totalToday: HTMLElement, currentDiv: HTMLDivElement, settings: SimpleTimeTrackerSettings): void { let running = getRunningEntry(tracker.entries); if (running && !running.endTime) { current.setText(formatDuration(getDuration(running), settings)); @@ -331,6 +334,7 @@ function setCountdownValues(tracker: Tracker, current: HTMLElement, total: HTMLE currentDiv.hidden = true; } total.setText(formatDuration(getTotalDuration(tracker.entries), settings)); + totalToday.setText(formatDuration(getTotalDurationToday(tracker.entries), settings)); } function formatEditableTimestamp(timestamp: string, settings: SimpleTimeTrackerSettings): string {