Compare commits

..

No commits in common. "08a202733244dc400a2e2d9ca0eb6df82404c522" and "69d3265b640b72164db150135e3f04384e37ec30" have entirely different histories.

View File

@ -175,14 +175,24 @@ func (m *conversationsModel) headerView() string {
} }
func (m *conversationsModel) renderConversationList() 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() now := time.Now()
midnight := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) 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()) monthStart := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
dayOfWeek := int(now.Weekday()) dayOfWeek := int(now.Weekday())
categories := []struct { categories := []timeCategory{
name string
cutoff time.Duration
}{
{"Today", now.Sub(midnight)}, {"Today", now.Sub(midnight)},
{"Yesterday", now.Sub(midnight.AddDate(0, 0, -1))}, {"Yesterday", now.Sub(midnight.AddDate(0, 0, -1))},
{"This week", now.Sub(midnight.AddDate(0, 0, -dayOfWeek))}, {"This week", now.Sub(midnight.AddDate(0, 0, -dayOfWeek))},
@ -199,7 +209,7 @@ func (m *conversationsModel) renderConversationList() string {
categoryStyle := lipgloss.NewStyle(). categoryStyle := lipgloss.NewStyle().
MarginBottom(1). MarginBottom(1).
Foreground(lipgloss.Color("12")). Foreground(lipgloss.Color("170")).
PaddingLeft(1). PaddingLeft(1).
Bold(true) Bold(true)
@ -211,16 +221,12 @@ func (m *conversationsModel) renderConversationList() string {
untitledStyle := lipgloss.NewStyle().Faint(true).Italic(true) untitledStyle := lipgloss.NewStyle().Faint(true).Italic(true)
selectedStyle := lipgloss.NewStyle().Faint(true).Foreground(lipgloss.Color("6")) selectedStyle := lipgloss.NewStyle().Faint(true).Foreground(lipgloss.Color("6"))
var ( var currentOffset int
currentOffset int var currentCategory string
currentCategory string
sb strings.Builder
)
m.itemOffsets = make([]int, len(m.conversations)) m.itemOffsets = make([]int, len(m.conversations))
sb := &strings.Builder{}
sb.WriteRune('\n') sb.WriteRune('\n')
currentOffset += 1 currentOffset += 1
for i, c := range m.conversations { for i, c := range m.conversations {
lastReplyAge := now.Sub(c.lastReply.CreatedAt) lastReplyAge := now.Sub(c.lastReply.CreatedAt)
@ -242,6 +248,7 @@ func (m *conversationsModel) renderConversationList() string {
} }
tStyle := titleStyle.Copy() tStyle := titleStyle.Copy()
padding := " "
if c.conv.Title == "" { if c.conv.Title == "" {
tStyle = tStyle.Inherit(untitledStyle).SetString("(untitled)") tStyle = tStyle.Inherit(untitledStyle).SetString("(untitled)")
} }
@ -256,9 +263,9 @@ func (m *conversationsModel) renderConversationList() string {
m.itemOffsets[i] = currentOffset m.itemOffsets[i] = currentOffset
item := itemStyle.Render(fmt.Sprintf( item := itemStyle.Render(fmt.Sprintf(
"%s\n %s", "%s\n%s",
title, title,
ageStyle.Render(util.HumanTimeElapsedSince(lastReplyAge)), padding+ageStyle.Render(util.HumanTimeElapsedSince(lastReplyAge)),
)) ))
sb.WriteString(item) sb.WriteString(item)
currentOffset += height(item) currentOffset += height(item)