Skip to content

Commit

Permalink
feat: build task log description once
Browse files Browse the repository at this point in the history
  • Loading branch information
dhth committed Jun 9, 2024
1 parent b6115b7 commit e3758ae
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Execute() {
currentUser, err := user.Current()

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

defaultDBPath := fmt.Sprintf("%s/hours.v%s.db", currentUser.HomeDir, DB_VERSION)
Expand Down
7 changes: 7 additions & 0 deletions internal/ui/render_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ func (t *task) updateDesc() {

t.desc = fmt.Sprintf("%s %s", RightPadTrim(lastUpdated, 60), timeSpent)
}

func (tl *taskLogEntry) updateDesc() {
secsSpent := int(tl.endTS.Sub(tl.beginTS).Seconds())
timeSpentStr := humanizeDuration(secsSpent)

tl.desc = fmt.Sprintf("%s (spent %s)", RightPadTrim(humanize.Time(tl.beginTS), 60), timeSpentStr)
}
16 changes: 5 additions & 11 deletions internal/ui/types.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package ui

import (
"fmt"
"time"

"github.com/dustin/go-humanize"
)

type task struct {
Expand All @@ -13,10 +10,10 @@ type task struct {
createdAt time.Time
updatedAt time.Time
trackingActive bool
title string
desc string
secsSpent int
active bool
title string
desc string
}

type taskLogEntry struct {
Expand All @@ -26,6 +23,8 @@ type taskLogEntry struct {
beginTS time.Time
endTS time.Time
comment string
title string
desc string
}

func (t task) Title() string {
Expand All @@ -45,12 +44,7 @@ func (e taskLogEntry) Title() string {
}

func (e taskLogEntry) Description() string {
secsSpent := int(e.endTS.Sub(e.beginTS).Seconds())
timeSpentStr := humanizeDuration(secsSpent)

timeStr := fmt.Sprintf("%s (spent %s)", RightPadTrim(humanize.Time(e.beginTS), 30), timeSpentStr)

return fmt.Sprintf("%s %s", RightPadTrim("["+e.taskSummary+"]", 60), timeStr)
return e.desc
}

func (e taskLogEntry) FilterValue() string {
Expand Down
3 changes: 2 additions & 1 deletion internal/ui/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
} else {
var items []list.Item
for _, e := range msg.entries {
items = append(items, list.Item(e))
e.updateDesc()
items = append(items, e)
}
m.taskLogList.SetItems(items)
}
Expand Down

0 comments on commit e3758ae

Please sign in to comment.