From 08a202733244dc400a2e2d9ca0eb6df82404c522 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Wed, 3 Apr 2024 07:10:41 +0000 Subject: [PATCH] tui: cleanup --- pkg/tui/conversations.go | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/pkg/tui/conversations.go b/pkg/tui/conversations.go index 938e571..7933718 100644 --- a/pkg/tui/conversations.go +++ b/pkg/tui/conversations.go @@ -175,24 +175,14 @@ func (m *conversationsModel) headerView() string { } func (m *conversationsModel) renderConversationList() string { - type timeCategory struct { - name string - cutoff time.Duration - } - - type listItem struct { - id uint - short string - title string - elapsed string - lastReplyAge time.Duration - } - now := time.Now() midnight := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) monthStart := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()) dayOfWeek := int(now.Weekday()) - categories := []timeCategory{ + categories := []struct { + name string + cutoff time.Duration + }{ {"Today", now.Sub(midnight)}, {"Yesterday", now.Sub(midnight.AddDate(0, 0, -1))}, {"This week", now.Sub(midnight.AddDate(0, 0, -dayOfWeek))}, @@ -221,12 +211,16 @@ func (m *conversationsModel) renderConversationList() string { untitledStyle := lipgloss.NewStyle().Faint(true).Italic(true) selectedStyle := lipgloss.NewStyle().Faint(true).Foreground(lipgloss.Color("6")) - var currentOffset int - var currentCategory string + var ( + currentOffset int + currentCategory string + sb strings.Builder + ) + m.itemOffsets = make([]int, len(m.conversations)) - sb := &strings.Builder{} sb.WriteRune('\n') currentOffset += 1 + for i, c := range m.conversations { lastReplyAge := now.Sub(c.lastReply.CreatedAt)