mirror of
https://github.com/block/buzz.git
synced 2026-11-26 11:12:22 +00:00
## Summary - Add a shared footer fade behind the floating tabs on Home, Activity, and Search. - Use a shared anchored popover for Activity filters and section actions, with working section move controls. - Polish message grouping/press states and remove the initial Search back button. <img width="630" height="1368" alt="Screenshot 2026-07-29 at 08 49 37" src="https://github.com/user-attachments/assets/9e787adf-0bb3-49c6-8224-5819e8cfb1ad" /> ### Testing - `flutter analyze` - `flutter test` - Release build installed and checked on a connected iPhone ### Screenshots A real-device Activity baseline showing the original solid footer is attached in a PR comment. The updated review build was checked on the connected iPhone. --------- Signed-off-by: kenny lopez <klopez4212@gmail.com>
269 lines
10 KiB
Dart
269 lines
10 KiB
Dart
import 'dart:async';
|
|
import 'dart:io';
|
|
import 'dart:math' show max, min, pi;
|
|
import 'dart:ui';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
import 'package:flutter/physics.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:lucide_icons_flutter/lucide_icons.dart';
|
|
|
|
import '../../shared/auth/auth.dart';
|
|
import '../../shared/community/community_icon_provider.dart';
|
|
import '../../shared/relay/relay.dart';
|
|
import '../../shared/theme/theme.dart';
|
|
import '../../shared/widgets/avatar_image.dart';
|
|
import '../../shared/widgets/anchored_popover_menu.dart';
|
|
import '../../shared/widgets/buzz_loading_indicator.dart';
|
|
import '../../shared/widgets/frosted_app_bar.dart';
|
|
import '../../shared/widgets/frosted_scaffold.dart';
|
|
import '../../shared/widgets/skeleton.dart';
|
|
import '../../shared/custom_emoji/custom_emoji.dart';
|
|
import '../../shared/custom_emoji/custom_emoji_provider.dart';
|
|
import '../../shared/custom_emoji/custom_emoji_render.dart';
|
|
import '../profile/profile_avatar.dart';
|
|
import '../profile/profile_provider.dart';
|
|
import '../profile/presence_cache_provider.dart';
|
|
import '../profile/user_cache_provider.dart';
|
|
import '../pairing/pairing_page.dart';
|
|
import '../pairing/pairing_provider.dart';
|
|
import 'channel.dart';
|
|
import 'channel_detail_page.dart';
|
|
import 'channel_management_provider.dart';
|
|
import 'dm_channel_labels.dart';
|
|
import 'ephemeral_channel_display.dart';
|
|
import 'channel_mutes/channel_mutes_provider.dart';
|
|
import 'channel_sections/channel_sections_provider.dart';
|
|
import 'channel_sections/channel_sections_storage.dart';
|
|
import 'channel_stars/channel_stars_provider.dart';
|
|
import 'channels_provider.dart';
|
|
import 'read_state/deferred_read_state_update.dart';
|
|
import 'read_state/read_state_format.dart';
|
|
import 'read_state/read_state_provider.dart';
|
|
import 'read_state/read_state_time.dart';
|
|
import 'unread_badge/observed_unread_event.dart';
|
|
|
|
part 'channels_page/body.dart';
|
|
part 'channels_page/sections.dart';
|
|
part 'channels_page/channel_tile.dart';
|
|
part 'channels_page/sheets.dart';
|
|
part 'channels_page/badges.dart';
|
|
part 'channels_page/skeleton.dart';
|
|
part 'channels_page/community.dart';
|
|
part 'channels_page/quick_actions.dart';
|
|
part 'channels_page/quick_actions_launcher.dart';
|
|
|
|
enum _QuickAction { createChannel, newDm }
|
|
|
|
const double _kChannelSectionInset = Grid.gutter;
|
|
const double _kChannelLeadingWidth = 22.0;
|
|
const double _kChannelIconSize = 18.0;
|
|
const double _kChannelLabelGap = Grid.xxs;
|
|
const double _kChannelRowVerticalPadding = Grid.xxs + Grid.quarter;
|
|
const double _kChannelLabelInset =
|
|
_kChannelSectionInset + _kChannelLeadingWidth + _kChannelLabelGap;
|
|
|
|
/// DM avatars are circles, so they fill their box edge to edge where a channel
|
|
/// glyph leaves 4dp of slack inside the same 22dp leading column. Sizing them to
|
|
/// the glyph's ink width keeps the icon-to-label distance identical across both
|
|
/// sections while the labels stay on [_kChannelLabelInset].
|
|
const double _kDmAvatarSize = _kChannelIconSize;
|
|
|
|
const double _kTopSectionAvatarSize = 32.0;
|
|
|
|
/// The top section's avatars are 32dp circles, which fill their box edge to
|
|
/// edge; the channel rows below lead with an 18dp glyph left-aligned in a 22dp
|
|
/// box at [_kChannelSectionInset]. Edge-aligning the two leaves the circles
|
|
/// looking pushed outward, so the bar is pulled in to sit the avatar's centre
|
|
/// on the channel-icon column (12 + 16 = 28dp against the glyph's ~29dp). Its
|
|
/// label gap is derived separately so both labels land on the same 50dp column.
|
|
const double _kTopSectionInset = Grid.twelve;
|
|
const double _kTopSectionLabelGap =
|
|
_kChannelLabelInset - _kTopSectionInset - _kTopSectionAvatarSize;
|
|
const Duration _kSectionExpandDuration = Duration(milliseconds: 220);
|
|
const Duration _kSectionCollapseDuration = Duration(milliseconds: 170);
|
|
const Curve _kSectionExpandCurve = Cubic(0.23, 1, 0.32, 1);
|
|
const Curve _kSectionCollapseCurve = Curves.easeInCubic;
|
|
const double _kSectionCollapsedScaleY = 0.98;
|
|
|
|
class _UnreadChannelState {
|
|
final Set<String> ids;
|
|
final Map<String, int> counts;
|
|
|
|
const _UnreadChannelState({required this.ids, required this.counts});
|
|
}
|
|
|
|
_UnreadChannelState _computeUnreadChannelState({
|
|
required Iterable<Channel> channels,
|
|
required ReadStateState readState,
|
|
required ChannelsNotifier channelsNotifier,
|
|
}) {
|
|
if (!readState.isReady) {
|
|
return const _UnreadChannelState(ids: {}, counts: {});
|
|
}
|
|
|
|
final latestObservedByChannel = channelsNotifier.latestObservedByChannel;
|
|
final observedEventsByChannel =
|
|
channelsNotifier.observedUnreadEventsByChannel;
|
|
final ids = <String>{};
|
|
final counts = <String, int>{};
|
|
|
|
for (final channel in channels) {
|
|
if (readState.locallyForcedChannelIds.contains(channel.id)) {
|
|
ids.add(channel.id);
|
|
counts[channel.id] = 1;
|
|
continue;
|
|
}
|
|
|
|
final latestObserved = latestObservedByChannel[channel.id];
|
|
if (latestObserved == null) continue;
|
|
|
|
final channelReadAt = readState.effectiveTimestamp(channel.id);
|
|
if (channelReadAt != null && latestObserved <= channelReadAt) continue;
|
|
|
|
final observedEvents = observedEventsByChannel[channel.id];
|
|
int? readAtForObservedEvent(ObservedUnreadEvent event) =>
|
|
observedUnreadEventReadAt(
|
|
event,
|
|
channelReadAt,
|
|
(rootId) => readState.effectiveTimestamp(threadContextKey(rootId)),
|
|
(messageId) => readState.effectiveTimestamp(msgContextKey(messageId)),
|
|
);
|
|
|
|
final unreadCount = countUnreadObservedEvents(
|
|
observedEvents,
|
|
readAtForObservedEvent,
|
|
);
|
|
if (unreadCount == 0) continue;
|
|
|
|
ids.add(channel.id);
|
|
counts[channel.id] = countUnreadBadgeObservedEvents(
|
|
observedEvents,
|
|
readAtForObservedEvent,
|
|
);
|
|
}
|
|
|
|
return _UnreadChannelState(ids: ids, counts: counts);
|
|
}
|
|
|
|
class ChannelsPage extends HookConsumerWidget {
|
|
const ChannelsPage({required this.settingsPageBuilder, super.key});
|
|
|
|
final WidgetBuilder settingsPageBuilder;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final channelsAsync = ref.watch(channelsProvider);
|
|
final sessionState = ref.watch(relaySessionProvider);
|
|
final currentPubkey = ref
|
|
.watch(profileProvider)
|
|
.whenData((value) => value?.pubkey)
|
|
.value;
|
|
|
|
// Cache the last successfully loaded channels so the UI never flashes
|
|
// back to a loading state when the provider rebuilds (e.g. reconnect).
|
|
// Clear the cache on community switch so we show a full loader instead of
|
|
// stale channels from the previous community. unwrapPrevious() ensures the
|
|
// selector sees null during loading (not the previous community's ID).
|
|
final activeCommunityId = ref.watch(
|
|
activeCommunityProvider.select((v) => v.unwrapPrevious().value?.id),
|
|
);
|
|
final cachedChannels = useRef<List<Channel>?>(null);
|
|
final lastCommunityId = useRef<String?>(null);
|
|
if (lastCommunityId.value != activeCommunityId) {
|
|
cachedChannels.value = null;
|
|
lastCommunityId.value = activeCommunityId;
|
|
}
|
|
if (channelsAsync.asData?.value case final data?) {
|
|
cachedChannels.value = data;
|
|
}
|
|
final channels = cachedChannels.value;
|
|
Future<void> openChannel(Channel channel) async {
|
|
if (!context.mounted) return;
|
|
await Navigator.of(context).push(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => ChannelDetailPage(channel: channel),
|
|
),
|
|
);
|
|
}
|
|
|
|
// Only surface fetch errors while the relay is stably connected. During a
|
|
// reconnect the session owns recovery, so a cancelled in-flight query must
|
|
// not turn into a manual Retry page.
|
|
final showError = useState(false);
|
|
final hasError = channelsAsync.hasError && channels == null;
|
|
final canSurfaceError =
|
|
hasError &&
|
|
sessionState.status != SessionStatus.connecting &&
|
|
sessionState.status != SessionStatus.reconnecting;
|
|
useEffect(() {
|
|
if (!canSurfaceError) {
|
|
showError.value = false;
|
|
return null;
|
|
}
|
|
final timer = Timer(const Duration(seconds: 2), () {
|
|
showError.value = true;
|
|
});
|
|
return timer.cancel;
|
|
}, [canSurfaceError]);
|
|
|
|
// Keep cached content steady through brief socket flaps. A sustained
|
|
// reconnect swaps to element-shaped skeletons that match desktop.
|
|
final showConnectionSkeleton = useState(false);
|
|
final isReconnectingWithContent =
|
|
channels != null &&
|
|
(sessionState.status == SessionStatus.connecting ||
|
|
sessionState.status == SessionStatus.reconnecting);
|
|
useEffect(() {
|
|
if (!isReconnectingWithContent) {
|
|
showConnectionSkeleton.value = false;
|
|
return null;
|
|
}
|
|
final timer = Timer(const Duration(seconds: 2), () {
|
|
showConnectionSkeleton.value = true;
|
|
});
|
|
return timer.cancel;
|
|
}, [isReconnectingWithContent]);
|
|
|
|
return FrostedScaffold(
|
|
backgroundColor: Colors.transparent,
|
|
appBar: FrostedAppBar(
|
|
horizontalInset: _kTopSectionInset,
|
|
// Under a Buzz theme the community + account avatar strip carries the
|
|
// branded gradient, the way desktop paints it across the sidebar. Null
|
|
// under every other theme, leaving the default frosted fill.
|
|
gradient: context.appColors.topSectionGradient,
|
|
leading: _CommunityIndicator(
|
|
onTap: () {
|
|
ref.invalidate(communityIconProvider);
|
|
showModalBottomSheet<void>(
|
|
context: context,
|
|
showDragHandle: true,
|
|
builder: (_) => const _CommunitySwitcherSheet(),
|
|
);
|
|
},
|
|
),
|
|
title: const SizedBox.shrink(),
|
|
actions: [
|
|
ProfileAvatar(
|
|
onTap: () => Navigator.of(
|
|
context,
|
|
).push(MaterialPageRoute<void>(builder: settingsPageBuilder)),
|
|
),
|
|
],
|
|
),
|
|
body: _ChannelsBody(
|
|
channels: channels,
|
|
channelsAsync: channelsAsync,
|
|
showError: showError.value,
|
|
sessionStatus: sessionState.status,
|
|
showConnectionSkeleton: showConnectionSkeleton.value,
|
|
currentPubkey: currentPubkey,
|
|
onRefresh: () => ref.read(channelsProvider.notifier).refresh(),
|
|
onSelectChannel: openChannel,
|
|
),
|
|
);
|
|
}
|
|
}
|