tui: cleanup

This commit is contained in:
Matt Low 2024-04-03 07:10:41 +00:00
parent b06e031ee0
commit 08a2027332

View File

@ -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)