Skip to content

Commit f333786

Browse files
committed
fix frontend
1 parent fa65e25 commit f333786

File tree

3 files changed

+8
-23
lines changed

3 files changed

+8
-23
lines changed

models/issues/stopwatch.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ func (s Stopwatch) Seconds() int64 {
4646
return int64(timeutil.TimeStampNow() - s.CreatedUnix)
4747
}
4848

49-
// Duration returns a human-readable duration string based on local server time
50-
func (s Stopwatch) Duration() string {
51-
return util.SecToHours(s.Seconds())
52-
}
53-
5449
func getStopwatch(ctx context.Context, userID, issueID int64) (sw *Stopwatch, exists bool, err error) {
5550
sw = new(Stopwatch)
5651
exists, err = db.GetEngine(ctx).

services/convert/issue.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"code.gitea.io/gitea/modules/log"
1717
"code.gitea.io/gitea/modules/setting"
1818
api "code.gitea.io/gitea/modules/structs"
19+
"code.gitea.io/gitea/modules/util"
1920
)
2021

2122
func ToIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) *api.Issue {
@@ -186,7 +187,7 @@ func ToStopWatches(ctx context.Context, sws []*issues_model.Stopwatch) (api.Stop
186187
result = append(result, api.StopWatch{
187188
Created: sw.CreatedUnix.AsTime(),
188189
Seconds: sw.Seconds(),
189-
Duration: sw.Duration(),
190+
Duration: util.SecToHours(sw.Seconds()),
190191
IssueIndex: issue.Index,
191192
IssueTitle: issue.Title,
192193
RepoOwnerName: repo.OwnerName,

web_src/js/features/stopwatch.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {createTippy} from '../modules/tippy.ts';
22
import {GET} from '../modules/fetch.ts';
3-
import {hideElem, showElem} from '../utils/dom.ts';
3+
import {hideElem, queryElems, showElem} from '../utils/dom.ts';
44
import {logoutFromWorker} from '../modules/worker.ts';
55

66
const {appSubUrl, notificationSettings, enableTimeTracking, assetVersionEncoded} = window.config;
@@ -147,20 +147,9 @@ function updateStopwatchData(data) {
147147
// TODO: This flickers on page load, we could avoid this by making a custom
148148
// element to render time periods. Feeding a datetime in backend does not work
149149
// 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);
166155
}

0 commit comments

Comments
 (0)