From 93fa3d3bec8d7805b4c0ad253d1a05161cd9a07f Mon Sep 17 00:00:00 2001 From: Hamlet Jiang Su Date: Wed, 5 Mar 2025 08:19:05 -0800 Subject: [PATCH 1/2] fix: navigating to post from report page crashing --- lib/utils/navigation.dart | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/utils/navigation.dart b/lib/utils/navigation.dart index 657caaef7..2e8ad9854 100644 --- a/lib/utils/navigation.dart +++ b/lib/utils/navigation.dart @@ -151,9 +151,27 @@ Future navigateToPost( final hasFeedBloc = context.findAncestorWidgetOfExactType>(); final feedBloc = hasFeedBloc != null ? context.read() : null; + PostViewMedia? pvm = postViewMedia; + + if (pvm == null) { + final client = LemmyClient.instance.lemmyApiV3; + final account = await fetchActiveProfileAccount(); + + GetPostResponse getPostResponse = await client.run( + GetPost( + auth: account?.jwt, + id: postId, + ), + ); + + List postViewMedias = await parsePostViews([getPostResponse.postView]); + + pvm = postViewMedias.first; + } + // Mark post as read when tapped if (authBloc.state.isLoggedIn) { - feedBloc?.add(FeedItemActionedEvent(postId: postViewMedia?.postView.post.id ?? postId, postAction: PostAction.read, value: true)); + feedBloc?.add(FeedItemActionedEvent(postId: pvm.postView.post.id, postAction: PostAction.read, value: true)); } final state = thunderBloc.state; @@ -183,7 +201,7 @@ Future navigateToPost( BlocProvider(create: (context) => AnonymousSubscriptionsBloc()), ], child: PostPage( - initialPostViewMedia: postViewMedia!, + initialPostViewMedia: pvm!, onPostUpdated: (PostViewMedia postViewMedia) { // Manually marking the read attribute as true when navigating to post since there is a case where the API call to mark the post as read from the feed page is not completed in time feedBloc?.add(FeedItemUpdatedEvent( From 9dfa0f170aff4902d199ad62dafd13285d0d2912 Mon Sep 17 00:00:00 2001 From: Hamlet Jiang Su Date: Wed, 5 Mar 2025 08:24:03 -0800 Subject: [PATCH 2/2] chore: remove unused code for comment navigator --- lib/shared/comment_navigator_fab.dart | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/lib/shared/comment_navigator_fab.dart b/lib/shared/comment_navigator_fab.dart index 6d3e183e4..87ccbfd29 100644 --- a/lib/shared/comment_navigator_fab.dart +++ b/lib/shared/comment_navigator_fab.dart @@ -154,13 +154,6 @@ class _CommentNavigatorFabState extends State { } void navigateToParent() { - if (widget.comments == null) { - // This is a placeholder to allow the previous post page to function correctly. - // TODO: Remove this logic when we deprecate the legacy post page - navigateUp(); - return; - } - var unobstructedVisibleRange = widget.listController.unobstructedVisibleRange; int previousIndex = (unobstructedVisibleRange?.$1 ?? 0) - 1; @@ -218,13 +211,6 @@ class _CommentNavigatorFabState extends State { } void navigateToNextParent() { - if (widget.comments == null) { - // This is a placeholder to allow the previous post page to function correctly. - // TODO: Remove this logic when we deprecate the legacy post page - navigateDown(); - return; - } - var unobstructedVisibleRange = widget.listController.unobstructedVisibleRange; int nextIndex = (unobstructedVisibleRange?.$1 ?? 0) + 1;