reorganize and rename widgets
This commit is contained in:
parent
05d25869ef
commit
d5f29dc344
2 changed files with 568 additions and 547 deletions
114
lib/widgets/read_receipts/read_receipts_row.dart
Normal file
114
lib/widgets/read_receipts/read_receipts_row.dart
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
import "dart:math";
|
||||
|
||||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||
import "package:material_ui/material_ui.dart";
|
||||
import "package:material_adaptive_sheets/material_adaptive_sheets.dart";
|
||||
import "package:nexus/controllers/read_receipts.dart";
|
||||
import "package:nexus/controllers/room_chat.dart";
|
||||
import "package:nexus/controllers/user.dart";
|
||||
import "package:nexus/helpers/extensions/get_localpart.dart";
|
||||
import "package:nexus/helpers/extensions/show_user_popover.dart";
|
||||
import "package:nexus/widgets/avatars/avatar_or_hash.dart";
|
||||
import "package:nexus/widgets/avatars/avatar_ring.dart";
|
||||
import "package:nexus/widgets/read_receipts/read_receipts_sheet.dart";
|
||||
|
||||
class const ReadReceiptsRow(
|
||||
final String eventId, {
|
||||
required final ChatParams chat,
|
||||
super.key,
|
||||
}) extends ConsumerWidget {
|
||||
static const avatarSize = 24.0;
|
||||
static const overlap = 6.0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final theme = Theme.of(context);
|
||||
final receipts = ref.watch(
|
||||
ReadReceiptsController.provider(chat)
|
||||
.select((receipts) => receipts[eventId] ?? const .empty()),
|
||||
);
|
||||
|
||||
return AnimatedSize(
|
||||
duration: Durations.medium2,
|
||||
curve: Curves.easeInOutCubicEmphasized,
|
||||
alignment: .topRight,
|
||||
child: receipts.isEmpty
|
||||
? const SizedBox(width: .infinity)
|
||||
: Padding(
|
||||
// Clear of the scrollbar
|
||||
padding: .only(right: 16, bottom: 2),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
const width = avatarSize + AvatarRing.ringWidth * 2;
|
||||
final fits =
|
||||
(constraints.maxWidth - width) ~/ (width - overlap) + 1;
|
||||
|
||||
// If they don't all fit, the last spot shows how many more there are
|
||||
final shown = receipts.length <= fits
|
||||
? receipts.length
|
||||
: max(0, fits - 1);
|
||||
|
||||
return Align(
|
||||
alignment: .centerRight,
|
||||
child: Wrap(
|
||||
spacing: -overlap,
|
||||
children: [
|
||||
...receipts
|
||||
.take(shown)
|
||||
.map(
|
||||
(receipt) => Consumer(
|
||||
builder: (context, ref, _) {
|
||||
final member = ref
|
||||
.watch(
|
||||
UserController.provider(
|
||||
.new(
|
||||
roomId: chat.roomId,
|
||||
userId: receipt.userId,
|
||||
),
|
||||
),
|
||||
)
|
||||
.value;
|
||||
final name =
|
||||
member?.displayName ??
|
||||
receipt.userId.localpart;
|
||||
|
||||
return AvatarRing(
|
||||
tooltip: name,
|
||||
onTap: () => context.showUserPopover(
|
||||
receipt.userId,
|
||||
roomId: chat.roomId,
|
||||
),
|
||||
child: AvatarOrHash(
|
||||
member?.avatarUrl,
|
||||
name,
|
||||
dimension: avatarSize,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
if (receipts.length > shown)
|
||||
AvatarRing(
|
||||
tooltip: "Show everyone who has read up to here",
|
||||
onTap: () => context.showAdaptiveSheet(
|
||||
(_) => ReadReceiptsSheet(eventId, chat: chat),
|
||||
),
|
||||
child: ColoredBox(
|
||||
color: theme.colorScheme.surfaceContainerHighest,
|
||||
child: Center(
|
||||
child: Text(
|
||||
"+${receipts.length - shown}",
|
||||
style: theme.textTheme.labelSmall,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
54
lib/widgets/read_receipts/read_receipts_sheet.dart
Normal file
54
lib/widgets/read_receipts/read_receipts_sheet.dart
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||
import "package:material_ui/material_ui.dart";
|
||||
import "package:material_adaptive_sheets/material_adaptive_sheets.dart";
|
||||
import "package:nexus/controllers/read_receipts.dart";
|
||||
import "package:nexus/controllers/room_chat.dart";
|
||||
import "package:nexus/controllers/user.dart";
|
||||
import "package:nexus/helpers/extensions/get_localpart.dart";
|
||||
import "package:nexus/helpers/extensions/show_user_popover.dart";
|
||||
import "package:nexus/widgets/avatars/avatar_or_hash.dart";
|
||||
|
||||
/// Everyone who has read up to an event, kept up to date while open.
|
||||
class const ReadReceiptsSheet(
|
||||
final String eventId, {
|
||||
required final ChatParams chat,
|
||||
super.key,
|
||||
}) extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) => SheetLayout(
|
||||
title: Text("Read by"),
|
||||
actions: [
|
||||
TextButton(onPressed: Navigator.of(context).pop, child: Text("Close")),
|
||||
],
|
||||
children: ref
|
||||
.watch(
|
||||
ReadReceiptsController.provider(chat)
|
||||
.select((receipts) => receipts[eventId] ?? const .empty()),
|
||||
)
|
||||
.map(
|
||||
(receipt) => Consumer(
|
||||
builder: (context, ref, _) {
|
||||
final member = ref
|
||||
.watch(
|
||||
UserController.provider(
|
||||
.new(roomId: chat.roomId, userId: receipt.userId),
|
||||
),
|
||||
)
|
||||
.value;
|
||||
final name = member?.displayName ?? receipt.userId.localpart;
|
||||
|
||||
return ListTile(
|
||||
leading: AvatarOrHash(member?.avatarUrl, name, dimension: 40),
|
||||
title: Text(name, overflow: .ellipsis),
|
||||
subtitle: Text(receipt.userId, overflow: .ellipsis),
|
||||
onTap: () => context.showUserPopover(
|
||||
receipt.userId,
|
||||
roomId: chat.roomId,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
Loading…
Reference in a new issue