| 
									
										
										
										
											2023-08-14 13:34:01 -07:00
										 |  |  | import 'package:appflowy/generated/flowy_svgs.g.dart'; | 
					
						
							| 
									
										
										
										
											2023-08-09 10:13:49 +08:00
										 |  |  | import 'package:appflowy/generated/locale_keys.g.dart'; | 
					
						
							| 
									
										
										
										
											2023-12-21 14:13:21 +08:00
										 |  |  | import 'package:appflowy/user/application/anon_user_bloc.dart'; | 
					
						
							| 
									
										
										
										
											2023-08-09 10:13:49 +08:00
										 |  |  | import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'; | 
					
						
							|  |  |  | import 'package:easy_localization/easy_localization.dart'; | 
					
						
							|  |  |  | import 'package:flowy_infra_ui/flowy_infra_ui.dart'; | 
					
						
							|  |  |  | import 'package:flutter/material.dart'; | 
					
						
							|  |  |  | import 'package:flutter_bloc/flutter_bloc.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-21 14:13:21 +08:00
										 |  |  | class AnonUserList extends StatelessWidget { | 
					
						
							|  |  |  |   const AnonUserList({required this.didOpenUser, super.key}); | 
					
						
							| 
									
										
										
										
											2023-08-09 10:13:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 16:37:36 +01:00
										 |  |  |   final VoidCallback didOpenUser; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 10:13:49 +08:00
										 |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     return BlocProvider( | 
					
						
							| 
									
										
										
										
											2023-12-21 14:13:21 +08:00
										 |  |  |       create: (context) => AnonUserBloc() | 
					
						
							| 
									
										
										
										
											2023-08-09 10:13:49 +08:00
										 |  |  |         ..add( | 
					
						
							| 
									
										
										
										
											2023-12-21 14:13:21 +08:00
										 |  |  |           const AnonUserEvent.initial(), | 
					
						
							| 
									
										
										
										
											2023-08-09 10:13:49 +08:00
										 |  |  |         ), | 
					
						
							| 
									
										
										
										
											2023-12-21 14:13:21 +08:00
										 |  |  |       child: BlocBuilder<AnonUserBloc, AnonUserState>( | 
					
						
							| 
									
										
										
										
											2023-08-09 10:13:49 +08:00
										 |  |  |         builder: (context, state) { | 
					
						
							| 
									
										
										
										
											2023-12-21 14:13:21 +08:00
										 |  |  |           if (state.anonUsers.isEmpty) { | 
					
						
							| 
									
										
										
										
											2023-08-09 10:13:49 +08:00
										 |  |  |             return const SizedBox.shrink(); | 
					
						
							|  |  |  |           } else { | 
					
						
							|  |  |  |             return Column( | 
					
						
							|  |  |  |               crossAxisAlignment: CrossAxisAlignment.start, | 
					
						
							|  |  |  |               children: [ | 
					
						
							|  |  |  |                 Opacity( | 
					
						
							|  |  |  |                   opacity: 0.6, | 
					
						
							|  |  |  |                   child: FlowyText.regular( | 
					
						
							|  |  |  |                     LocaleKeys.settings_menu_historicalUserListTooltip.tr(), | 
					
						
							|  |  |  |                     fontSize: 13, | 
					
						
							|  |  |  |                     maxLines: null, | 
					
						
							|  |  |  |                   ), | 
					
						
							|  |  |  |                 ), | 
					
						
							|  |  |  |                 const VSpace(6), | 
					
						
							|  |  |  |                 Expanded( | 
					
						
							|  |  |  |                   child: ListView.builder( | 
					
						
							|  |  |  |                     itemBuilder: (context, index) { | 
					
						
							| 
									
										
										
										
											2023-12-21 14:13:21 +08:00
										 |  |  |                       final user = state.anonUsers[index]; | 
					
						
							|  |  |  |                       return AnonUserItem( | 
					
						
							|  |  |  |                         key: ValueKey(user.id), | 
					
						
							| 
									
										
										
										
											2023-08-09 10:13:49 +08:00
										 |  |  |                         user: user, | 
					
						
							|  |  |  |                         isSelected: false, | 
					
						
							|  |  |  |                         didOpenUser: didOpenUser, | 
					
						
							|  |  |  |                       ); | 
					
						
							|  |  |  |                     }, | 
					
						
							| 
									
										
										
										
											2023-12-21 14:13:21 +08:00
										 |  |  |                     itemCount: state.anonUsers.length, | 
					
						
							| 
									
										
										
										
											2023-08-09 10:13:49 +08:00
										 |  |  |                   ), | 
					
						
							| 
									
										
										
										
											2023-11-14 22:33:07 +08:00
										 |  |  |                 ), | 
					
						
							| 
									
										
										
										
											2023-08-09 10:13:49 +08:00
										 |  |  |               ], | 
					
						
							|  |  |  |             ); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-21 14:13:21 +08:00
										 |  |  | class AnonUserItem extends StatelessWidget { | 
					
						
							|  |  |  |   const AnonUserItem({ | 
					
						
							| 
									
										
										
										
											2024-01-25 16:37:36 +01:00
										 |  |  |     super.key, | 
					
						
							| 
									
										
										
										
											2023-08-09 10:13:49 +08:00
										 |  |  |     required this.user, | 
					
						
							|  |  |  |     required this.isSelected, | 
					
						
							|  |  |  |     required this.didOpenUser, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 16:37:36 +01:00
										 |  |  |   final UserProfilePB user; | 
					
						
							|  |  |  |   final bool isSelected; | 
					
						
							|  |  |  |   final VoidCallback didOpenUser; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 10:13:49 +08:00
										 |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							| 
									
										
										
										
											2023-08-14 13:34:01 -07:00
										 |  |  |     final icon = isSelected ? const FlowySvg(FlowySvgs.check_s) : null; | 
					
						
							| 
									
										
										
										
											2023-12-26 02:03:42 +08:00
										 |  |  |     final isDisabled = | 
					
						
							|  |  |  |         isSelected || user.authenticator != AuthenticatorPB.Local; | 
					
						
							|  |  |  |     final desc = "${user.name}\t ${user.authenticator}\t"; | 
					
						
							| 
									
										
										
										
											2023-08-09 10:13:49 +08:00
										 |  |  |     final child = SizedBox( | 
					
						
							|  |  |  |       height: 30, | 
					
						
							|  |  |  |       child: FlowyButton( | 
					
						
							|  |  |  |         disable: isDisabled, | 
					
						
							|  |  |  |         text: FlowyText.medium( | 
					
						
							|  |  |  |           desc, | 
					
						
							|  |  |  |           fontSize: 12, | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |         rightIcon: icon, | 
					
						
							|  |  |  |         onTap: () { | 
					
						
							| 
									
										
										
										
											2023-12-21 14:13:21 +08:00
										 |  |  |           context.read<AnonUserBloc>().add(AnonUserEvent.openAnonUser(user)); | 
					
						
							| 
									
										
										
										
											2023-08-09 10:13:49 +08:00
										 |  |  |           didOpenUser(); | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     return child; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |