[flutter]: remove menu listener

This commit is contained in:
appflowy 2021-10-18 22:08:35 +08:00
parent 3f83e7ee06
commit 98836f821b
7 changed files with 201 additions and 772 deletions

View File

@ -14,29 +14,43 @@ part 'menu_bloc.freezed.dart';
class MenuBloc extends Bloc<MenuEvent, MenuState> {
final IWorkspace workspaceManager;
MenuBloc(this.workspaceManager) : super(MenuState.initial());
final IWorkspaceListener listener;
MenuBloc({required this.workspaceManager, required this.listener}) : super(MenuState.initial());
@override
Stream<MenuState> mapEventToState(
MenuEvent event,
) async* {
yield* event.map(
initial: (value) async* {
initial: (e) async* {
listener.start(addAppCallback: _handleAppsOrFail);
yield* _fetchApps();
},
collapse: (e) async* {
final isCollapse = state.isCollapse;
yield state.copyWith(isCollapse: !isCollapse);
},
openPage: (OpenPage e) async* {
openPage: (e) async* {
yield* _performActionOnOpenPage(e);
},
createApp: (CreateApp event) async* {
yield* _performActionOnCreateApp(event);
},
didReceiveApps: (e) async* {
yield e.appsOrFail.fold(
(apps) => state.copyWith(apps: some(apps), successOrFailure: left(unit)),
(err) => state.copyWith(successOrFailure: right(err)),
);
},
);
}
@override
Future<void> close() async {
await listener.stop();
return super.close();
}
Stream<MenuState> _performActionOnOpenPage(OpenPage e) async* {
yield state.copyWith(context: e.context);
}
@ -63,6 +77,13 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> {
},
);
}
void _handleAppsOrFail(Either<List<App>, WorkspaceError> appsOrFail) {
appsOrFail.fold(
(apps) => add(MenuEvent.didReceiveApps(left(apps))),
(error) => add(MenuEvent.didReceiveApps(right(error))),
);
}
}
@freezed
@ -71,6 +92,7 @@ class MenuEvent with _$MenuEvent {
const factory MenuEvent.collapse() = Collapse;
const factory MenuEvent.openPage(HomeStackContext context) = OpenPage;
const factory MenuEvent.createApp(String name, {String? desc}) = CreateApp;
const factory MenuEvent.didReceiveApps(Either<List<App>, WorkspaceError> appsOrFail) = ReceiveApps;
}
@freezed

View File

