summaryrefslogtreecommitdiff
path: root/internal/tui/history_box.go
diff options
context:
space:
mode:
authorT <t@tjp.lol>2025-08-06 16:54:24 -0600
committerT <t@tjp.lol>2025-08-06 16:56:46 -0600
commitd75bd93385bf3b54ada84c3d45011d7f8efc1f80 (patch)
treecd50a2f300afaa24a48b3df84a2eb4a0af2429eb /internal/tui/history_box.go
parentc53e8c4e41aa88566b101431bcd104ebf7b34312 (diff)
auto scrolling the history view
Diffstat (limited to 'internal/tui/history_box.go')
-rw-r--r--internal/tui/history_box.go55
1 files changed, 51 insertions, 4 deletions
diff --git a/internal/tui/history_box.go b/internal/tui/history_box.go
index 10ede60..799947d 100644
--- a/internal/tui/history_box.go
+++ b/internal/tui/history_box.go
@@ -177,10 +177,57 @@ func (m HistoryBoxModel) View(width, height int, isSelected bool, timer TimerBox
vp := viewport.New(width-2, height-4)
vp.SetContent(content)
+
+ selectionHeight := m.selectionHeight()
+ visible := vp.VisibleLineCount()
+ if selectionHeight > vp.VisibleLineCount() {
+ vp.ScrollDown(selectionHeight - visible)
+ }
+
return style.Render(vp.View())
}
+func (m HistoryBoxModel) selectionHeight() int {
+ switch m.viewLevel {
+ case HistoryLevelSummary:
+ return m.summarySelectionHeight()
+ case HistoryLevelDetails:
+ return m.detailsSelectionHeight()
+ }
+ return 0
+}
+
+func (m HistoryBoxModel) summarySelectionHeight() int {
+ height := 1 // "Recent History" title line
+ var date *time.Time
+ for i, item := range m.summaryItems {
+ if date == nil || !date.Equal(item.Date) {
+ date = &item.Date
+ height += 4 // 2 newlines, the date, 1 more newline
+ }
+ height += 1 // newline before the selectable line
+ if i == m.summarySelection {
+ return height
+ }
+ height += 1 // the selectable line that's not selected
+ }
+ return 0
+}
+
+func (m HistoryBoxModel) detailsSelectionHeight() int {
+ height := 3 // "Details" title line + 2 newlines
+
+ for i := range m.selectedEntries() {
+ if i == m.detailSelection {
+ return height
+ }
+ height += 3 // un-selected line + 2 new lines
+ }
+ return 0
+}
+
var (
+ titleStyle = lipgloss.NewStyle().Bold(true)
dateStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("3"))
summaryItemStyle = lipgloss.NewStyle()
selectedItemStyle = lipgloss.NewStyle().Background(lipgloss.Color("62")).Foreground(lipgloss.Color("230"))
@@ -194,7 +241,7 @@ var (
// renderSummaryView renders the summary view (level 1) with date headers and client/project summaries
func (m HistoryBoxModel) renderSummaryView(timer TimerBoxModel) string {
- content := "📝 Recent History"
+ content := titleStyle.Render("📝 Recent History")
var activeKey HistorySummaryKey
if timer.timerInfo.IsActive {
@@ -215,7 +262,7 @@ func (m HistoryBoxModel) renderSummaryView(timer TimerBoxModel) string {
for i, item := range m.summaryItems {
if date == nil || !date.Equal(item.Date) {
date = &item.Date
- content += fmt.Sprintf("\n\n%s\n", dateStyle.Render(date.Format("2006/01/02")))
+ content += fmt.Sprintf("\n\n%s\n", dateStyle.Render(date.Format("Mon 2006/01/02")))
}
style := summaryItemStyle
@@ -249,7 +296,7 @@ func (m HistoryBoxModel) selectedEntries() []queries.TimeEntry {
// renderDetailsView renders the details view (level 2) showing individual entries
func (m HistoryBoxModel) renderDetailsView(timer TimerBoxModel) string {
- content := fmt.Sprintf("📝 Details: %s\n\n", m.formatSummaryTitle(m.summaryItems[m.summarySelection]))
+ content := titleStyle.Render(fmt.Sprintf("📝 Details: %s", m.formatSummaryTitle(m.summaryItems[m.summarySelection]))) + "\n\n"
entries := m.selectedEntries()
if len(entries) == 0 {
@@ -315,7 +362,7 @@ func (m HistoryBoxModel) formatSummaryTitle(summary HistorySummaryItem) string {
if summary.ProjectID != nil {
return fmt.Sprintf("%s / %s", summary.ClientName, *summary.ProjectName)
}
- return fmt.Sprintf("%s / General work", summary.ClientName)
+ return fmt.Sprintf("%s", summary.ClientName)
}
func dateOnly(t time.Time) time.Time {