@@ -3,11 +3,9 @@ import 'package:flutter_hooks/flutter_hooks.dart';
33import 'package:hooks_riverpod/hooks_riverpod.dart' ;
44
55import '../../../shared/me/me_sync.dart' ;
6- import '../../../shared/theme/theme.dart' ;
76import '../../../shared/theme/buzz_icons.dart' ;
87import '../../../shared/widgets/feedback_snackbar.dart' ;
98import '../../../shared/widgets/frosted_app_bar.dart' ;
10- import '../../../shared/widgets/modal_presentation.dart' ;
119import 'new_me_project.dart' ;
1210
1311/// The workspace control shared by draft and existing Solo conversations.
@@ -22,7 +20,8 @@ import 'new_me_project.dart';
2220}) {
2321 final busy = useState (false );
2422 final sync = enabled ? ref.watch (meSyncProvider) : null ;
25- final groups = enabled ? ref.watch (meGroupsProvider).value : null ;
23+ final groupState = enabled ? ref.watch (meGroupsProvider) : null ;
24+ final groups = groupState? .value;
2625 final current = channelId == null ? selected : groups? .assignments[channelId];
2726 final name =
2827 groups? .groups
@@ -32,18 +31,14 @@ import 'new_me_project.dart';
3231 final label = current == null
3332 ? 'Choose workspace'
3433 : 'Workspace: ${name ?? "Unavailable workspace" }' ;
35- Future <void > choose () async {
34+ Future <void > choose (String picked ) async {
3635 if (sync == null || busy.value) return ;
36+ if (picked == '+reload' ) {
37+ ref.invalidate (meGroupsProvider);
38+ return ;
39+ }
3740 busy.value = true ;
3841 try {
39- final picked = await showBuzzModalBottomSheet <String >(
40- context: context,
41- title: 'Workspace' ,
42- isScrollControlled: true ,
43- showDragHandle: true ,
44- builder: (_) => _WorkspaceChoices (selected: current),
45- );
46- if (picked == null || ! context.mounted) return ;
4742 sync .check ();
4843 final id = picked == '+create'
4944 ? await createMeProject (
@@ -81,66 +76,68 @@ import 'new_me_project.dart';
8176 }
8277 }
8378
84- final onPressed = ! enabled || locked || busy.value ? null : choose;
79+ final available =
80+ enabled &&
81+ ! locked &&
82+ ! busy.value &&
83+ (groups != null || groupState? .hasError == true );
8584 return (
8685 busy: busy.value,
87- action: IconButton (
86+ action: PopupMenuButton < String > (
8887 key: const ValueKey ('me-workspace-button' ),
8988 tooltip: label,
90- onPressed : onPressed ,
89+ enabled : available ,
9190 icon: const Icon (BuzzIcons .workspace),
91+ onSelected: choose,
92+ itemBuilder: (_) => [
93+ CheckedPopupMenuItem (
94+ value: '' ,
95+ checked: current == null ,
96+ child: const Text ('No Workspace' ),
97+ ),
98+ for (final group in groups? .groups ?? < Map <String , dynamic >> [])
99+ CheckedPopupMenuItem (
100+ value: group['id' ] as String ,
101+ checked: current == group['id' ],
102+ child: Text (group['name' ] as String ),
103+ ),
104+ if (groupState? .hasError == true )
105+ const PopupMenuItem (
106+ value: '+reload' ,
107+ child: Text ('Reload workspaces' ),
108+ ),
109+ const PopupMenuItem (value: '+create' , child: Text ('Create workspace' )),
110+ ],
92111 ),
93112 nativeAction: IosNavigationAction (
94113 label: label,
95114 icon: BuzzIcons .workspace,
96- onPressed: onPressed,
97- ),
98- );
99- }
100-
101- class _WorkspaceChoices extends ConsumerWidget {
102- const _WorkspaceChoices ({required this .selected});
103- final String ? selected;
104- @override
105- Widget build (BuildContext context, WidgetRef ref) {
106- final groups = ref.watch (meGroupsProvider);
107- return SizedBox (
108- height: (MediaQuery .sizeOf (context).height * 0.6 ).clamp (0.0 , 420.0 ),
109- child: Material (
110- type: MaterialType .transparency,
111- child: ListView (
112- padding: const EdgeInsets .symmetric (horizontal: Grid .gutter),
113- children: [
114- ListTile (
115- title: const Text ('No workspace' ),
116- selected: selected == null ,
117- trailing: selected == null ? const Icon (BuzzIcons .check) : null ,
118- onTap: () => Navigator .pop (context, '' ),
119- ),
120- if (groups.isLoading) const LinearProgressIndicator (),
121- if (groups.hasError)
122- TextButton (
123- onPressed: () => ref.invalidate (meGroupsProvider),
124- child: const Text ('Reload workspaces' ),
115+ sharesBackground: false ,
116+ children: ! available
117+ ? const []
118+ : [
119+ IosNavigationAction (
120+ label: 'No Workspace' ,
121+ selected: current == null ,
122+ onPressed: () => choose ('' ),
125123 ),
126- for (final group
127- in groups.value? .groups ?? < Map <String , dynamic >> [])
128- ListTile (
129- title: Text (group['name' ] as String ),
130- selected: selected == group['id' ],
131- trailing: selected == group['id' ]
132- ? const Icon (BuzzIcons .check)
133- : null ,
134- onTap: () => Navigator .pop (context, group['id' ] as String ),
124+ for (final group in groups? .groups ?? < Map <String , dynamic >> [])
125+ IosNavigationAction (
126+ label: group['name' ] as String ,
127+ selected: current == group['id' ],
128+ onPressed: () => choose (group['id' ] as String ),
129+ ),
130+ if (groupState? .hasError == true )
131+ IosNavigationAction (
132+ label: 'Reload workspaces' ,
133+ onPressed: () => choose ('+reload' ),
134+ ),
135+ IosNavigationAction (
136+ label: 'Create workspace' ,
137+ icon: BuzzIcons .plus,
138+ onPressed: () => choose ('+create' ),
135139 ),
136- ListTile (
137- leading: const Icon (BuzzIcons .plus),
138- title: const Text ('Create workspace' ),
139- onTap: () => Navigator .pop (context, '+create' ),
140- ),
141- ],
142- ),
143- ),
144- );
145- }
140+ ],
141+ ),
142+ );
146143}
0 commit comments