Skip to content

Commit

Permalink
feat: show reacted users on long press add or remove reaction button
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon committed Oct 25, 2024
1 parent a9ebfe8 commit 6523900
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 72 deletions.
50 changes: 25 additions & 25 deletions lib/view/widget/note_footer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -461,25 +461,27 @@ class _AddReactionButton extends ConsumerWidget {
);

return GestureDetector(
onLongPress: note.reactionAcceptance == ReactionAcceptance.likeOnly &&
(note.reactionCount ?? 0) > 0
onLongPress: (note.reactionCount ?? 0) > 0
? () => showModalBottomSheet<void>(
context: context,
builder: (context) => ReactionUsersSheet(
account: account,
noteId: note.id,
initialReaction: '❤',
initialReaction: note.reactions.entries.fold<(String?, int)>(
(null, 0),
(acc, e) => acc.$2 < e.value ? (e.key, e.value) : acc,
).$1,
),
clipBehavior: Clip.antiAlias,
isScrollControlled: true,
)
: null,
child: IconButton(
tooltip: note.reactionAcceptance != ReactionAcceptance.likeOnly
? t.misskey.reaction
: (note.reactionCount ?? 0) <= 0
tooltip: (note.reactionCount ?? 0) <= 0
? note.reactionAcceptance == ReactionAcceptance.likeOnly
? t.misskey.like
: null,
: t.misskey.reaction
: null,
onPressed: !account.isGuest
? () async {
if (note.id.isEmpty) return;
Expand Down Expand Up @@ -557,25 +559,23 @@ class _RemoveReactionButton extends ConsumerWidget {
);

return GestureDetector(
onLongPress: note.reactionAcceptance == ReactionAcceptance.likeOnly
? () {
if (note.id.isEmpty) return;
showModalBottomSheet<void>(
context: context,
builder: (context) => ReactionUsersSheet(
account: account,
noteId: note.id,
initialReaction: '❤',
),
clipBehavior: Clip.antiAlias,
isScrollControlled: true,
);
}
: null,
onLongPress: () {
if (note.id.isEmpty) return;
showModalBottomSheet<void>(
context: context,
builder: (context) => ReactionUsersSheet(
account: account,
noteId: note.id,
initialReaction: note.reactions.entries.fold<(String?, int)>(
(null, 0),
(acc, e) => acc.$2 < e.value ? (e.key, e.value) : acc,
).$1,
),
clipBehavior: Clip.antiAlias,
isScrollControlled: true,
);
},
child: IconButton(
tooltip: note.reactionAcceptance != ReactionAcceptance.likeOnly
? t.misskey.reaction
: null,
onPressed: () async {
if (note.id.isEmpty) return;
final confirmed = await confirm(
Expand Down
49 changes: 2 additions & 47 deletions test/view/widget/note_footer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,7 @@ void main() {
expect(find.byType(ReactionUsersSheet), findsNothing);
});

testWidgets(
'should not show reacted users on long press if reacted and not like-only',
testWidgets('should show reacted users on long press if reacted',
(tester) async {
const account = Account(host: 'misskey.tld', username: 'testuser');
final note = dummyNote.copyWith(
Expand All @@ -882,27 +881,6 @@ void main() {
await tester.pumpAndSettle();
await tester.longPress(find.byIcon(Icons.add));
await tester.pumpAndSettle();
expect(find.byType(ReactionUsersSheet), findsNothing);
});

testWidgets(
'should show reacted users on long press if reacted and like-only',
(tester) async {
const account = Account(host: 'misskey.tld', username: 'testuser');
final note = dummyNote.copyWith(
id: 'test',
reactionCount: 1,
reactionAcceptance: ReactionAcceptance.likeOnly,
);
final container = await setupWidget(
tester,
account: account,
noteId: note.id,
);
container.read(notesNotifierProvider(account).notifier).add(note);
await tester.pumpAndSettle();
await tester.longPress(find.byIcon(Icons.favorite_border));
await tester.pumpAndSettle();
expect(find.byType(ReactionUsersSheet), findsOne);
});
});
Expand Down Expand Up @@ -1022,8 +1000,7 @@ void main() {
expect(find.text(t.misskey.cancelReactionConfirm), findsOne);
});

testWidgets(
'should not show reacted users on long press if reacted and not like-only',
testWidgets('should show reacted users on long press if reacted',
(tester) async {
const account = Account(host: 'misskey.tld', username: 'testuser');
final note = dummyNote.copyWith(
Expand All @@ -1040,28 +1017,6 @@ void main() {
await tester.pumpAndSettle();
await tester.longPress(find.byIcon(Icons.remove));
await tester.pumpAndSettle();
expect(find.byType(ReactionUsersSheet), findsNothing);
});

testWidgets(
'should show reacted users on long press if reacted and like-only',
(tester) async {
const account = Account(host: 'misskey.tld', username: 'testuser');
final note = dummyNote.copyWith(
id: 'test',
reactionCount: 1,
myReaction: '❤',
reactionAcceptance: ReactionAcceptance.likeOnly,
);
final container = await setupWidget(
tester,
account: account,
noteId: note.id,
);
container.read(notesNotifierProvider(account).notifier).add(note);
await tester.pumpAndSettle();
await tester.longPress(find.byIcon(Icons.favorite));
await tester.pumpAndSettle();
expect(find.byType(ReactionUsersSheet), findsOne);
});
});
Expand Down

0 comments on commit 6523900

Please sign in to comment.