Skip to content

Add a loading indicator for PerAccountStore #852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 9, 2024
Merged

Conversation

PIG208
Copy link
Member

@PIG208 PIG208 commented Jul 30, 2024

Preview
isLoading=false isLoading=true
image image
image image

Fixes #465.

@PIG208 PIG208 added the maintainer review PR ready for review by Zulip maintainers label Jul 30, 2024
@@ -295,6 +295,15 @@ class PerAccountStore extends ChangeNotifier with ChannelStore, MessageStore {
final GlobalStore _globalStore;
final ApiConnection connection; // TODO(#135): update zulipFeatureLevel with events

bool get isLoading => _isLoading;
bool _isLoading = false;
@visibleForTesting
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful for a widget test added later.

await store.addUser(eg.selfUser);

await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
child: ProfilePage(userId: eg.selfUser.userId)));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intentionally only test this with one of the many call sites. This test does not prevent the bug where a new page is added without ZulipAppBar, as we don't have a way to exhaustively list pages that have access to a PerAccountStoreWidget yet.

@PIG208 PIG208 requested a review from chrisbobbe July 30, 2024 22:10
@chrisbobbe
Copy link
Collaborator

Looks like CI is failing; could you fix that please?

@PIG208
Copy link
Member Author

PIG208 commented Jul 31, 2024

Oops, just pushed again to fix that.

Copy link
Collaborator

@chrisbobbe chrisbobbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I'm curious if you explored an approach with a toast: #465 (comment)

Would it be easy to put some code in one central place, ensuring that a toast showing the org's name is visible for each account in the loading state? (E.g., for CZO: "Connecting to Zulip Community…")

Or, a refinement (that could be annoying to implement): filter that list of toasts down to the account corresponding to the foregrounded screen, and no need to show the org's name.

In the screenshots, I'm noticing the color isn't a great match for the app bar, and the split between the app bar and the sticky recipient header is looking kind of awkward.

If we're going with this linear-indicator approach, let's definitely track that it's missing on the lightbox screen, which needs it because it's a per-account screen too.

Comment on lines 262 to 265
: null, // i.e., inherit
),
: null),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this comment. A reader might see null and think it means there's no bottom border. That would be wrong; what null actually does is make the app bar inherit its bottom border from the AppBarTheme.

@PIG208
Copy link
Member Author

PIG208 commented Jul 31, 2024

Thanks for the review! I didn't experiment with Toast. It sounds like another viable option.

Could you elaborate on this?

Or, a refinement (that could be annoying to implement): filter that list of toasts down to the account corresponding to the foregrounded screen, and no need to show the org's name.

Visually, matching the background color should be fairly simple, because LinearProgressIndicator is shipped with the app bar (this doesn't address the lightbox issue with its app bar, though).

diff --git lib/widgets/app_bar.dart lib/widgets/app_bar.dart
index da49a639..a1c4645b 100644
--- lib/widgets/app_bar.dart
+++ lib/widgets/app_bar.dart
@@ -12,6 +12,6 @@ class ZulipAppBar extends AppBar {
     bottom: PreferredSize(
       preferredSize: const Size.fromHeight(4.0),
       child: (isLoading)
-        ? const LinearProgressIndicator(minHeight: 4.0)
+        ? LinearProgressIndicator(backgroundColor: backgroundColor, minHeight: 4.0)
         : const SizedBox.shrink()));
 }

@PIG208
Copy link
Member Author

PIG208 commented Aug 1, 2024

Do we have a toast library in mind to use? Or are we writing one from scratch? Looks like SnackBar is the official implementation.

@gnprice
Copy link
Member

gnprice commented Aug 1, 2024

@gnprice
Copy link
Member

gnprice commented Aug 1, 2024

If we're going with this linear-indicator approach, let's definitely track that it's missing on the lightbox screen, which needs it because it's a per-account screen too.

