diff --git a/frontend/lib/api/api_status_provider.dart b/frontend/lib/api/api_status_provider.dart index efa72487..546fa67d 100644 --- a/frontend/lib/api/api_status_provider.dart +++ b/frontend/lib/api/api_status_provider.dart @@ -43,6 +43,10 @@ class ApiStatus extends _$ApiStatus { Future _updateStatus() async { state = await AsyncValue.guard(() => _checkBackendStatus()); } + + Future updateStatus(bool isOnline) async { + state = AsyncValue.data(isOnline); + } } // @riverpod diff --git a/frontend/lib/recipes/controller/edit_controller.dart b/frontend/lib/recipes/controller/edit_controller.dart index db49ae63..64a8a9d4 100644 --- a/frontend/lib/recipes/controller/edit_controller.dart +++ b/frontend/lib/recipes/controller/edit_controller.dart @@ -8,8 +8,10 @@ import 'package:go_router/go_router.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:sqflite/sqflite.dart'; import 'package:zest/api/api_service.dart'; +import 'package:zest/api/api_status_provider.dart'; import 'package:zest/main.dart'; import 'package:zest/recipes/controller/draft_controller.dart'; +import 'package:zest/recipes/screens/recipe_search.dart'; import 'package:zest/settings/settings_provider.dart'; import 'package:zest/utils/utils.dart'; @@ -217,7 +219,11 @@ class RecipeEditController extends _$RecipeEditController { // TODO: onconfirm ); } else if (categories.error is ServerNotReachableException) { - openServerNotAvailableDialog(); + openServerNotAvailableDialog(onPressed: () { + ref.read(apiStatusProvider.notifier).updateStatus(false); + shellNavigatorKey.currentState!.overlay!.context + .goNamed(RecipeSearchPage.routeName); + }); } } // express the list as a map diff --git a/frontend/lib/ui/main_scaffold.dart b/frontend/lib/ui/main_scaffold.dart index e0b2b5e5..9866df01 100644 --- a/frontend/lib/ui/main_scaffold.dart +++ b/frontend/lib/ui/main_scaffold.dart @@ -49,7 +49,7 @@ class MainScaffold extends ConsumerWidget { appBar: AppBar( backgroundColor: Theme.of(context).colorScheme.primary, title: backendStatus.value ?? false - ? const Text("Online") + ? Container() : Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -71,9 +71,11 @@ class MainScaffold extends ConsumerWidget { IconButton( icon: const Icon( key: Key("appbar_addrecipe_icon"), Icons.add_card_rounded), - onPressed: () { - context.goNamed(RecipeEditPage.routeNameCreate); - }, + onPressed: (backendStatus.value ?? false) + ? () { + context.goNamed(RecipeEditPage.routeNameCreate); + } + : null, ), if (isAuthenticated) IconButton( diff --git a/frontend/lib/utils/networking.dart b/frontend/lib/utils/networking.dart index 412edf0d..dc880b23 100644 --- a/frontend/lib/utils/networking.dart +++ b/frontend/lib/utils/networking.dart @@ -131,7 +131,7 @@ class ResourceNotFoundInterceptor extends InterceptorContract { case 400: throw BadRequestException(); case 500: - throw Exception("Server error"); + throw ServerNotReachableException(); // "Internal Server Error [500]" } return response; }