Skip to content

Commit 5380574

Browse files
committed
store: Add field for tracking loading status.
When an error occurs to a getEvents call, there isn't a visual indicator for the retry attempts. This prepares the data model for the feature. Signed-off-by: Zixuan James Li <[email protected]>
1 parent fff2d8d commit 5380574

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

lib/model/store.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,15 @@ class PerAccountStore extends ChangeNotifier with ChannelStore, MessageStore {
297297
final GlobalStore _globalStore;
298298
final ApiConnection connection; // TODO(#135): update zulipFeatureLevel with events
299299

300+
bool get isLoading => _isLoading;
301+
bool _isLoading = false;
302+
@visibleForTesting
303+
set isLoading(bool value) {
304+
if (_isLoading == value) return;
305+
_isLoading = value;
306+
notifyListeners();
307+
}
308+
300309
////////////////////////////////
301310
// Data attached to the realm or the server.
302311

@@ -770,6 +779,7 @@ class UpdateMachine {
770779
result = await getEvents(store.connection,
771780
queueId: queueId, lastEventId: lastEventId);
772781
} catch (e) {
782+
store.isLoading = true;
773783
switch (e) {
774784
case ZulipApiException(code: 'BAD_EVENT_QUEUE_ID'):
775785
assert(debugLog('Lost event queue for $store. Replacing…'));
@@ -797,6 +807,7 @@ class UpdateMachine {
797807
}
798808
}
799809

810+
store.isLoading = false;
800811
final events = result.events;
801812
for (final event in events) {
802813
await store.handleEvent(event);

test/model/store_checks.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extension GlobalStoreChecks on Subject<GlobalStore> {
2828

2929
extension PerAccountStoreChecks on Subject<PerAccountStore> {
3030
Subject<ApiConnection> get connection => has((x) => x.connection, 'connection');
31+
Subject<bool> get isLoading => has((x) => x.isLoading, 'isLoading');
3132
Subject<Uri> get realmUrl => has((x) => x.realmUrl, 'realmUrl');
3233
Subject<String> get zulipVersion => has((x) => x.zulipVersion, 'zulipVersion');
3334
Subject<int> get maxFileUploadSizeMib => has((x) => x.maxFileUploadSizeMib, 'maxFileUploadSizeMib');

test/model/store_test.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,12 @@ void main() {
406406
updateMachine.debugAdvanceLoop();
407407
async.flushMicrotasks();
408408
await Future<void>.delayed(Duration.zero);
409+
check(store).isLoading.isTrue();
409410

410411
// The global store has a new store.
411412
check(globalStore.perAccountSync(store.accountId)).not((it) => it.identicalTo(store));
412413
updateFromGlobalStore();
414+
check(store).isLoading.isFalse();
413415

414416
// The new UpdateMachine updates the new store.
415417
updateMachine.debugPauseLoop();
@@ -435,8 +437,9 @@ void main() {
435437
// Make the request, inducing an error in it.
436438
prepareError();
437439
updateMachine.debugAdvanceLoop();
438-
async.flushMicrotasks();
440+
async.elapse(Duration.zero);
439441
checkLastRequest(lastEventId: 1);
442+
check(store).isLoading.isTrue();
440443

441444
// Polling doesn't resume immediately; there's a timer.
442445
check(async.pendingTimers).length.equals(1);
@@ -452,6 +455,7 @@ void main() {
452455
async.flushTimers();
453456
checkLastRequest(lastEventId: 1);
454457
check(updateMachine.lastEventId).equals(2);
458+
check(store).isLoading.isFalse();
455459
});
456460
}
457461

0 commit comments

Comments
 (0)