From 0bcd92459f68dece081368b6a3c75a18573f1152 Mon Sep 17 00:00:00 2001 From: Micah Morrison Date: Wed, 27 Nov 2024 12:41:44 -0500 Subject: [PATCH] Highlight last tapped post on feed (#1525) --- lib/community/widgets/post_card.dart | 7 +++++++ lib/community/widgets/post_card_view_comfortable.dart | 8 +++++++- lib/community/widgets/post_card_view_compact.dart | 8 +++++++- lib/feed/widgets/feed_post_card_list.dart | 5 +++++ lib/moderator/view/report_page.dart | 1 + lib/settings/pages/post_appearance_settings_page.dart | 2 ++ 6 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/community/widgets/post_card.dart b/lib/community/widgets/post_card.dart index b8b133eea..8d606164e 100644 --- a/lib/community/widgets/post_card.dart +++ b/lib/community/widgets/post_card.dart @@ -25,6 +25,7 @@ class PostCard extends StatefulWidget { final PostViewMedia postViewMedia; final FeedType? feedType; final bool indicateRead; + final bool isLastTapped; final Function(int) onVoteAction; final Function(bool) onSaveAction; @@ -32,6 +33,7 @@ class PostCard extends StatefulWidget { final Function(bool) onHideAction; final Function(double) onUpAction; final Function() onDownAction; + final Function() onTap; final ListingType? listingType; @@ -45,8 +47,10 @@ class PostCard extends StatefulWidget { required this.onHideAction, required this.onUpAction, required this.onDownAction, + required this.onTap, required this.listingType, required this.indicateRead, + required this.isLastTapped, }); @override @@ -239,6 +243,7 @@ class _PostCardState extends State { navigateToPost: ({PostViewMedia? postViewMedia}) async => await navigateToPost(context, postViewMedia: widget.postViewMedia), indicateRead: widget.indicateRead, showMedia: !state.hideThumbnails, + isLastTapped: widget.isLastTapped, ) : PostCardViewComfortable( postViewMedia: widget.postViewMedia, @@ -261,6 +266,7 @@ class _PostCardState extends State { listingType: widget.listingType, navigateToPost: ({PostViewMedia? postViewMedia}) async => await navigateToPost(context, postViewMedia: widget.postViewMedia), indicateRead: widget.indicateRead, + isLastTapped: widget.isLastTapped, ), onLongPress: () => showPostActionBottomModalSheet( context, @@ -294,6 +300,7 @@ class _PostCardState extends State { }, ), onTap: () async { + widget.onTap.call(); PostView postView = widget.postViewMedia.postView; if (postView.read == false && isUserLoggedIn) context.read().add(FeedItemActionedEvent(postId: postView.post.id, postAction: PostAction.read, value: true)); return await navigateToPost(context, postViewMedia: widget.postViewMedia); diff --git a/lib/community/widgets/post_card_view_comfortable.dart b/lib/community/widgets/post_card_view_comfortable.dart index 656e1da8c..f55df58d6 100644 --- a/lib/community/widgets/post_card_view_comfortable.dart +++ b/lib/community/widgets/post_card_view_comfortable.dart @@ -46,6 +46,7 @@ class PostCardViewComfortable extends StatelessWidget { final ListingType? listingType; final void Function({PostViewMedia? postViewMedia})? navigateToPost; final bool? indicateRead; + final bool isLastTapped; const PostCardViewComfortable({ super.key, @@ -68,6 +69,7 @@ class PostCardViewComfortable extends StatelessWidget { required this.markPostReadOnMediaView, required this.listingType, this.indicateRead, + required this.isLastTapped, this.navigateToPost, }); @@ -105,7 +107,11 @@ class PostCardViewComfortable extends StatelessWidget { final bool darkTheme = context.read().state.useDarkTheme; return Container( - color: indicateRead && postViewMedia.postView.read ? theme.colorScheme.onSurface.withOpacity(darkTheme ? 0.05 : 0.075) : null, + color: isLastTapped + ? theme.colorScheme.primary.withOpacity(0.15) + : indicateRead && postViewMedia.postView.read + ? theme.colorScheme.onSurface.withOpacity(darkTheme ? 0.05 : 0.075) + : null, padding: const EdgeInsets.symmetric(vertical: 12.0), child: Column( mainAxisAlignment: MainAxisAlignment.start, diff --git a/lib/community/widgets/post_card_view_compact.dart b/lib/community/widgets/post_card_view_compact.dart index 333e54e10..07b31a8de 100644 --- a/lib/community/widgets/post_card_view_compact.dart +++ b/lib/community/widgets/post_card_view_compact.dart @@ -26,6 +26,7 @@ class PostCardViewCompact extends StatelessWidget { final void Function({PostViewMedia? postViewMedia})? navigateToPost; final bool? indicateRead; final bool showMedia; + final bool isLastTapped; const PostCardViewCompact({ super.key, @@ -36,6 +37,7 @@ class PostCardViewCompact extends StatelessWidget { this.navigateToPost, this.indicateRead, this.showMedia = true, + required this.isLastTapped, }); @override @@ -59,7 +61,11 @@ class PostCardViewCompact extends StatelessWidget { final bool darkTheme = context.read().state.useDarkTheme; return Container( - color: indicateRead && postViewMedia.postView.read ? theme.colorScheme.onSurface.withOpacity(darkTheme ? 0.05 : 0.075) : null, + color: isLastTapped + ? theme.colorScheme.primary.withOpacity(0.15) + : indicateRead && postViewMedia.postView.read + ? theme.colorScheme.onSurface.withOpacity(darkTheme ? 0.05 : 0.075) + : null, padding: showMedia ? const EdgeInsets.only(bottom: 8.0, top: 6) : const EdgeInsets.only(left: 4.0, top: 10.0, bottom: 10.0), child: Row( crossAxisAlignment: CrossAxisAlignment.center, diff --git a/lib/feed/widgets/feed_post_card_list.dart b/lib/feed/widgets/feed_post_card_list.dart index 56046c60f..5f7448e0b 100644 --- a/lib/feed/widgets/feed_post_card_list.dart +++ b/lib/feed/widgets/feed_post_card_list.dart @@ -61,6 +61,9 @@ class _FeedPostCardListState extends State { /// Timer for debouncing the read action Timer? debounceTimer; + /// The ID of the last post that the user tapped or navigated into + int? lastTappedPost; + @override void dispose() { debounceTimer?.cancel(); @@ -160,8 +163,10 @@ class _FeedPostCardListState extends State { isScrollingDown = updatedIsScrollingDown; } }, + onTap: () => setState(() => lastTappedPost = widget.postViewMedias[index].postView.post.id), listingType: state.postListingType, indicateRead: dimReadPosts, + isLastTapped: lastTappedPost == widget.postViewMedias[index].postView.post.id, )) : null, ); diff --git a/lib/moderator/view/report_page.dart b/lib/moderator/view/report_page.dart index 128223009..738d60377 100644 --- a/lib/moderator/view/report_page.dart +++ b/lib/moderator/view/report_page.dart @@ -231,6 +231,7 @@ class _ReportFeedViewState extends State { feedType: FeedType.general, isUserLoggedIn: false, listingType: ListingType.all, + isLastTapped: false, ), ), ), diff --git a/lib/settings/pages/post_appearance_settings_page.dart b/lib/settings/pages/post_appearance_settings_page.dart index 6294c9c83..bd6829b1a 100644 --- a/lib/settings/pages/post_appearance_settings_page.dart +++ b/lib/settings/pages/post_appearance_settings_page.dart @@ -513,6 +513,7 @@ class _PostAppearanceSettingsPageState extends State isUserLoggedIn: true, listingType: ListingType.all, indicateRead: dimReadPosts, + isLastTapped: false, ), ) : IgnorePointer( @@ -536,6 +537,7 @@ class _PostAppearanceSettingsPageState extends State showTextContent: showTextContent, onVoteAction: (voteType) {}, onSaveAction: (saved) {}, + isLastTapped: false, ), ), const FeedCardDivider(),