summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorJeffas <dev@jeffas.io>2020-02-29 02:50:11 +0000
committerDrew DeVault <sir@cmpwn.com>2020-02-28 22:06:01 -0500
commitb55813f2c0e96e0350473d96dc2dd82f0544ea8f (patch)
tree574d898f3912bf577ed41ca28445fa390a56d5e2 /lib
parent2a0430ab90bdcb03d3f3243945280f29642faab0 (diff)
downloadaerc-b55813f2c0e96e0350473d96dc2dd82f0544ea8f.tar.gz
Don't show empty message while sorting
This changes the ui to show the spinner while we are sorting. It only
shows one line of the spinner since there are an unknown number of
messages at this time.
Diffstat (limited to 'lib')
-rw-r--r--lib/msgstore.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go
index b1785c1..709c7a2 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -14,6 +14,8 @@ type MessageStore struct {
 	Deleted  map[uint32]interface{}
 	DirInfo  models.DirectoryInfo
 	Messages map[uint32]*models.MessageInfo
+	Sorting  bool
+
 	// Ordered list of known UIDs
 	uids []uint32
 
@@ -185,9 +187,7 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
 	switch msg := msg.(type) {
 	case *types.DirectoryInfo:
 		store.DirInfo = *msg.Info
-		store.worker.PostAction(&types.FetchDirectoryContents{
-			SortCriteria: store.defaultSortCriteria,
-		}, nil)
+		store.Sort(store.defaultSortCriteria, nil)
 		update = true
 	case *types.DirectoryContents:
 		newMap := make(map[uint32]*models.MessageInfo)
@@ -599,10 +599,14 @@ func (store *MessageStore) ModifyLabels(uids []uint32, add, remove []string,
 }
 
 func (store *MessageStore) Sort(criteria []*types.SortCriterion, cb func()) {
+	store.Sorting = true
 	store.worker.PostAction(&types.FetchDirectoryContents{
 		SortCriteria: criteria,
 	}, func(msg types.WorkerMessage) {
-		cb()
+		store.Sorting = false
+		if cb != nil {
+			cb()
+		}
 	})
 }