Skip to content

Commit e3758ae

Browse files
committed
feat: build task log description once
1 parent b6115b7 commit e3758ae

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func Execute() {
1818
currentUser, err := user.Current()
1919

2020
if err != nil {
21-
die("Error getting your home directory, This is a fatal error; let @dhth know about this.\n%s\n", err)
21+
die("Error getting your home directory, This is a fatal error; use -db-path to specify database path manually.\n%s\n", err)
2222
}
2323

2424
defaultDBPath := fmt.Sprintf("%s/hours.v%s.db", currentUser.HomeDir, DB_VERSION)

internal/ui/render_helpers.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ func (t *task) updateDesc() {
2727

2828
t.desc = fmt.Sprintf("%s %s", RightPadTrim(lastUpdated, 60), timeSpent)
2929
}
30+
31+
func (tl *taskLogEntry) updateDesc() {
32+
secsSpent := int(tl.endTS.Sub(tl.beginTS).Seconds())
33+
timeSpentStr := humanizeDuration(secsSpent)
34+
35+
tl.desc = fmt.Sprintf("%s (spent %s)", RightPadTrim(humanize.Time(tl.beginTS), 60), timeSpentStr)
36+
}

internal/ui/types.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package ui
22

33
import (
4-
"fmt"
54
"time"
6-
7-
"github.com/dustin/go-humanize"
85
)
96

107
type task struct {
@@ -13,10 +10,10 @@ type task struct {
1310
createdAt time.Time
1411
updatedAt time.Time
1512
trackingActive bool
16-
title string
17-
desc string
1813
secsSpent int
1914
active bool
15+
title string
16+
desc string
2017
}
2118

2219
type taskLogEntry struct {
@@ -26,6 +23,8 @@ type taskLogEntry struct {
2623
beginTS time.Time
2724
endTS time.Time
2825
comment string
26+
title string
27+
desc string
2928
}
3029

3130
func (t task) Title() string {
@@ -45,12 +44,7 @@ func (e taskLogEntry) Title() string {
4544
}
4645

4746
func (e taskLogEntry) Description() string {
48-
secsSpent := int(e.endTS.Sub(e.beginTS).Seconds())
49-
timeSpentStr := humanizeDuration(secsSpent)
50-
51-
timeStr := fmt.Sprintf("%s (spent %s)", RightPadTrim(humanize.Time(e.beginTS), 30), timeSpentStr)
52-
53-
return fmt.Sprintf("%s %s", RightPadTrim("["+e.taskSummary+"]", 60), timeStr)
47+
return e.desc
5448
}
5549

5650
func (e taskLogEntry) FilterValue() string {

internal/ui/update.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
475475
} else {
476476
var items []list.Item
477477
for _, e := range msg.entries {
478-
items = append(items, list.Item(e))
478+
e.updateDesc()
479+
items = append(items, e)
479480
}
480481
m.taskLogList.SetItems(items)
481482
}

0 commit comments

Comments
 (0)