mirror of
https://github.com/block/buzz.git
synced 2026-11-28 04:01:45 +00:00
Keep agent details inside Agents modal navigation
Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
@@ -5,6 +5,8 @@ import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
import '../features/profile/user_profile_sheet.dart';
|
||||
import '../features/channels/channel.dart';
|
||||
import '../features/channels/channel_detail_page.dart';
|
||||
import '../shared/community/community_provider.dart';
|
||||
import '../shared/crypto/nip_oa.dart';
|
||||
import '../shared/identity_names/identity_names_provider.dart';
|
||||
@@ -18,20 +20,73 @@ import '../shared/widgets/modal_presentation.dart';
|
||||
import 'create_agent_sheet.dart';
|
||||
import 'remote_agent_controller.dart';
|
||||
|
||||
/// Community-scoped list. Returning a key opens the existing profile from the
|
||||
/// app navigator, so Message can leave both sheets and navigate to the DM.
|
||||
/// Opens a community-scoped Agents navigation stack inside one modal.
|
||||
Future<void> showPrototypeAgents(
|
||||
BuildContext context,
|
||||
RemoteAgentController controller,
|
||||
) async {
|
||||
final pubkey = await showBuzzModalBottomSheet<String>(
|
||||
final channel = await showBuzzModalBottomSheet<Channel>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
showCloseButton: false,
|
||||
builder: (_) => PrototypeAgentsSheet(controller: controller),
|
||||
builder: (_) => _AgentsNavigation(controller: controller),
|
||||
);
|
||||
if (pubkey != null && context.mounted) {
|
||||
showUserProfileSheet(context, pubkey);
|
||||
if (channel != null && context.mounted) {
|
||||
await Navigator.of(context).push<void>(
|
||||
MaterialPageRoute(builder: (_) => ChannelDetailPage(channel: channel)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AgentsNavigation extends HookConsumerWidget {
|
||||
const _AgentsNavigation({required this.controller});
|
||||
|
||||
final RemoteAgentController controller;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final communityId = ref.watch(activeCommunityProvider).asData?.value?.id;
|
||||
final navigator = useMemoized(() => GlobalKey<NavigatorState>(), [
|
||||
communityId,
|
||||
]);
|
||||
return SizedBox(
|
||||
height: MediaQuery.sizeOf(context).height * .72,
|
||||
child: NavigatorPopHandler<Channel>(
|
||||
onPopWithResult: (result) => navigator.currentState!.pop(result),
|
||||
child: Navigator(
|
||||
key: navigator,
|
||||
onGenerateRoute: (_) => MaterialPageRoute<void>(
|
||||
builder: (listContext) => PrototypeAgentsSheet(
|
||||
controller: controller,
|
||||
onClose: () => Navigator.of(context).pop(),
|
||||
onSelect: (pubkey) async {
|
||||
final channel = await Navigator.of(listContext).push<Channel>(
|
||||
MaterialPageRoute(
|
||||
builder: (detailContext) => BuzzTitledSheetLayout(
|
||||
title: 'Agent',
|
||||
leading: IconButton(
|
||||
tooltip: 'Back',
|
||||
icon: const Icon(Icons.arrow_back_ios_new),
|
||||
onPressed: () => Navigator.of(detailContext).pop(),
|
||||
),
|
||||
trailing: IconButton(
|
||||
tooltip: 'Close',
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
child: UserProfileSheet(pubkey: pubkey),
|
||||
),
|
||||
),
|
||||
);
|
||||
if (channel != null && context.mounted) {
|
||||
Navigator.of(context).pop(channel);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +109,14 @@ Future<Set<String>> registeredCommunityAgents(
|
||||
}
|
||||
|
||||
class PrototypeAgentsSheet extends HookConsumerWidget {
|
||||
const PrototypeAgentsSheet({required this.controller, super.key});
|
||||
const PrototypeAgentsSheet({
|
||||
required this.controller,
|
||||
required this.onClose,
|
||||
required this.onSelect,
|
||||
super.key,
|
||||
});
|
||||
final VoidCallback onClose;
|
||||
final ValueChanged<String> onSelect;
|
||||
final RemoteAgentController controller;
|
||||
|
||||
@override
|
||||
@@ -105,7 +167,7 @@ class PrototypeAgentsSheet extends HookConsumerWidget {
|
||||
leading: IconButton(
|
||||
tooltip: 'Close',
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
onPressed: onClose,
|
||||
),
|
||||
trailing: IconButton(
|
||||
tooltip: 'Add agent',
|
||||
@@ -123,58 +185,61 @@ class PrototypeAgentsSheet extends HookConsumerWidget {
|
||||
),
|
||||
icon: const Icon(Icons.add),
|
||||
),
|
||||
child: RefreshIndicator(
|
||||
onRefresh: refresh,
|
||||
child: ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.fromLTRB(Grid.xs, 0, Grid.xs, Grid.sm),
|
||||
children: [
|
||||
if (loading) const LinearProgressIndicator(),
|
||||
if (controller.account.account == null)
|
||||
ListTile(
|
||||
title: const Text('Sign in to create an agent'),
|
||||
subtitle: controller.busy ? Text(controller.status) : null,
|
||||
trailing: TextButton(
|
||||
onPressed: controller.busy ? null : controller.signIn,
|
||||
child: const Text('Sign in'),
|
||||
),
|
||||
),
|
||||
if (failed)
|
||||
ListTile(
|
||||
title: const Text('Could not load agents'),
|
||||
trailing: TextButton(
|
||||
onPressed: refresh,
|
||||
child: const Text('Retry'),
|
||||
),
|
||||
),
|
||||
if (!loading && !failed && keys.isEmpty)
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(Grid.sm),
|
||||
child: Text(
|
||||
'No agents in this community yet.',
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
for (final key in keys)
|
||||
ListTile(
|
||||
key: ValueKey(key),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: Grid.xxs,
|
||||
vertical: Grid.xxs,
|
||||
),
|
||||
leading: AvatarImage(
|
||||
imageUrl: profiles[key]?.avatarUrl,
|
||||
radius: Grid.sm,
|
||||
isAgent: true,
|
||||
backgroundColor: context.colors.surfaceContainerHighest,
|
||||
fallback: Center(
|
||||
child: Text(names.labelFor(key).characters.first),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: RefreshIndicator(
|
||||
onRefresh: refresh,
|
||||
child: ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.fromLTRB(Grid.xs, 0, Grid.xs, Grid.sm),
|
||||
children: [
|
||||
if (loading) const LinearProgressIndicator(),
|
||||
if (controller.account.account == null)
|
||||
ListTile(
|
||||
title: const Text('Sign in to create an agent'),
|
||||
subtitle: controller.busy ? Text(controller.status) : null,
|
||||
trailing: TextButton(
|
||||
onPressed: controller.busy ? null : controller.signIn,
|
||||
child: const Text('Sign in'),
|
||||
),
|
||||
),
|
||||
title: Text(names.labelFor(key)),
|
||||
onTap: () => Navigator.pop(context, key),
|
||||
),
|
||||
],
|
||||
if (failed)
|
||||
ListTile(
|
||||
title: const Text('Could not load agents'),
|
||||
trailing: TextButton(
|
||||
onPressed: refresh,
|
||||
child: const Text('Retry'),
|
||||
),
|
||||
),
|
||||
if (!loading && !failed && keys.isEmpty)
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(Grid.sm),
|
||||
child: Text(
|
||||
'No agents in this community yet.',
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
for (final key in keys)
|
||||
ListTile(
|
||||
key: ValueKey(key),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: Grid.xxs,
|
||||
vertical: Grid.xxs,
|
||||
),
|
||||
leading: AvatarImage(
|
||||
imageUrl: profiles[key]?.avatarUrl,
|
||||
radius: Grid.sm,
|
||||
isAgent: true,
|
||||
backgroundColor: context.colors.surfaceContainerHighest,
|
||||
fallback: Center(
|
||||
child: Text(names.labelFor(key).characters.first),
|
||||
),
|
||||
),
|
||||
title: Text(names.labelFor(key)),
|
||||
onTap: () => onSelect(key),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'package:buzz/prototype/agents_sheet.dart';
|
||||
import 'package:buzz/features/profile/user_profile_sheet.dart';
|
||||
import 'package:buzz/shared/mentions/agent_identity_provider.dart';
|
||||
import 'package:buzz/shared/relay/relay.dart';
|
||||
import 'package:nostr/nostr.dart' as nostr;
|
||||
import 'package:buzz/prototype/create_agent_sheet.dart';
|
||||
@@ -109,6 +111,55 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('agent detail pushes inside one modal and Back restores list', (
|
||||
tester,
|
||||
) async {
|
||||
final account = BuilderlabAccountClient();
|
||||
final controller = _Controller(account);
|
||||
addTearDown(() {
|
||||
controller.dispose();
|
||||
controller.relayAuth.dispose();
|
||||
account.dispose();
|
||||
});
|
||||
final pubkey = 'a' * 64;
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
agentDirectoryProvider.overrideWith(
|
||||
(ref) async => [AgentDirectoryEntry(pubkey: pubkey)],
|
||||
),
|
||||
],
|
||||
child: MaterialApp(
|
||||
theme: AppTheme.light(),
|
||||
home: Builder(
|
||||
builder: (context) => Scaffold(
|
||||
body: TextButton(
|
||||
onPressed: () => showPrototypeAgents(context, controller),
|
||||
child: const Text('Open Agents'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Open Agents'));
|
||||
await tester.pumpAndSettle();
|
||||
final list = tester.element(find.byType(PrototypeAgentsSheet));
|
||||
await tester.tap(find.byKey(ValueKey(pubkey)));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(BottomSheet), findsOneWidget);
|
||||
expect(find.byType(UserProfileSheet), findsOneWidget);
|
||||
expect(list.mounted, isTrue);
|
||||
await tester.tap(find.byTooltip('Back'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(UserProfileSheet), findsNothing);
|
||||
expect(find.byKey(ValueKey(pubkey)), findsOneWidget);
|
||||
expect(tester.element(find.byType(PrototypeAgentsSheet)), same(list));
|
||||
await tester.tap(find.byTooltip('Close'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(BottomSheet), findsNothing);
|
||||
});
|
||||
|
||||
for (final succeed in [true, false]) {
|
||||
testWidgets(
|
||||
'Create returns to list only after confirmed success: $succeed',
|
||||
|
||||
Reference in New Issue
Block a user