Nathan.fooo a49b009980
tests: more cloud test (#4204)
* test: add anon user test

* chore: add to runner

* test: fix

* test: fix

* test: add tests

* chore: add test

* chore: fix warn

* chore: fix warn

* fix: build

* fix: test

* chore: rename

* chore: fix test

* chore: fix test

* chore: fix test

* chore: disable test
2023-12-26 02:03:42 +08:00

96 lines
2.9 KiB
Dart

import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/user/application/anon_user_bloc.dart';
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';
class AnonUserList extends StatelessWidget {
final VoidCallback didOpenUser;
const AnonUserList({required this.didOpenUser, super.key});
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => AnonUserBloc()
..add(
const AnonUserEvent.initial(),
),
child: BlocBuilder<AnonUserBloc, AnonUserState>(
builder: (context, state) {
if (state.anonUsers.isEmpty) {
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) {
final user = state.anonUsers[index];
return AnonUserItem(
key: ValueKey(user.id),
user: user,
isSelected: false,
didOpenUser: didOpenUser,
);
},
itemCount: state.anonUsers.length,
),
),
],
);
}
},
),
);
}
}
class AnonUserItem extends StatelessWidget {
final VoidCallback didOpenUser;
final bool isSelected;
final UserProfilePB user;
const AnonUserItem({
required this.user,
required this.isSelected,
required this.didOpenUser,
super.key,
});
@override
Widget build(BuildContext context) {
final icon = isSelected ? const FlowySvg(FlowySvgs.check_s) : null;
final isDisabled =
isSelected || user.authenticator != AuthenticatorPB.Local;
final desc = "${user.name}\t ${user.authenticator}\t";
final child = SizedBox(
height: 30,
child: FlowyButton(
disable: isDisabled,
text: FlowyText.medium(
desc,
fontSize: 12,
),
rightIcon: icon,
onTap: () {
context.read<AnonUserBloc>().add(AnonUserEvent.openAnonUser(user));
didOpenUser();
},
),
);
return child;
}
}