fix: infinite loading (#271)

Drew Smirnoff created

Change summary

main.go             |  2 +-
tui/folder_inbox.go | 12 +++++++++++-
tui/inbox.go        |  4 +++-
3 files changed, 15 insertions(+), 3 deletions(-)

Detailed changes

main.go 🔗

@@ -408,7 +408,7 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 		if msg.FolderName != "" && m.config != nil {
 			delete(m.folderEmails, msg.FolderName)
 			if m.folderInbox != nil {
-				m.folderInbox.SetLoadingEmails(true)
+				m.folderInbox.SetRefreshing(true)
 			}
 			return m, fetchFolderEmailsCmd(m.config, msg.FolderName)
 		}

tui/folder_inbox.go 🔗

@@ -178,6 +178,8 @@ func (m *FolderInbox) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 			return m, nil
 		}
 		m.isLoadingEmails = false
+		m.inbox.isFetching = false
+		m.inbox.isRefreshing = false
 		m.inbox.SetEmails(msg.Emails, m.accounts)
 		m.inbox.SetFolderName(msg.FolderName)
 		return m, nil
@@ -501,8 +503,16 @@ func (m *FolderInbox) SetLoadingEmails(loading bool) {
 	m.isLoadingEmails = loading
 	if loading {
 		m.inbox.isFetching = true
-		m.inbox.list.Title = m.inbox.getTitle()
+	} else {
+		m.inbox.isFetching = false
 	}
+	m.inbox.list.Title = m.inbox.getTitle()
+}
+
+// SetRefreshing sets the refreshing state (used when user presses "r").
+func (m *FolderInbox) SetRefreshing(refreshing bool) {
+	m.inbox.isRefreshing = refreshing
+	m.inbox.list.Title = m.inbox.getTitle()
 }
 
 // GetFolders returns the current folder list.

tui/inbox.go 🔗

@@ -449,6 +449,8 @@ func (m *Inbox) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 				}
 			}
 		case "r":
+			m.isRefreshing = true
+			m.list.Title = m.getTitle()
 			// Copy counts to avoid race conditions if used elsewhere (though here it's just passing data)
 			counts := make(map[string]int)
 			for k, v := range m.emailCountByAcct {
@@ -539,7 +541,7 @@ func (m *Inbox) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 }
 
 func (m *Inbox) shouldFetchMore() bool {
-	if m.isFetching {
+	if m.isFetching || m.isRefreshing {
 		return false
 	}
 	if m.allAccountsExhausted() {