Skip to content

Commit

Permalink
Handle errors with navigation to non-instances (#1076)
Browse files Browse the repository at this point in the history
  • Loading branch information
micahmo authored Jan 22, 2024
1 parent 1dad7b6 commit 80f5eb1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
4 changes: 4 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,10 @@
"@unableToLoadPostsFrominstance": {},
"unableToLoadReplies": "Unable to load more replies.",
"@unableToLoadReplies": {},
"unableToNavigateToInstance": "Unable to navigate to {instanceHost}. It may not be a valid Lemmy instance.",
"@unableToNavigateToInstance": {
"description": "Error message for when we can't navigate to a Lemmy instance"
},
"unblockInstance": "Unblock Instance",
"@unblockInstance": {
"description": "Tooltip for unblocking an instance"
Expand Down
40 changes: 24 additions & 16 deletions lib/utils/navigate_instance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lemmy_api_client/v3.dart';
import 'package:swipeable_page_route/swipeable_page_route.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import 'package:thunder/account/models/account.dart';
import 'package:thunder/core/auth/helpers/fetch_account.dart';
import 'package:thunder/core/singletons/lemmy_client.dart';
import 'package:thunder/instance/instance_page.dart';
import 'package:thunder/shared/snackbar.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';

Future<void> navigateToInstancePage(BuildContext context, {required String instanceHost, required int? instanceId}) async {
final AppLocalizations l10n = AppLocalizations.of(context)!;

ThunderBloc thunderBloc = context.read<ThunderBloc>();

final bool reduceAnimations = thunderBloc.state.reduceAnimations;
Expand All @@ -27,23 +31,27 @@ Future<void> navigateToInstancePage(BuildContext context, {required String insta
isBlocked = localSite.myUser?.instanceBlocks?.any((i) => i.instance.domain == instanceHost) == true;
} catch (e) {}

if (getSiteResponse?.siteView.site != null && context.mounted) {
Navigator.of(context).push(
SwipeablePageRoute(
transitionDuration: reduceAnimations ? const Duration(milliseconds: 100) : null,
backGestureDetectionWidth: 45,
canOnlySwipeFromEdge: !thunderBloc.state.enableFullScreenSwipeNavigationGesture,
builder: (context) => MultiBlocProvider(
providers: [
BlocProvider.value(value: thunderBloc),
],
child: InstancePage(
getSiteResponse: getSiteResponse!,
isBlocked: isBlocked,
instanceId: instanceId,
if (context.mounted) {
if (getSiteResponse?.siteView.site != null) {
Navigator.of(context).push(
SwipeablePageRoute(
transitionDuration: reduceAnimations ? const Duration(milliseconds: 100) : null,
backGestureDetectionWidth: 45,
canOnlySwipeFromEdge: !thunderBloc.state.enableFullScreenSwipeNavigationGesture,
builder: (context) => MultiBlocProvider(
providers: [
BlocProvider.value(value: thunderBloc),
],
child: InstancePage(
getSiteResponse: getSiteResponse!,
isBlocked: isBlocked,
instanceId: instanceId,
),
),
),
),
);
);
} else {
showSnackbar(context, l10n.unableToNavigateToInstance(instanceHost));
}
}
}

0 comments on commit 80f5eb1

Please sign in to comment.