menu_user_bloc.dart 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import 'package:app_flowy/workspace/domain/i_user.dart';
  2. import 'package:flowy_sdk/protobuf/flowy-user/user_profile.pb.dart';
  3. import 'package:flowy_sdk/protobuf/flowy-workspace/workspace_create.pb.dart';
  4. import 'package:flutter_bloc/flutter_bloc.dart';
  5. import 'package:freezed_annotation/freezed_annotation.dart';
  6. import 'package:dartz/dartz.dart';
  7. part 'menu_user_bloc.freezed.dart';
  8. class MenuUserBloc extends Bloc<MenuUserEvent, MenuUserState> {
  9. final IUser iUserImpl;
  10. MenuUserBloc(this.iUserImpl) : super(MenuUserState.initial(iUserImpl.user));
  11. @override
  12. Stream<MenuUserState> mapEventToState(MenuUserEvent event) async* {
  13. yield* event.map(
  14. initial: (_) async* {
  15. // // fetch workspaces
  16. // iUserImpl.fetchWorkspaces().then((result) {
  17. // result.fold(
  18. // (workspaces) async* {
  19. // yield state.copyWith(workspaces: some(workspaces));
  20. // },
  21. // (error) async* {
  22. // yield state.copyWith(successOrFailure: right(error.msg));
  23. // },
  24. // );
  25. // });
  26. },
  27. fetchWorkspaces: (_FetchWorkspaces value) async* {},
  28. );
  29. }
  30. @override
  31. Future<void> close() async {
  32. super.close();
  33. }
  34. }
  35. @freezed
  36. class MenuUserEvent with _$MenuUserEvent {
  37. const factory MenuUserEvent.initial() = _Initial;
  38. const factory MenuUserEvent.fetchWorkspaces() = _FetchWorkspaces;
  39. }
  40. @freezed
  41. class MenuUserState with _$MenuUserState {
  42. const factory MenuUserState({
  43. required UserProfile user,
  44. required Option<List<Workspace>> workspaces,
  45. required Either<Unit, String> successOrFailure,
  46. }) = _MenuUserState;
  47. factory MenuUserState.initial(UserProfile user) => MenuUserState(
  48. user: user,
  49. workspaces: none(),
  50. successOrFailure: left(unit),
  51. );
  52. }