|
1 | 1 | import {createTippy} from '../modules/tippy.ts'; |
2 | 2 | import {GET} from '../modules/fetch.ts'; |
3 | | -import {hideElem, showElem} from '../utils/dom.ts'; |
| 3 | +import {hideElem, queryElems, showElem} from '../utils/dom.ts'; |
4 | 4 | import {logoutFromWorker} from '../modules/worker.ts'; |
5 | 5 |
|
6 | 6 | const {appSubUrl, notificationSettings, enableTimeTracking, assetVersionEncoded} = window.config; |
@@ -147,20 +147,9 @@ function updateStopwatchData(data) { |
147 | 147 | // TODO: This flickers on page load, we could avoid this by making a custom |
148 | 148 | // element to render time periods. Feeding a datetime in backend does not work |
149 | 149 | // when time zone between server and client differs. |
150 | | -function updateStopwatchTime(seconds) { |
151 | | - if (!Number.isFinite(seconds)) return; |
152 | | - const datetime = (new Date(Date.now() - seconds * 1000)).toISOString(); |
153 | | - for (const parent of document.querySelectorAll('.header-stopwatch-dot')) { |
154 | | - const existing = parent.querySelector(':scope > relative-time'); |
155 | | - if (existing) { |
156 | | - existing.setAttribute('datetime', datetime); |
157 | | - } else { |
158 | | - const el = document.createElement('relative-time'); |
159 | | - el.setAttribute('format', 'micro'); |
160 | | - el.setAttribute('datetime', datetime); |
161 | | - el.setAttribute('lang', 'en-US'); |
162 | | - el.setAttribute('title', ''); // make <relative-time> show no title and therefor no tooltip |
163 | | - parent.append(el); |
164 | | - } |
165 | | - } |
| 150 | +function updateStopwatchTime(seconds: number) { |
| 151 | + const hours = seconds / 3600 || 0; |
| 152 | + const minutes = seconds / 60 || 0; |
| 153 | + const timeText = hours >= 1 ? `${Math.round(hours)}h` : `${Math.round(minutes)}m`; |
| 154 | + queryElems(document, '.header-stopwatch-dot', (el) => el.textContent = timeText); |
166 | 155 | } |
0 commit comments