Files
buzz/mobile/lib/features/forum/forum_posts_view.dart
klopez4212 9c0bcd6239 Align Duo chat headers, inset Home selections, and fix received photo-stack swipes (#9795)
- In unfolded Duo portrait, place the live chat avatar and name together
beside Back. Align the Messages and Activity headers with the status
controls and keep the filters full width.
- Center the stacked avatar and chat title over the sticky date with the
Duo rail on either side.
- Give Home selections rounder corners and a shared 12-point outer
gutter for channels, DMs, and Solo chats. Preserve icon and label
alignment.
- Mirror drag distance and flick velocity for received photo stacks so a
rightward swipe advances the stack.

The combined release preview was installed and checked on a physical
Duo. Widget tests cover the portrait header geometry, filter width, and
return to landscape.

### Portrait layout references

Cropped headers from the earlier Duo preview used as the design
reference.

![Messages header in unfolded
portrait](https://github.com/user-attachments/assets/93fa0134-81c8-406e-90a9-9d3711b0bdc0)

![Left-aligned chat chip in unfolded
portrait](https://github.com/user-attachments/assets/e79a9337-7d31-4871-96c3-9cb0300437cf)

### Simulator snapshots

The fixtures use sample content and a 76-point right rail inset.

![Stacked avatar and title aligned with the sticky
date](https://github.com/user-attachments/assets/1b9b409d-5fa6-4f79-8444-9927e2bee59e)

![Received photo stack during a rightward
swipe](https://github.com/user-attachments/assets/383be530-31df-4238-b6e4-62ecc2f299e0)

---------

Signed-off-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
Co-authored-by: Tom Brow <tomb@block.xyz>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz>
2026-11-20 18:09:43 +00:00

242 lines
8.4 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:buzz/shared/theme/buzz_icons.dart';
import '../../shared/relay/relay_closed_policy.dart';
import '../../shared/theme/theme.dart';
import '../../shared/widgets/buzz_loading_indicator.dart';
import '../../shared/widgets/frosted_app_bar.dart';
import '../../shared/widgets/load_error_view.dart';
import '../../shared/widgets/bee_refresh_indicator.dart';
import '../channels/channel.dart';
import '../channels/compose_bar.dart';
import 'forum_models.dart';
import 'forum_post_card.dart';
import 'forum_provider.dart';
import 'forum_thread_page.dart';
/// Main forum view — replaces the old _ForumPlaceholder.
///
/// Shows a list of forum posts for the channel with a FAB to open the compose
/// bar, and navigates to [ForumThreadPage] when a post is tapped.
class ForumPostsView extends HookConsumerWidget {
final Channel channel;
final String? currentPubkey;
final double? headerHeight;
const ForumPostsView({
super.key,
required this.channel,
required this.currentPubkey,
this.headerHeight,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
final postsAsync = ref.watch(forumPostsProvider(channel.id));
final isComposing = useState(false);
// A queued attachment can finish after this view is popped. Capture the
// app-level provider container instead of retaining the route's WidgetRef.
final providerContainer = ProviderScope.containerOf(context, listen: false);
final forumDelivery = ForumEventDelivery.capture(providerContainer);
// Periodic refresh (every 15s, matching desktop). A settled deadline
// pauses polling; reopening the forum is the explicit retry.
useEffect(() {
final provider = forumPostsProvider(channel.id);
// Only a deadline already settled when this surface mounts is a
// reopen; a first load that fails after mounting is not retried.
// Hooks run effects during build, so defer the invalidation past it.
if (isSettledRelayDeadline(ref.read(provider))) {
Future.microtask(() {
if (context.mounted) ref.invalidate(provider);
});
}
final timer = Stream.periodic(const Duration(seconds: 15)).listen((_) {
if (!isSettledRelayDeadline(ref.read(provider))) {
ref.invalidate(provider);
}
});
return timer.cancel;
}, [channel.id]);
final topInset = headerHeight ?? frostedAppBarHeight(context);
final canPost = channel.isMember && !channel.isArchived;
return Column(
children: [
Expanded(
child: Scaffold(
// Transparent so the parent Scaffold's background shows through.
backgroundColor: Colors.transparent,
floatingActionButton: canPost && !isComposing.value
? FloatingActionButton(
heroTag: 'forum-fab',
onPressed: () => isComposing.value = true,
tooltip: 'New post',
shape: const CircleBorder(),
child: const Icon(BuzzIcons.plus),
)
: null,
body: postsAsync.when(
// A retry from an error shows loading, not the stale error and its Retry.
skipLoadingOnRefresh: !postsAsync.hasError,
loading: () => Padding(
padding: EdgeInsets.only(top: topInset),
child: const Center(
child: BuzzLoadingIndicator(
size: 44,
semanticLabel: 'Loading posts',
),
),
),
error: (e, _) => Padding(
padding: EdgeInsets.only(top: topInset),
child: LoadErrorView(
message: 'Failed to load posts',
onRetry: () => ref.invalidate(forumPostsProvider(channel.id)),
),
),
data: (response) {
final posts = response.posts;
if (posts.isEmpty) {
return _EmptyState(
isMember: channel.isMember,
isArchived: channel.isArchived,
);
}
return BeeRefreshIndicator(
onRefresh: () async {
ref.invalidate(forumPostsProvider(channel.id));
await ref.read(forumPostsProvider(channel.id).future);
},
child: ListView.separated(
padding: EdgeInsets.only(
top: topInset,
left: Grid.gutter,
right: Grid.gutter,
bottom: Grid.xs,
),
itemCount: posts.length,
separatorBuilder: (_, _) =>
const SizedBox(height: Grid.xxs),
itemBuilder: (context, index) {
final post = posts[index];
return ForumPostCard(
post: post,
currentPubkey: currentPubkey,
onTap: () => _openThread(context, post),
onDelete: (eventId) async {
await deleteForumEvent(
ref,
channelId: channel.id,
eventId: eventId,
);
},
);
},
),
);
},
),
),
),
if (isComposing.value) ...[
Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.only(right: Grid.xxs),
child: IconButton(
onPressed: () => isComposing.value = false,
icon: const Icon(BuzzIcons.x, size: 18),
tooltip: 'Dismiss',
visualDensity: VisualDensity.compact,
),
),
),
ComposeBar(
channelId: channel.id,
hintText: 'Write your post\u2026',
onSend:
(
content,
mentionPubkeys, {
mediaTags = const <List<String>>[],
}) async {
await forumDelivery.createPost(
channelId: channel.id,
content: content,
mentionPubkeys: mentionPubkeys,
mediaTags: mediaTags,
);
if (context.mounted) isComposing.value = false;
},
),
],
],
);
}
void _openThread(BuildContext context, ForumPost post) {
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => ForumThreadPage(
channelId: channel.id,
postEventId: post.eventId,
currentPubkey: currentPubkey,
isMember: channel.isMember,
isArchived: channel.isArchived,
),
),
);
}
}
class _EmptyState extends StatelessWidget {
final bool isMember;
final bool isArchived;
const _EmptyState({required this.isMember, required this.isArchived});
@override
Widget build(BuildContext context) {
return Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: Grid.sm),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
BuzzIcons.messageSquareText,
size: Grid.xl,
color: context.colors.onSurfaceVariant,
),
const SizedBox(height: Grid.xxs),
Text(
'No posts yet',
style: context.textTheme.bodyLarge?.copyWith(
color: context.colors.onSurfaceVariant,
),
),
const SizedBox(height: Grid.half),
Text(
isArchived
? 'This forum is archived.'
: isMember
? 'Start a discussion by creating the first post.'
: 'Join this forum to create posts.',
style: context.textTheme.bodySmall?.copyWith(
color: context.colors.onSurfaceVariant,
),
textAlign: TextAlign.center,
),
],
),
),
);
}
}