Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions lib/showcase/component_showcase_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,67 @@ class _ShowcasePageState extends State<_ShowcasePage> {
// directly: it renders `_window`, the range the host has loaded, the way an
// SDK-backed controller renders the page it fetched.
late List<Message> _history = List<Message>.of(_showcaseMessages);
final Map<String, MessageReactionSummary> _reactionSummaries = {
_showcaseMessages.last.id: MessageReactionSummary(
messageId: _showcaseMessages.last.id,
reactions: const [
ReactionSummary(emoji: '❤️', count: 2, reactedByMe: false),
],
hasMore: false,
),
};

Future<bool> _toggleReaction(Message message, String emoji) async {
setState(() {
final previous =
_reactionSummaries[message.id]?.reactions ??
const <ReactionSummary>[];
final found = previous.where((row) => row.emoji == emoji).firstOrNull;
final count = (found?.count ?? 0) + (found?.reactedByMe == true ? -1 : 1);
_reactionSummaries[message.id] = MessageReactionSummary(
messageId: message.id,
reactions: [
for (final row in previous)
if (row.emoji != emoji) row,
if (count > 0)
ReactionSummary(
emoji: emoji,
count: count,
reactedByMe: found?.reactedByMe != true,
),
],
hasMore: false,
);
});
return true;
}

Future<ReactionUsersPage> _listReactionUsers(
Message message,
String emoji,
String? cursor,
) async => ReactionUsersPage(
data:
cursor != null
? const []
: [
if (_reactionSummaries[message.id]?.reactions.any(
(row) => row.emoji == emoji && row.reactedByMe,
) ==
true)
ReactionUser(
userId: _currentUserId,
name: 'Maya Chen',
reactedAt: DateTime.now(),
),
ReactionUser(
userId: 'alex',
name: 'Alex Rivera',
reactedAt: DateTime.now(),
),
],
nextCursor: null,
);
int _windowStart = 0;
int _windowEnd = 0;
// Whether the rendered window is a jumped-to one rather than the live tail.
Expand Down Expand Up @@ -360,6 +421,9 @@ class _ShowcasePageState extends State<_ShowcasePage> {
onReplyToMessage: _startReply,
onCancelReply: _cancelReply,
replyPreviewByMessageId: _replyPreviews(),
reactionSummaries: _reactionSummaries,
onToggleReaction: _toggleReaction,
onListReactionUsers: _listReactionUsers,
// Jump, highlight and the window around it.
onJumpToMessage: _jumpToMessage,
highlightedMessageId: _highlightedMessageId,
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ environment:
dependencies:
flutter:
sdk: flutter
convokit_flutter: ^0.9.0
convokit_flutter_ui: ^0.9.0
convokit_flutter: ^0.10.0
convokit_flutter_ui: ^0.10.0
http: ^1.2.0

dev_dependencies:
Expand Down
6 changes: 4 additions & 2 deletions test/component_showcase_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,10 @@ void main() {

// Scrolling toward the newer edge calls `onLoadNewer`, which extends
// the window forwards.
await tester.drag(history, const Offset(0, -300));
await tester.pumpAndSettle();
for (var i = 0; i < 4 && find.text(beyondWindow).evaluate().isEmpty; i++) {
await tester.drag(history, const Offset(0, -300));
await tester.pumpAndSettle();
}
expect(find.text(beyondWindow), findsOneWidget);

// Keeping at it reaches the room's newest message, which rejoins the
Expand Down
Loading