Skip to content

Commit

Permalink
Highlight last tapped post on feed (#1525)
Browse files Browse the repository at this point in the history
  • Loading branch information
micahmo authored Nov 27, 2024
1 parent c5a4c6b commit 0bcd924
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/community/widgets/post_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ class PostCard extends StatefulWidget {
final PostViewMedia postViewMedia;
final FeedType? feedType;
final bool indicateRead;
final bool isLastTapped;

final Function(int) onVoteAction;
final Function(bool) onSaveAction;
final Function(bool) onReadAction;
final Function(bool) onHideAction;
final Function(double) onUpAction;
final Function() onDownAction;
final Function() onTap;

final ListingType? listingType;

Expand All @@ -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
Expand Down Expand Up @@ -239,6 +243,7 @@ class _PostCardState extends State<PostCard> {
navigateToPost: ({PostViewMedia? postViewMedia}) async => await navigateToPost(context, postViewMedia: widget.postViewMedia),
indicateRead: widget.indicateRead,
showMedia: !state.hideThumbnails,
isLastTapped: widget.isLastTapped,
)
: PostCardViewComfortable(
postViewMedia: widget.postViewMedia,
Expand All @@ -261,6 +266,7 @@ class _PostCardState extends State<PostCard> {
listingType: widget.listingType,
navigateToPost: ({PostViewMedia? postViewMedia}) async => await navigateToPost(context, postViewMedia: widget.postViewMedia),
indicateRead: widget.indicateRead,
isLastTapped: widget.isLastTapped,
),
onLongPress: () => showPostActionBottomModalSheet(
context,
Expand Down Expand Up @@ -294,6 +300,7 @@ class _PostCardState extends State<PostCard> {
},
),
onTap: () async {
widget.onTap.call();
PostView postView = widget.postViewMedia.postView;
if (postView.read == false && isUserLoggedIn) context.read<FeedBloc>().add(FeedItemActionedEvent(postId: postView.post.id, postAction: PostAction.read, value: true));
return await navigateToPost(context, postViewMedia: widget.postViewMedia);
Expand Down
8 changes: 7 additions & 1 deletion lib/community/widgets/post_card_view_comfortable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -68,6 +69,7 @@ class PostCardViewComfortable extends StatelessWidget {
required this.markPostReadOnMediaView,
required this.listingType,
this.indicateRead,
required this.isLastTapped,
this.navigateToPost,
});

Expand Down Expand Up @@ -105,7 +107,11 @@ class PostCardViewComfortable extends StatelessWidget {
final bool darkTheme = context.read<ThemeBloc>().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,
Expand Down
8 changes: 7 additions & 1 deletion lib/community/widgets/post_card_view_compact.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -36,6 +37,7 @@ class PostCardViewCompact extends StatelessWidget {
this.navigateToPost,
this.indicateRead,
this.showMedia = true,
required this.isLastTapped,
});

@override
Expand All @@ -59,7 +61,11 @@ class PostCardViewCompact extends StatelessWidget {
final bool darkTheme = context.read<ThemeBloc>().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,
Expand Down
5 changes: 5 additions & 0 deletions lib/feed/widgets/feed_post_card_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class _FeedPostCardListState extends State<FeedPostCardList> {
/// 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();
Expand Down Expand Up @@ -160,8 +163,10 @@ class _FeedPostCardListState extends State<FeedPostCardList> {
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,
);
Expand Down
1 change: 1 addition & 0 deletions lib/moderator/view/report_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ class _ReportFeedViewState extends State<ReportFeedView> {
feedType: FeedType.general,
isUserLoggedIn: false,
listingType: ListingType.all,
isLastTapped: false,
),
),
),
Expand Down
2 changes: 2 additions & 0 deletions lib/settings/pages/post_appearance_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>
isUserLoggedIn: true,
listingType: ListingType.all,
indicateRead: dimReadPosts,
isLastTapped: false,
),
)
: IgnorePointer(
Expand All @@ -536,6 +537,7 @@ class _PostAppearanceSettingsPageState extends State<PostAppearanceSettingsPage>
showTextContent: showTextContent,
onVoteAction: (voteType) {},
onSaveAction: (saved) {},
isLastTapped: false,
),
),
const FeedCardDivider(),
Expand Down

0 comments on commit 0bcd924

Please sign in to comment.