diff --git a/main.go b/main.go index d8a07076b7fec9d380afc91fc6379d72480fa627..6f7c79324a9271e0965d62948275e01fbc9bbcae 100644 --- a/main.go +++ b/main.go @@ -63,10 +63,10 @@ type mainModel struct { config *config.Config emails []fetcher.Email emailsByAcct map[string][]fetcher.Email - sentEmails []fetcher.Email - sentByAcct map[string][]fetcher.Email + sentEmails []fetcher.Email + sentByAcct map[string][]fetcher.Email inbox *tui.Inbox - sentInbox *tui.Inbox + sentInbox *tui.Inbox width int height int err error @@ -263,6 +263,12 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { refreshEmails(m.config, tui.MailboxInbox), ) + case tui.RequestRefreshMsg: + return m, tea.Batch( + func() tea.Msg { return tui.RefreshingEmailsMsg{Mailbox: msg.Mailbox} }, + refreshEmails(m.config, msg.Mailbox), + ) + case tui.EmailsRefreshedMsg: if msg.Mailbox == tui.MailboxSent { m.sentByAcct = msg.EmailsByAccount diff --git a/tui/inbox.go b/tui/inbox.go index 7bd9ffa6b79758d6da838cfe1e9b31148a4586ee..29f267e0d75af2fa89f6624c68ab2828da8119d2 100644 --- a/tui/inbox.go +++ b/tui/inbox.go @@ -196,6 +196,7 @@ func (m *Inbox) updateList() { bindings := []key.Binding{ key.NewBinding(key.WithKeys("d"), key.WithHelp("d", "delete")), key.NewBinding(key.WithKeys("a"), key.WithHelp("a", "archive")), + key.NewBinding(key.WithKeys("r"), key.WithHelp("r", "refresh")), } if len(m.tabs) > 1 { bindings = append(bindings, @@ -301,6 +302,10 @@ func (m *Inbox) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return ArchiveEmailMsg{UID: selectedItem.uid, AccountID: selectedItem.accountID, Mailbox: m.mailbox} } } + case "r": + return m, func() tea.Msg { + return RequestRefreshMsg{Mailbox: m.mailbox} + } case "enter": selectedItem, ok := m.list.SelectedItem().(item) if ok { diff --git a/tui/messages.go b/tui/messages.go index bbf7507b556a32ba90bde42cdda72cb3184b67e2..3cfc52efc0144c5be7335575613ba70cb4fc0ae4 100644 --- a/tui/messages.go +++ b/tui/messages.go @@ -63,7 +63,6 @@ type GoToInboxMsg struct{} type GoToSentInboxMsg struct{} - type GoToSendMsg struct { To string Subject string @@ -254,7 +253,7 @@ type CachedEmailsLoadedMsg struct { } // RefreshingEmailsMsg signals that a background refresh is in progress. -type RefreshingEmailsMsg struct{ +type RefreshingEmailsMsg struct { Mailbox MailboxKind } @@ -263,3 +262,8 @@ type EmailsRefreshedMsg struct { EmailsByAccount map[string][]fetcher.Email Mailbox MailboxKind } + +// RequestRefreshMsg signals a request to refresh emails from the server. +type RequestRefreshMsg struct { + Mailbox MailboxKind +}