summary refs log tree commit diff stats
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
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.
-rw-r--r--lib/msgstore.go12
-rw-r--r--widgets/msglist.go6
2 files changed, 14 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()
+		}
 	})
 }
 
diff --git a/widgets/msglist.go b/widgets/msglist.go
index 51c133c..59abf59 100644
--- a/widgets/msglist.go
+++ b/widgets/msglist.go
@@ -63,6 +63,12 @@ func (ml *MessageList) Draw(ctx *ui.Context) {
 		}
 	}
 
+	if store.Sorting {
+		ml.spinner.Start()
+		ml.spinner.Draw(ctx)
+		return
+	}
+
 	var (
 		needsHeaders []uint32
 		row          int = 0
n209'>209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473