@ -36,6 +36,12 @@ class _$MenuEventTearOff {
desc: desc,
);
}
ReceiveApps didReceiveApps(Either<List<App>, WorkspaceError> appsOrFail) {
return ReceiveApps(
appsOrFail,
);
}
}
/// @nodoc
@ -49,6 +55,8 @@ mixin _$MenuEvent {
required TResult Function() collapse,
required TResult Function(HomeStackContext context) openPage,
required TResult Function(String name, String? desc) createApp,
required TResult Function(Either<List<App>, WorkspaceError> appsOrFail)
didReceiveApps,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
@ -57,6 +65,8 @@ mixin _$MenuEvent {
TResult Function()? collapse,
TResult Function(HomeStackContext context)? openPage,
TResult Function(String name, String? desc)? createApp,
TResult Function(Either<List<App>, WorkspaceError> appsOrFail)?
didReceiveApps,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@ -66,6 +76,7 @@ mixin _$MenuEvent {
required TResult Function(Collapse value) collapse,
required TResult Function(OpenPage value) openPage,
required TResult Function(CreateApp value) createApp,
required TResult Function(ReceiveApps value) didReceiveApps,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
@ -74,6 +85,7 @@ mixin _$MenuEvent {
TResult Function(Collapse value)? collapse,
TResult Function(OpenPage value)? openPage,
TResult Function(CreateApp value)? createApp,
TResult Function(ReceiveApps value)? didReceiveApps,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@ -135,6 +147,8 @@ class _$_Initial implements _Initial {
required TResult Function() collapse,
required TResult Function(HomeStackContext context) openPage,
required TResult Function(String name, String? desc) createApp,
required TResult Function(Either<List<App>, WorkspaceError> appsOrFail)
didReceiveApps,
}) {
return initial();
}
@ -146,6 +160,8 @@ class _$_Initial implements _Initial {
TResult Function()? collapse,
TResult Function(HomeStackContext context)? openPage,
TResult Function(String name, String? desc)? createApp,
TResult Function(Either<List<App>, WorkspaceError> appsOrFail)?
didReceiveApps,
required TResult orElse(),
}) {
if (initial != null) {
@ -161,6 +177,7 @@ class _$_Initial implements _Initial {
required TResult Function(Collapse value) collapse,
required TResult Function(OpenPage value) openPage,
required TResult Function(CreateApp value) createApp,
required TResult Function(ReceiveApps value) didReceiveApps,
}) {
return initial(this);
}
@ -172,6 +189,7 @@ class _$_Initial implements _Initial {
TResult Function(Collapse value)? collapse,
TResult Function(OpenPage value)? openPage,
TResult Function(CreateApp value)? createApp,
TResult Function(ReceiveApps value)? didReceiveApps,
required TResult orElse(),
}) {
if (initial != null) {
@ -226,6 +244,8 @@ class _$Collapse implements Collapse {
required TResult Function() collapse,
required TResult Function(HomeStackContext context) openPage,
required TResult Function(String name, String? desc) createApp,
required TResult Function(Either<List<App>, WorkspaceError> appsOrFail)
didReceiveApps,
}) {
return collapse();
}
@ -237,6 +257,8 @@ class _$Collapse implements Collapse {
TResult Function()? collapse,
TResult Function(HomeStackContext context)? openPage,
TResult Function(String name, String? desc)? createApp,
TResult Function(Either<List<App>, WorkspaceError> appsOrFail)?
didReceiveApps,
required TResult orElse(),
}) {
if (collapse != null) {
@ -252,6 +274,7 @@ class _$Collapse implements Collapse {
required TResult Function(Collapse value) collapse,
required TResult Function(OpenPage value) openPage,
required TResult Function(CreateApp value) createApp,
required TResult Function(ReceiveApps value) didReceiveApps,
}) {
return collapse(this);
}
@ -263,6 +286,7 @@ class _$Collapse implements Collapse {
TResult Function(Collapse value)? collapse,
TResult Function(OpenPage value)? openPage,
TResult Function(CreateApp value)? createApp,
TResult Function(ReceiveApps value)? didReceiveApps,
required TResult orElse(),
}) {
if (collapse != null) {
@ -342,6 +366,8 @@ class _$OpenPage implements OpenPage {
required TResult Function() collapse,
required TResult Function(HomeStackContext context) openPage,
required TResult Function(String name, String? desc) createApp,
required TResult Function(Either<List<App>, WorkspaceError> appsOrFail)
didReceiveApps,
}) {
return openPage(context);
}
@ -353,6 +379,8 @@ class _$OpenPage implements OpenPage {
TResult Function()? collapse,
TResult Function(HomeStackContext context)? openPage,
TResult Function(String name, String? desc)? createApp,
TResult Function(Either<List<App>, WorkspaceError> appsOrFail)?
didReceiveApps,
required TResult orElse(),
}) {
if (openPage != null) {
@ -368,6 +396,7 @@ class _$OpenPage implements OpenPage {
required TResult Function(Collapse value) collapse,
required TResult Function(OpenPage value) openPage,
required TResult Function(CreateApp value) createApp,
required TResult Function(ReceiveApps value) didReceiveApps,
}) {
return openPage(this);
}
@ -379,6 +408,7 @@ class _$OpenPage implements OpenPage {
TResult Function(Collapse value)? collapse,
TResult Function(OpenPage value)? openPage,
TResult Function(CreateApp value)? createApp,
TResult Function(ReceiveApps value)? didReceiveApps,
required TResult orElse(),
}) {
if (openPage != null) {
@ -474,6 +504,8 @@ class _$CreateApp implements CreateApp {
required TResult Function() collapse,
required TResult Function(HomeStackContext context) openPage,
required TResult Function(String name, String? desc) createApp,
required TResult Function(Either<List<App>, WorkspaceError> appsOrFail)
didReceiveApps,
}) {
return createApp(name, desc);
}
@ -485,6 +517,8 @@ class _$CreateApp implements CreateApp {
TResult Function()? collapse,
TResult Function(HomeStackContext context)? openPage,
TResult Function(String name, String? desc)? createApp,
TResult Function(Either<List<App>, WorkspaceError> appsOrFail)?
didReceiveApps,
required TResult orElse(),
}) {
if (createApp != null) {
@ -500,6 +534,7 @@ class _$CreateApp implements CreateApp {
required TResult Function(Collapse value) collapse,
required TResult Function(OpenPage value) openPage,
required TResult Function(CreateApp value) createApp,
required TResult Function(ReceiveApps value) didReceiveApps,
}) {
return createApp(this);
}
@ -511,6 +546,7 @@ class _$CreateApp implements CreateApp {
TResult Function(Collapse value)? collapse,
TResult Function(OpenPage value)? openPage,
TResult Function(CreateApp value)? createApp,
TResult Function(ReceiveApps value)? didReceiveApps,
required TResult orElse(),
}) {
if (createApp != null) {
@ -530,6 +566,138 @@ abstract class CreateApp implements MenuEvent {
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ReceiveAppsCopyWith<$Res> {
factory $ReceiveAppsCopyWith(
ReceiveApps value, $Res Function(ReceiveApps) then) =
_$ReceiveAppsCopyWithImpl<$Res>;
$Res call({Either<List<App>, WorkspaceError> appsOrFail});
}
/// @nodoc
class _$ReceiveAppsCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res>
implements $ReceiveAppsCopyWith<$Res> {
_$ReceiveAppsCopyWithImpl(
ReceiveApps _value, $Res Function(ReceiveApps) _then)
: super(_value, (v) => _then(v as ReceiveApps));
@override
ReceiveApps get _value => super._value as ReceiveApps;
@override
$Res call({
Object? appsOrFail = freezed,
}) {
return _then(ReceiveApps(
appsOrFail == freezed
? _value.appsOrFail
: appsOrFail // ignore: cast_nullable_to_non_nullable
as Either<List<App>, WorkspaceError>,
));
}
}
/// @nodoc
class _$ReceiveApps implements ReceiveApps {
const _$ReceiveApps(this.appsOrFail);
@override
final Either<List<App>, WorkspaceError> appsOrFail;
@override
String toString() {
return 'MenuEvent.didReceiveApps(appsOrFail: $appsOrFail)';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other is ReceiveApps &&
(identical(other.appsOrFail, appsOrFail) ||
const DeepCollectionEquality()
.equals(other.appsOrFail, appsOrFail)));
}
@override
int get hashCode =>
runtimeType.hashCode ^ const DeepCollectionEquality().hash(appsOrFail);
@JsonKey(ignore: true)
@override
$ReceiveAppsCopyWith<ReceiveApps> get copyWith =>
_$ReceiveAppsCopyWithImpl<ReceiveApps>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() collapse,
required TResult Function(HomeStackContext context) openPage,
required TResult Function(String name, String? desc) createApp,
required TResult Function(Either<List<App>, WorkspaceError> appsOrFail)
didReceiveApps,
}) {
return didReceiveApps(appsOrFail);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? collapse,
TResult Function(HomeStackContext context)? openPage,
TResult Function(String name, String? desc)? createApp,
TResult Function(Either<List<App>, WorkspaceError> appsOrFail)?
didReceiveApps,
required TResult orElse(),
}) {
if (didReceiveApps != null) {
return didReceiveApps(appsOrFail);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(Collapse value) collapse,
required TResult Function(OpenPage value) openPage,
required TResult Function(CreateApp value) createApp,
required TResult Function(ReceiveApps value) didReceiveApps,
}) {
return didReceiveApps(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(Collapse value)? collapse,
TResult Function(OpenPage value)? openPage,
TResult Function(CreateApp value)? createApp,
TResult Function(ReceiveApps value)? didReceiveApps,
required TResult orElse(),
}) {
if (didReceiveApps != null) {
return didReceiveApps(this);
}
return orElse();
}
}
abstract class ReceiveApps implements MenuEvent {
const factory ReceiveApps(Either<List<App>, WorkspaceError> appsOrFail) =
_$ReceiveApps;
Either<List<App>, WorkspaceError> get appsOrFail =>
throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$ReceiveAppsCopyWith<ReceiveApps> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
class _$MenuStateTearOff {
const _$MenuStateTearOff();

View File

@ -1,67 +0,0 @@
import 'package:app_flowy/workspace/domain/i_workspace.dart';
import 'package:flowy_log/flowy_log.dart';
import 'package:flowy_sdk/protobuf/flowy-workspace/app_create.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:dartz/dartz.dart';
part 'menu_listen.freezed.dart';
class MenuListenBloc extends Bloc<MenuListenEvent, MenuListenState> {
final IWorkspaceListener listener;
MenuListenBloc(this.listener) : super(const MenuListenState.initial());
@override
Stream<MenuListenState> mapEventToState(MenuListenEvent event) async* {
yield* event.map(
started: (_) async* {
listener.start(
addAppCallback: (appsOrFail) => _handleAppsOrFail(appsOrFail),
);
},
appsReceived: (e) async* {
yield e.appsOrFail.fold(
(apps) => MenuListenState.loadApps(apps),
(error) => MenuListenState.loadFail(error),
);
},
);
}
@override
Future<void> close() async {
await listener.stop();
return super.close();
}
void _handleAppsOrFail(Either<List<App>, WorkspaceError> appsOrFail) {
appsOrFail.fold(
(apps) => add(MenuListenEvent.appsReceived(left(apps))),
(error) {
Log.error(error);
add(MenuListenEvent.appsReceived(right(error)));
},
);
}
}
@freezed
class MenuListenEvent with _$MenuListenEvent {
const factory MenuListenEvent.started() = _Started;
const factory MenuListenEvent.appsReceived(Either<List<App>, WorkspaceError> appsOrFail) = AppsReceived;
}
@freezed
class MenuListenState with _$MenuListenState {
const factory MenuListenState.initial() = _Initial;
const factory MenuListenState.loadApps(
List<App> apps,
) = _LoadApps;
const factory MenuListenState.loadFail(
WorkspaceError error,
) = _LoadFail;
}

View File

@ -1,682 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target
part of 'menu_listen.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
/// @nodoc
class _$MenuListenEventTearOff {
const _$MenuListenEventTearOff();
_Started started() {
return const _Started();
}
AppsReceived appsReceived(Either<List<App>, WorkspaceError> appsOrFail) {
return AppsReceived(
appsOrFail,
);
}
}
/// @nodoc
const $MenuListenEvent = _$MenuListenEventTearOff();
/// @nodoc
mixin _$MenuListenEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function(Either<List<App>, WorkspaceError> appsOrFail)
appsReceived,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function(Either<List<App>, WorkspaceError> appsOrFail)?
appsReceived,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Started value) started,
required TResult Function(AppsReceived value) appsReceived,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Started value)? started,
TResult Function(AppsReceived value)? appsReceived,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $MenuListenEventCopyWith<$Res> {
factory $MenuListenEventCopyWith(
MenuListenEvent value, $Res Function(MenuListenEvent) then) =
_$MenuListenEventCopyWithImpl<$Res>;
}
/// @nodoc
class _$MenuListenEventCopyWithImpl<$Res>
implements $MenuListenEventCopyWith<$Res> {
_$MenuListenEventCopyWithImpl(this._value, this._then);
final MenuListenEvent _value;
// ignore: unused_field
final $Res Function(MenuListenEvent) _then;
}
/// @nodoc
abstract class _$StartedCopyWith<$Res> {
factory _$StartedCopyWith(_Started value, $Res Function(_Started) then) =
__$StartedCopyWithImpl<$Res>;
}
/// @nodoc
class __$StartedCopyWithImpl<$Res> extends _$MenuListenEventCopyWithImpl<$Res>
implements _$StartedCopyWith<$Res> {
__$StartedCopyWithImpl(_Started _value, $Res Function(_Started) _then)
: super(_value, (v) => _then(v as _Started));
@override
_Started get _value => super._value as _Started;
}
/// @nodoc
class _$_Started implements _Started {
const _$_Started();
@override
String toString() {
return 'MenuListenEvent.started()';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) || (other is _Started);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function(Either<List<App>, WorkspaceError> appsOrFail)
appsReceived,
}) {
return started();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function(Either<List<App>, WorkspaceError> appsOrFail)?
appsReceived,
required TResult orElse(),
}) {
if (started != null) {
return started();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Started value) started,
required TResult Function(AppsReceived value) appsReceived,
}) {
return started(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Started value)? started,
TResult Function(AppsReceived value)? appsReceived,
required TResult orElse(),
}) {
if (started != null) {
return started(this);
}
return orElse();
}
}
abstract class _Started implements MenuListenEvent {
const factory _Started() = _$_Started;
}
/// @nodoc
abstract class $AppsReceivedCopyWith<$Res> {
factory $AppsReceivedCopyWith(
AppsReceived value, $Res Function(AppsReceived) then) =
_$AppsReceivedCopyWithImpl<$Res>;
$Res call({Either<List<App>, WorkspaceError> appsOrFail});
}
/// @nodoc
class _$AppsReceivedCopyWithImpl<$Res>
extends _$MenuListenEventCopyWithImpl<$Res>
implements $AppsReceivedCopyWith<$Res> {
_$AppsReceivedCopyWithImpl(
AppsReceived _value, $Res Function(AppsReceived) _then)
: super(_value, (v) => _then(v as AppsReceived));
@override
AppsReceived get _value => super._value as AppsReceived;
@override
$Res call({
Object? appsOrFail = freezed,
}) {
return _then(AppsReceived(
appsOrFail == freezed
? _value.appsOrFail
: appsOrFail // ignore: cast_nullable_to_non_nullable
as Either<List<App>, WorkspaceError>,
));
}
}
/// @nodoc
class _$AppsReceived implements AppsReceived {
const _$AppsReceived(this.appsOrFail);
@override
final Either<List<App>, WorkspaceError> appsOrFail;
@override
String toString() {
return 'MenuListenEvent.appsReceived(appsOrFail: $appsOrFail)';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other is AppsReceived &&
(identical(other.appsOrFail, appsOrFail) ||
const DeepCollectionEquality()
.equals(other.appsOrFail, appsOrFail)));
}
@override
int get hashCode =>
runtimeType.hashCode ^ const DeepCollectionEquality().hash(appsOrFail);
@JsonKey(ignore: true)
@override
$AppsReceivedCopyWith<AppsReceived> get copyWith =>
_$AppsReceivedCopyWithImpl<AppsReceived>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function(Either<List<App>, WorkspaceError> appsOrFail)
appsReceived,
}) {
return appsReceived(appsOrFail);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function(Either<List<App>, WorkspaceError> appsOrFail)?
appsReceived,
required TResult orElse(),
}) {
if (appsReceived != null) {
return appsReceived(appsOrFail);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Started value) started,
required TResult Function(AppsReceived value) appsReceived,
}) {
return appsReceived(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Started value)? started,
TResult Function(AppsReceived value)? appsReceived,
required TResult orElse(),
}) {
if (appsReceived != null) {
return appsReceived(this);
}
return orElse();
}
}
abstract class AppsReceived implements MenuListenEvent {
const factory AppsReceived(Either<List<App>, WorkspaceError> appsOrFail) =
_$AppsReceived;
Either<List<App>, WorkspaceError> get appsOrFail =>
throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$AppsReceivedCopyWith<AppsReceived> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
class _$MenuListenStateTearOff {
const _$MenuListenStateTearOff();
_Initial initial() {
return const _Initial();
}
_LoadApps loadApps(List<App> apps) {
return _LoadApps(
apps,
);
}
_LoadFail loadFail(WorkspaceError error) {
return _LoadFail(
error,
);
}
}
/// @nodoc
const $MenuListenState = _$MenuListenStateTearOff();
/// @nodoc
mixin _$MenuListenState {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function(List<App> apps) loadApps,
required TResult Function(WorkspaceError error) loadFail,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function(List<App> apps)? loadApps,
TResult Function(WorkspaceError error)? loadFail,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_LoadApps value) loadApps,
required TResult Function(_LoadFail value) loadFail,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_LoadApps value)? loadApps,
TResult Function(_LoadFail value)? loadFail,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $MenuListenStateCopyWith<$Res> {
factory $MenuListenStateCopyWith(
MenuListenState value, $Res Function(MenuListenState) then) =
_$MenuListenStateCopyWithImpl<$Res>;
}
/// @nodoc
class _$MenuListenStateCopyWithImpl<$Res>
implements $MenuListenStateCopyWith<$Res> {
_$MenuListenStateCopyWithImpl(this._value, this._then);
final MenuListenState _value;
// ignore: unused_field
final $Res Function(MenuListenState) _then;
}
/// @nodoc
abstract class _$InitialCopyWith<$Res> {
factory _$InitialCopyWith(_Initial value, $Res Function(_Initial) then) =
__$InitialCopyWithImpl<$Res>;
}
/// @nodoc
class __$InitialCopyWithImpl<$Res> extends _$MenuListenStateCopyWithImpl<$Res>
implements _$InitialCopyWith<$Res> {
__$InitialCopyWithImpl(_Initial _value, $Res Function(_Initial) _then)
: super(_value, (v) => _then(v as _Initial));
@override
_Initial get _value => super._value as _Initial;
}
/// @nodoc
class _$_Initial implements _Initial {
const _$_Initial();
@override
String toString() {
return 'MenuListenState.initial()';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) || (other is _Initial);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function(List<App> apps) loadApps,
required TResult Function(WorkspaceError error) loadFail,
}) {
return initial();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function(List<App> apps)? loadApps,
TResult Function(WorkspaceError error)? loadFail,
required TResult orElse(),
}) {
if (initial != null) {
return initial();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_LoadApps value) loadApps,
required TResult Function(_LoadFail value) loadFail,
}) {
return initial(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_LoadApps value)? loadApps,
TResult Function(_LoadFail value)? loadFail,
required TResult orElse(),
}) {
if (initial != null) {
return initial(this);
}
return orElse();
}
}
abstract class _Initial implements MenuListenState {
const factory _Initial() = _$_Initial;
}
/// @nodoc
abstract class _$LoadAppsCopyWith<$Res> {
factory _$LoadAppsCopyWith(_LoadApps value, $Res Function(_LoadApps) then) =
__$LoadAppsCopyWithImpl<$Res>;
$Res call({List<App> apps});
}
/// @nodoc
class __$LoadAppsCopyWithImpl<$Res> extends _$MenuListenStateCopyWithImpl<$Res>
implements _$LoadAppsCopyWith<$Res> {
__$LoadAppsCopyWithImpl(_LoadApps _value, $Res Function(_LoadApps) _then)
: super(_value, (v) => _then(v as _LoadApps));
@override
_LoadApps get _value => super._value as _LoadApps;
@override
$Res call({
Object? apps = freezed,
}) {
return _then(_LoadApps(
apps == freezed
? _value.apps
: apps // ignore: cast_nullable_to_non_nullable
as List<App>,
));
}
}
/// @nodoc
class _$_LoadApps implements _LoadApps {
const _$_LoadApps(this.apps);
@override
final List<App> apps;
@override
String toString() {
return 'MenuListenState.loadApps(apps: $apps)';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other is _LoadApps &&
(identical(other.apps, apps) ||
const DeepCollectionEquality().equals(other.apps, apps)));
}
@override
int get hashCode =>
runtimeType.hashCode ^ const DeepCollectionEquality().hash(apps);
@JsonKey(ignore: true)
@override
_$LoadAppsCopyWith<_LoadApps> get copyWith =>
__$LoadAppsCopyWithImpl<_LoadApps>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function(List<App> apps) loadApps,
required TResult Function(WorkspaceError error) loadFail,
}) {
return loadApps(apps);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function(List<App> apps)? loadApps,
TResult Function(WorkspaceError error)? loadFail,
required TResult orElse(),
}) {
if (loadApps != null) {
return loadApps(apps);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_LoadApps value) loadApps,
required TResult Function(_LoadFail value) loadFail,
}) {
return loadApps(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_LoadApps value)? loadApps,
TResult Function(_LoadFail value)? loadFail,
required TResult orElse(),
}) {
if (loadApps != null) {
return loadApps(this);
}
return orElse();
}
}
abstract class _LoadApps implements MenuListenState {
const factory _LoadApps(List<App> apps) = _$_LoadApps;
List<App> get apps => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
_$LoadAppsCopyWith<_LoadApps> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class _$LoadFailCopyWith<$Res> {
factory _$LoadFailCopyWith(_LoadFail value, $Res Function(_LoadFail) then) =
__$LoadFailCopyWithImpl<$Res>;
$Res call({WorkspaceError error});
}
/// @nodoc
class __$LoadFailCopyWithImpl<$Res> extends _$MenuListenStateCopyWithImpl<$Res>
implements _$LoadFailCopyWith<$Res> {
__$LoadFailCopyWithImpl(_LoadFail _value, $Res Function(_LoadFail) _then)
: super(_value, (v) => _then(v as _LoadFail));
@override
_LoadFail get _value => super._value as _LoadFail;
@override
$Res call({
Object? error = freezed,
}) {
return _then(_LoadFail(
error == freezed
? _value.error
: error // ignore: cast_nullable_to_non_nullable
as WorkspaceError,
));
}
}
/// @nodoc
class _$_LoadFail implements _LoadFail {
const _$_LoadFail(this.error);
@override
final WorkspaceError error;
@override
String toString() {
return 'MenuListenState.loadFail(error: $error)';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other is _LoadFail &&
(identical(other.error, error) ||
const DeepCollectionEquality().equals(other.error, error)));
}
@override
int get hashCode =>
runtimeType.hashCode ^ const DeepCollectionEquality().hash(error);
@JsonKey(ignore: true)
@override
_$LoadFailCopyWith<_LoadFail> get copyWith =>
__$LoadFailCopyWithImpl<_LoadFail>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function(List<App> apps) loadApps,
required TResult Function(WorkspaceError error) loadFail,
}) {
return loadFail(error);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function(List<App> apps)? loadApps,
TResult Function(WorkspaceError error)? loadFail,
required TResult orElse(),
}) {
if (loadFail != null) {
return loadFail(error);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_LoadApps value) loadApps,
required TResult Function(_LoadFail value) loadFail,
}) {
return loadFail(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_LoadApps value)? loadApps,
TResult Function(_LoadFail value)? loadFail,
required TResult orElse(),
}) {
if (loadFail != null) {
return loadFail(this);
}
return orElse();
}
}
abstract class _LoadFail implements MenuListenState {
const factory _LoadFail(WorkspaceError error) = _$_LoadFail;
WorkspaceError get error => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
_$LoadFailCopyWith<_LoadFail> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@ -3,7 +3,6 @@ import 'package:app_flowy/workspace/application/doc/doc_bloc.dart';
import 'package:app_flowy/workspace/application/doc/doc_edit_bloc.dart';
import 'package:app_flowy/workspace/application/menu/menu_bloc.dart';
import 'package:app_flowy/workspace/application/menu/menu_user_bloc.dart';
import 'package:app_flowy/workspace/application/menu/menu_listen.dart';
import 'package:app_flowy/workspace/application/trash/trash_bloc.dart';
import 'package:app_flowy/workspace/application/view/view_bloc.dart';
import 'package:app_flowy/workspace/application/workspace/welcome_bloc.dart';
@ -69,9 +68,11 @@ class HomeDepsResolver {
//Menu Bloc
getIt.registerFactoryParam<MenuBloc, UserProfile, String>(
(user, workspaceId) => MenuBloc(getIt<IWorkspace>(param1: user, param2: workspaceId)));
getIt.registerFactoryParam<MenuListenBloc, UserProfile, String>(
(user, workspaceId) => MenuListenBloc(getIt<IWorkspaceListener>(param1: user, param2: workspaceId)));
(user, workspaceId) => MenuBloc(
workspaceManager: getIt<IWorkspace>(param1: user, param2: workspaceId),
listener: getIt<IWorkspaceListener>(param1: user, param2: workspaceId),
),
);
getIt.registerFactoryParam<MenuUserBloc, UserProfile, void>(
(user, _) => MenuUserBloc(getIt<IUser>(param1: user), getIt<IUserListener>(param1: user)));

View File

@ -13,7 +13,6 @@ import 'package:expandable/expandable.dart';
import 'package:flowy_infra/time/duration.dart';
import 'package:app_flowy/startup/startup.dart';
import 'package:app_flowy/workspace/application/menu/menu_bloc.dart';
import 'package:app_flowy/workspace/application/menu/menu_listen.dart';
import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart';
import 'package:app_flowy/workspace/presentation/widgets/menu/widget/menu_user.dart';
@ -64,9 +63,6 @@ class HomeMenu extends StatelessWidget {
providers: [
BlocProvider<MenuBloc>(
create: (context) => getIt<MenuBloc>(param1: user, param2: workspaceId)..add(const MenuEvent.initial())),
BlocProvider(
create: (context) =>
getIt<MenuListenBloc>(param1: user, param2: workspaceId)..add(const MenuListenEvent.started())),
],
child: MultiBlocListener(
listeners: [
@ -113,18 +109,8 @@ class HomeMenu extends StatelessWidget {
}
Widget _renderMenuList(BuildContext context) {
return BlocBuilder<MenuListenBloc, MenuListenState>(
builder: (context, state) {
return state.map(
initial: (_) => MenuList(
menuItems: buildMenuItems(context.read<MenuBloc>().state.apps),
),
loadApps: (s) => MenuList(
menuItems: buildMenuItems(some(s.apps)),
),
loadFail: (s) => FlowyErrorPage(s.error.toString()),
);
},
return MenuList(
menuItems: buildMenuItems(context.read<MenuBloc>().state.apps),
);
}

View File

@ -109,6 +109,7 @@ struct RevisionServerImpl {
}
impl RevisionServer for RevisionServerImpl {
#[tracing::instrument(level = "debug", skip(self))]
fn fetch_document_from_remote(&self, doc_id: &str) -> ResultFuture<Doc, DocError> {
let params = DocIdentifier {
doc_id: doc_id.to_string(),