Skip to content
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

Offline mode behavior #645

Merged
merged 2 commits into from
Apr 30, 2024
Merged

Conversation

Silipok
Copy link

@Silipok Silipok commented Apr 21, 2024

Issue #462
In play tab:

  • disable friends button

In the bottom navigation bar:

  • disable the "watch" button
  • show a toast: "Not available in offline mode" if the watch button is tapped

@Silipok Silipok changed the title #462 Fix offline mode behavior Offline mode behavior Apr 22, 2024
@Silipok Silipok marked this pull request as draft April 24, 2024 09:04
@Silipok Silipok marked this pull request as ready for review April 24, 2024 09:04
@Silipok
Copy link
Author

Silipok commented Apr 24, 2024

@veloce If it's possible review pls.

@veloce
Copy link
Contributor

veloce commented Apr 25, 2024

I will review after #644

@veloce veloce added this to the Public beta milestone Apr 26, 2024
Copy link
Contributor

@veloce veloce left a comment

Choose a reason for hiding this comment

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

Thanks for this. It needs some changes regarding the use of riverpod API.

@@ -110,6 +117,8 @@ class BottomNavScaffold extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final currentTab = ref.watch(currentBottomTabProvider);
final connectivity = ref.watch(connectivityChangesProvider);
final isOnline = connectivity.value?.isOnline ?? false;
Copy link
Contributor

Choose a reason for hiding this comment

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

You should not assume the value is false when in loading state, I'd prefer to have true by default.

Also the connectivity is only needed for the watch tab, so instead of having the ref.watch here, it would be better to wrap the NavigationDestination with a Consumer widget so only that one rebuilds.

Copy link
Author

Choose a reason for hiding this comment

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

It's impossible cause i need this value in onDestinationSelected cb, all what can i do, it wrap NavigationBar with Consumer, but I coudn’t do it with CupertinoTabBar.

@@ -98,6 +100,11 @@ final watchScrollController = ScrollController(debugLabel: 'WatchScroll');
final RouteObserver<PageRoute<void>> rootNavPageRouteObserver =
RouteObserver<PageRoute<void>>();

final cupertinoTabControllerProvider =
Copy link
Contributor

Choose a reason for hiding this comment

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

Not really useful to declare a state provider here, you could just use a private final variable.

@@ -602,16 +602,21 @@ class _PlayerScreenButton extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final connectivity = ref.watch(connectivityChangesProvider);
final isOnline = connectivity.value?.isOnline ?? false;
Copy link
Contributor

Choose a reason for hiding this comment

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

You should not access value directly but use AsyncValue's when() method: https://pub.dev/documentation/riverpod/latest/riverpod/AsyncValue-class.html

Copy link
Author

Choose a reason for hiding this comment

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

If a consumer of an AsyncValue does not care about the loading/error state, consider using value/valueOrNull to read the state:

Do we really need error and load value here?

Copy link
Contributor

Choose a reason for hiding this comment

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

TBH I find the async value api a bit confusing. But ok we can use value here. Just I don't like it to be false by default. I'd rather assume the connectivity is on than off when we don't know it yet.

@veloce veloce merged commit 5dd6430 into lichess-org:main Apr 30, 2024
1 check passed
@veloce
Copy link
Contributor

veloce commented Apr 30, 2024

Just added a couple of tweak on top of it. Thanks!

@Silipok Silipok deleted the 462-improvements-offline-mode branch May 2, 2024 09:59
@veloce veloce mentioned this pull request May 5, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants