mirror of
https://github.com/block/buzz.git
synced 2026-11-26 19:21:50 +00:00
The UI-only part of #9193 by @klopez4212, split out so it can land without the Activity sync changes. - Activity moves from a row in the Home list to a bell button in the Home header, with an unread dot driven by the existing Activity feed and read state. - Home filter capsules match native iOS and Android widths, with a subtle outline on Android when the header collapses. - Home section spacing is tighter. Left out: the reconnect rewrite in #9193's last commit (live events applied in place, no rebuild on reconnect, fatal fallback reads). The Activity provider is unchanged from main. Channel and Solo rows keep their bottom padding so they stay at the 44 pt minimum tap height. ### Validation - Kenny's added tests: `inbox_unread_provider_test` (unread dot) and the Home page bell and filter width tests. - Full mobile suite: all pass except 11 push and notification-toggle tests that fail identically on an unchanged checkout in this environment. - Automated simulator run (iPhone 17 Pro, iOS 27) of a build combining this PR with its sibling split: Home rows measure 44 pt, the bell opens Activity and shows its dot after a row is marked unread, type/sender/Unread filters each narrow the feed, a row opens its conversation, Search results scroll under the fade, and filter labels fit at the largest text size. Screenshots are in Buzz rather than here because they show internal test data. Android was covered only by widget tests. ### Before merge - [x] Automated simulator run of Home, the bell, Activity and channel navigation, with screenshots. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Tom Brow <tomb@squareup.com> Co-authored-by: Tom Brow <tomb@squareup.com> Co-authored-by: kenny lopez <klopez4212@gmail.com> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
602 lines
17 KiB
Dart
602 lines
17 KiB
Dart
part of '../channels_page.dart';
|
||
|
||
const _sectionMenuItemPadding = EdgeInsets.fromLTRB(Grid.xs, 0, Grid.twelve, 0);
|
||
|
||
class _CustomChannelSection extends StatelessWidget {
|
||
final ChannelSection section;
|
||
final List<Channel> channels;
|
||
final Set<String> unreadChannelIds;
|
||
final Set<String> attentionChannelIds;
|
||
final Set<String> mutedChannelIds;
|
||
final String? currentPubkey;
|
||
final bool expanded;
|
||
final bool isFirst;
|
||
final bool isLast;
|
||
final VoidCallback onToggle;
|
||
final VoidCallback onRename;
|
||
final VoidCallback onDelete;
|
||
final VoidCallback onMoveUp;
|
||
final VoidCallback onMoveDown;
|
||
final ChannelSortMode sortMode;
|
||
final ValueChanged<ChannelSortMode> onSortModeChange;
|
||
final Future<void> Function(Channel channel) onSelectChannel;
|
||
final void Function(Channel channel) onMarkChannelRead;
|
||
|
||
const _CustomChannelSection({
|
||
required this.section,
|
||
required this.channels,
|
||
required this.unreadChannelIds,
|
||
required this.attentionChannelIds,
|
||
required this.mutedChannelIds,
|
||
required this.currentPubkey,
|
||
required this.expanded,
|
||
required this.isFirst,
|
||
required this.isLast,
|
||
required this.onToggle,
|
||
required this.onRename,
|
||
required this.onDelete,
|
||
required this.onMoveUp,
|
||
required this.onMoveDown,
|
||
required this.sortMode,
|
||
required this.onSortModeChange,
|
||
required this.onSelectChannel,
|
||
required this.onMarkChannelRead,
|
||
});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
_CustomSectionHeader(
|
||
section: section,
|
||
expanded: expanded,
|
||
isFirst: isFirst,
|
||
isLast: isLast,
|
||
onToggle: onToggle,
|
||
onRename: onRename,
|
||
onDelete: onDelete,
|
||
onMoveUp: onMoveUp,
|
||
onMoveDown: onMoveDown,
|
||
sortMode: sortMode,
|
||
onSortModeChange: onSortModeChange,
|
||
),
|
||
CollapsibleSectionBody(
|
||
expanded: expanded,
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
for (final channel in channels)
|
||
_ChannelTile(
|
||
channel: channel,
|
||
isUnread: unreadChannelIds.contains(channel.id),
|
||
hasAttention: attentionChannelIds.contains(channel.id),
|
||
isMuted: mutedChannelIds.contains(channel.id),
|
||
currentPubkey: currentPubkey,
|
||
onTap: () => onSelectChannel(channel),
|
||
onMarkRead: () => onMarkChannelRead(channel),
|
||
sectionId: section.id,
|
||
),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
);
|
||
}
|
||
}
|
||
|
||
class _CustomSectionHeader extends StatelessWidget {
|
||
final ChannelSection section;
|
||
final bool expanded;
|
||
final bool isFirst;
|
||
final bool isLast;
|
||
final VoidCallback onToggle;
|
||
final VoidCallback onRename;
|
||
final VoidCallback onDelete;
|
||
final VoidCallback onMoveUp;
|
||
final VoidCallback onMoveDown;
|
||
final ChannelSortMode sortMode;
|
||
final ValueChanged<ChannelSortMode> onSortModeChange;
|
||
|
||
const _CustomSectionHeader({
|
||
required this.section,
|
||
required this.expanded,
|
||
required this.isFirst,
|
||
required this.isLast,
|
||
required this.onToggle,
|
||
required this.onRename,
|
||
required this.onDelete,
|
||
required this.onMoveUp,
|
||
required this.onMoveDown,
|
||
required this.sortMode,
|
||
required this.onSortModeChange,
|
||
});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final sectionColor = navigationHeadingForeground(context);
|
||
return GestureDetector(
|
||
onTap: onToggle,
|
||
behavior: HitTestBehavior.opaque,
|
||
child: Padding(
|
||
padding: const EdgeInsets.fromLTRB(
|
||
Grid.gutter,
|
||
_kSectionHeaderVerticalPadding,
|
||
Grid.gutter,
|
||
_kSectionHeaderVerticalPadding,
|
||
),
|
||
child: Row(
|
||
children: [
|
||
Expanded(
|
||
child: _SectionLabel(
|
||
label: section.name,
|
||
expanded: expanded,
|
||
color: sectionColor,
|
||
),
|
||
),
|
||
Builder(
|
||
builder: (buttonContext) => _SectionOptionsButton(
|
||
key: ValueKey('section-menu-${section.id}'),
|
||
tooltip: '${section.name} options',
|
||
icon: Icon(
|
||
BuzzIcons.ellipsis,
|
||
size: 14,
|
||
color: navigationAccessoryForeground(context),
|
||
),
|
||
onPressed: () async {
|
||
final value = await showAnchoredPopover<String>(
|
||
context: buttonContext,
|
||
width: 216,
|
||
alignment: AnchoredPopoverAlignment.end,
|
||
surfaceKey: ValueKey('section-popover-${section.id}'),
|
||
items: [
|
||
const PopupMenuItem(
|
||
value: 'rename',
|
||
padding: _sectionMenuItemPadding,
|
||
child: _SectionMenuItemContent(
|
||
icon: BuzzIcons.pencil,
|
||
label: 'Rename section',
|
||
),
|
||
),
|
||
PopupMenuItem(
|
||
value: 'move_up',
|
||
enabled: !isFirst,
|
||
padding: _sectionMenuItemPadding,
|
||
child: const _SectionMenuItemContent(
|
||
icon: BuzzIcons.arrowUp,
|
||
label: 'Move up',
|
||
),
|
||
),
|
||
PopupMenuItem(
|
||
value: 'move_down',
|
||
enabled: !isLast,
|
||
padding: _sectionMenuItemPadding,
|
||
child: const _SectionMenuItemContent(
|
||
icon: BuzzIcons.arrowDown,
|
||
label: 'Move down',
|
||
),
|
||
),
|
||
..._sortMenuItems(sortMode),
|
||
PopupMenuItem(
|
||
value: 'delete',
|
||
padding: _sectionMenuItemPadding,
|
||
child: _SectionMenuItemContent(
|
||
icon: BuzzIcons.trash2,
|
||
label: 'Delete section',
|
||
color: context.colors.error,
|
||
),
|
||
),
|
||
],
|
||
);
|
||
switch (value) {
|
||
case 'rename':
|
||
onRename();
|
||
case 'move_up':
|
||
onMoveUp();
|
||
case 'move_down':
|
||
onMoveDown();
|
||
case _kSortRecentMenuValue:
|
||
onSortModeChange(ChannelSortMode.recent);
|
||
case _kSortAlphaMenuValue:
|
||
onSortModeChange(ChannelSortMode.alpha);
|
||
case 'delete':
|
||
onDelete();
|
||
}
|
||
},
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
class _SectionMenuItemContent extends StatelessWidget {
|
||
final IconData icon;
|
||
final String label;
|
||
final Color? color;
|
||
|
||
const _SectionMenuItemContent({
|
||
required this.icon,
|
||
required this.label,
|
||
this.color,
|
||
});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Row(
|
||
children: [
|
||
Icon(icon, size: 16, color: color),
|
||
const SizedBox(width: Grid.xxs),
|
||
Flexible(
|
||
child: Text(
|
||
label,
|
||
maxLines: 1,
|
||
overflow: TextOverflow.ellipsis,
|
||
style: color == null ? null : TextStyle(color: color),
|
||
),
|
||
),
|
||
],
|
||
);
|
||
}
|
||
}
|
||
|
||
class _SectionNameDialog extends HookWidget {
|
||
final String title;
|
||
final String confirmLabel;
|
||
final String initialValue;
|
||
|
||
const _SectionNameDialog({
|
||
required this.title,
|
||
required this.confirmLabel,
|
||
this.initialValue = '',
|
||
});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final controller = useTextEditingController(text: initialValue);
|
||
|
||
void confirm() {
|
||
final name = controller.text.trim();
|
||
if (name.isNotEmpty) Navigator.of(context).pop(name);
|
||
}
|
||
|
||
return AlertDialog(
|
||
title: Text(title),
|
||
content: TextField(
|
||
controller: controller,
|
||
autofocus: true,
|
||
decoration: const InputDecoration(labelText: 'Name'),
|
||
onSubmitted: (_) => confirm(),
|
||
),
|
||
actions: [
|
||
TextButton(
|
||
onPressed: () => Navigator.of(context).pop(),
|
||
child: const Text('Cancel'),
|
||
),
|
||
TextButton(onPressed: confirm, child: Text(confirmLabel)),
|
||
],
|
||
);
|
||
}
|
||
}
|
||
|
||
const _kSortRecentMenuValue = 'sort_recent';
|
||
const _kSortAlphaMenuValue = 'sort_alpha';
|
||
|
||
PopupMenuItem<String> _sortMenuItem({
|
||
required String value,
|
||
required String label,
|
||
required bool selected,
|
||
}) => PopupMenuItem(
|
||
value: value,
|
||
child: Row(
|
||
children: [
|
||
Expanded(child: Text(label)),
|
||
if (selected)
|
||
const Icon(BuzzIcons.check, key: ValueKey('sort-selected-check'))
|
||
else
|
||
const SizedBox(width: 24),
|
||
],
|
||
),
|
||
);
|
||
|
||
List<PopupMenuEntry<String>> _sortMenuItems(
|
||
ChannelSortMode current, {
|
||
bool showDivider = true,
|
||
}) => [
|
||
if (showDivider) const PopupMenuDivider(),
|
||
_sortMenuItem(
|
||
value: _kSortRecentMenuValue,
|
||
label: 'Sort: Recent',
|
||
selected: current == ChannelSortMode.recent,
|
||
),
|
||
_sortMenuItem(
|
||
value: _kSortAlphaMenuValue,
|
||
label: 'Sort: A–Z',
|
||
selected: current == ChannelSortMode.alpha,
|
||
),
|
||
];
|
||
|
||
class _ChannelSection extends StatelessWidget {
|
||
final String title;
|
||
final bool expanded;
|
||
final VoidCallback onToggle;
|
||
final List<Channel> channels;
|
||
final Set<String> unreadChannelIds;
|
||
final Set<String> attentionChannelIds;
|
||
final Set<String> mutedChannelIds;
|
||
final String? currentPubkey;
|
||
final String emptyLabel;
|
||
final ChannelSortMode? sortMode;
|
||
final ValueChanged<ChannelSortMode>? onSortModeChange;
|
||
final Future<void> Function(Channel channel) onSelectChannel;
|
||
|
||
const _ChannelSection({
|
||
required this.title,
|
||
required this.expanded,
|
||
required this.onToggle,
|
||
required this.channels,
|
||
required this.unreadChannelIds,
|
||
required this.attentionChannelIds,
|
||
required this.mutedChannelIds,
|
||
required this.currentPubkey,
|
||
required this.emptyLabel,
|
||
this.sortMode,
|
||
this.onSortModeChange,
|
||
required this.onSelectChannel,
|
||
});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
_SectionHeader(
|
||
label: title,
|
||
expanded: expanded,
|
||
onToggle: onToggle,
|
||
sortMode: sortMode,
|
||
onSortModeChange: onSortModeChange,
|
||
),
|
||
CollapsibleSectionBody(
|
||
expanded: expanded,
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
if (channels.isEmpty)
|
||
Padding(
|
||
padding: const EdgeInsets.only(
|
||
left: _kChannelLabelInset,
|
||
right: _kChannelSectionInset,
|
||
top: Grid.half,
|
||
bottom: Grid.half,
|
||
),
|
||
child: Align(
|
||
alignment: Alignment.centerLeft,
|
||
child: Text(
|
||
emptyLabel,
|
||
style: contentListBodyTextStyle.copyWith(
|
||
color: context.colors.onSurfaceVariant.withValues(
|
||
alpha: 0.65,
|
||
),
|
||
),
|
||
),
|
||
),
|
||
)
|
||
else
|
||
for (final channel in channels)
|
||
_ChannelTile(
|
||
channel: channel,
|
||
isUnread: unreadChannelIds.contains(channel.id),
|
||
hasAttention: attentionChannelIds.contains(channel.id),
|
||
isMuted: mutedChannelIds.contains(channel.id),
|
||
currentPubkey: currentPubkey,
|
||
onTap: () => onSelectChannel(channel),
|
||
onMarkRead: null,
|
||
sectionId: null,
|
||
),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
);
|
||
}
|
||
}
|
||
|
||
class _EmptyState extends StatelessWidget {
|
||
const _EmptyState();
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return SizedBox(
|
||
height: MediaQuery.sizeOf(context).height * 0.55,
|
||
child: Center(
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
Icon(
|
||
BuzzIcons.messagesSquare,
|
||
size: Grid.xl,
|
||
color: context.colors.onSurfaceVariant,
|
||
),
|
||
const SizedBox(height: Grid.xs),
|
||
Text(
|
||
'No conversations yet',
|
||
style: context.textTheme.bodyLarge?.copyWith(
|
||
color: context.colors.onSurfaceVariant,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
class _SectionHeader extends StatelessWidget {
|
||
final String label;
|
||
final bool expanded;
|
||
final VoidCallback onToggle;
|
||
final ChannelSortMode? sortMode;
|
||
final ValueChanged<ChannelSortMode>? onSortModeChange;
|
||
|
||
const _SectionHeader({
|
||
required this.label,
|
||
required this.expanded,
|
||
required this.onToggle,
|
||
this.sortMode,
|
||
this.onSortModeChange,
|
||
});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final sectionColor = navigationHeadingForeground(context);
|
||
|
||
return GestureDetector(
|
||
onTap: onToggle,
|
||
behavior: HitTestBehavior.opaque,
|
||
child: Padding(
|
||
padding: const EdgeInsets.fromLTRB(
|
||
Grid.gutter,
|
||
_kSectionHeaderVerticalPadding,
|
||
Grid.gutter,
|
||
_kSectionHeaderVerticalPadding,
|
||
),
|
||
child: Row(
|
||
children: [
|
||
Expanded(
|
||
child: _SectionLabel(
|
||
label: label,
|
||
expanded: expanded,
|
||
color: sectionColor,
|
||
),
|
||
),
|
||
if (sortMode case final mode?) ...[
|
||
Builder(
|
||
builder: (buttonContext) => _SectionOptionsButton(
|
||
key: ValueKey('sort-menu-$label'),
|
||
tooltip: '$label options',
|
||
icon: Icon(
|
||
BuzzIcons.ellipsis,
|
||
size: 14,
|
||
color: navigationAccessoryForeground(context),
|
||
),
|
||
onPressed: () async {
|
||
final value = await showAnchoredPopover<String>(
|
||
context: buttonContext,
|
||
width: 216,
|
||
alignment: AnchoredPopoverAlignment.end,
|
||
surfaceKey: ValueKey('sort-popover-$label'),
|
||
items: _sortMenuItems(mode, showDivider: false),
|
||
);
|
||
if (value == _kSortRecentMenuValue) {
|
||
onSortModeChange?.call(ChannelSortMode.recent);
|
||
} else if (value == _kSortAlphaMenuValue) {
|
||
onSortModeChange?.call(ChannelSortMode.alpha);
|
||
}
|
||
},
|
||
),
|
||
),
|
||
],
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
class _SectionLabel extends StatelessWidget {
|
||
const _SectionLabel({
|
||
required this.label,
|
||
required this.expanded,
|
||
required this.color,
|
||
});
|
||
|
||
final String label;
|
||
final bool expanded;
|
||
final Color color;
|
||
|
||
@override
|
||
Widget build(BuildContext context) => Padding(
|
||
padding: const EdgeInsets.only(top: Grid.xxs),
|
||
child: Row(
|
||
children: [
|
||
Flexible(
|
||
child: Text(
|
||
label,
|
||
maxLines: 1,
|
||
overflow: TextOverflow.ellipsis,
|
||
style: navigationSectionTextStyle.copyWith(
|
||
color: color,
|
||
fontWeight: FontWeight.w500,
|
||
),
|
||
),
|
||
),
|
||
const SizedBox(width: Grid.quarter),
|
||
_SectionChevron(
|
||
expanded: expanded,
|
||
color: navigationAccessoryForeground(context),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
class _SectionChevron extends StatelessWidget {
|
||
final bool expanded;
|
||
final Color color;
|
||
|
||
const _SectionChevron({required this.expanded, required this.color});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final reducedMotion = MediaQuery.of(context).disableAnimations;
|
||
|
||
return AnimatedRotation(
|
||
turns: expanded ? 0 : -0.25,
|
||
duration: reducedMotion ? Duration.zero : sectionExpandDuration,
|
||
curve: sectionExpandCurve,
|
||
child: Icon(BuzzIcons.chevronDown, size: 14, color: color),
|
||
);
|
||
}
|
||
}
|
||
|
||
class _SectionOptionsButton extends StatelessWidget {
|
||
const _SectionOptionsButton({
|
||
super.key,
|
||
required this.tooltip,
|
||
required this.icon,
|
||
required this.onPressed,
|
||
});
|
||
|
||
final String tooltip;
|
||
final Widget icon;
|
||
final VoidCallback onPressed;
|
||
|
||
@override
|
||
Widget build(BuildContext context) => Semantics(
|
||
button: true,
|
||
label: tooltip,
|
||
onTap: onPressed,
|
||
excludeSemantics: true,
|
||
child: Tooltip(
|
||
message: tooltip,
|
||
child: SizedBox.square(
|
||
dimension: 44,
|
||
child: InkWell(
|
||
onTap: onPressed,
|
||
borderRadius: BorderRadius.circular(Radii.full),
|
||
child: Align(
|
||
alignment: Alignment.centerRight,
|
||
child: SizedBox(
|
||
width: _kChannelIconSize,
|
||
child: Center(child: icon),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|