I think it's actually fine to not have the indicator on the lightbox screen. Critically, there's very little there to get live-updated — even if you're looking at stale data there and you think it's up to date, it's hard to get misled about much as a result. In particular it never gets updated by a new message arriving.

It should definitely get a comment saying we've chosen not to put the indicator there, though, and why.

@chrisbobbe
Copy link
Collaborator

Sure, I guess that all makes sense.

@chrisbobbe
Copy link
Collaborator

chrisbobbe commented Aug 2, 2024

So the current revision is close to what we want, right? Is this the only thing missing:

It should definitely get a comment saying we've chosen not to put the indicator there, though, and why.

?

@PIG208
Copy link
Member Author

PIG208 commented Aug 2, 2024

Right, will update this later.

@PIG208
Copy link
Member Author

PIG208 commented Aug 2, 2024

Updated the PR to mention the ZulipAppBar exceptions in comments after its dart doc.

@PIG208
Copy link
Member Author

PIG208 commented Aug 5, 2024

Updated the PR to handle isLoading when there are transient connection errors.

@chrisbobbe
Copy link
Collaborator

Thanks! LGTM, over to Greg for his review.

@chrisbobbe chrisbobbe added integration review Added by maintainers when PR may be ready for integration and removed maintainer review PR ready for review by Zulip maintainers labels Aug 6, 2024
@PIG208
Copy link
Member Author

PIG208 commented Aug 8, 2024

(Rebased the PR)

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @PIG208, and thanks @chrisbobbe for the previous reviews!

Generally this looks good. I also put a build with this PR (among others) onto my phone last week before going on vacation, and the behavior was very helpful.

A couple of small comments below. I've also pushed some additional commits on top:
c384847 wip squash? plain AppBar where isLoading always false
667adf8 app_bar [nfc]: Move ZulipAppBar.isLoading to within widget
a6965aa app_bar [nfc]: Explain why the lightbox skips ZulipAppBar

The first one reflects one comment, and can be squashed; I added it just because that change is needed for the next commit.

Comment on lines 183 to 186
appBar: ZulipAppBar(
title: Text(zulipLocalizations.chooseAccountPageTitle),
actions: const [ChooseAccountPageOverflowButton()]),
actions: const [ChooseAccountPageOverflowButton()],
isLoading: false),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just AppBar, if we're going to hard-code isLoading here to false?

Comment on lines 163 to 166
appBar: AppBar(title: const Text('Inbox')),
appBar: ZulipAppBar(
title: const Text('Inbox'),
isLoading: store.isLoading),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this pattern can be simplified. I'll push a separate commit on top to do so.

PIG208 added 2 commits August 9, 2024 18:37
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]>
Ideally we may have test to exhaustively ensure that all pages
specific to a single PerAccountStore use ZulipAppBar.

Some pages with `AppBar`s are skipped, such as AboutZulip (no
PerAccountStore access) and lightboxes (progress indicator is occupied
for other purposes, and the AppBar can be hidden).

Fixes zulip#465.
gnprice added 2 commits August 9, 2024 18:38
Just listing that there is an exception doesn't help much to provide
guidance for someone writing a new page on whether they should also
skip ZulipAppBar there.  The "why" is much more helpful for that.

Right at the call site is also more helpful than at the definition
of ZulipAppBar, because the call site is the place someone will
definitely be looking if they're contemplating whether this
deviation from the pattern is appropriate, a mistake, or just an
oversight.
@PIG208
Copy link
Member Author

PIG208 commented Aug 9, 2024

Thanks! Rebased the PR and squashed the commit.

@gnprice
Copy link
Member

gnprice commented Aug 9, 2024

Looks good! Thanks for the revision — merging.

@gnprice gnprice merged commit 1fb76ac into zulip:main Aug 9, 2024
1 check passed
@PIG208 PIG208 deleted the connection branch August 12, 2024 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration review Added by maintainers when PR may be ready for integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show "Connecting…" banner (or equivalent) when server data is stale
3 participants