chore: save app order

This commit is contained in:
appflowy 2022-04-27 07:22:18 +08:00
parent 7f7801d04e
commit e8bb6f0a7f
6 changed files with 427 additions and 236 deletions

View File

@ -99,7 +99,6 @@ void _resolveFolderDeps(GetIt getIt) {
getIt.registerFactoryParam<MenuBloc, UserProfile, String>( getIt.registerFactoryParam<MenuBloc, UserProfile, String>(
(user, workspaceId) => MenuBloc( (user, workspaceId) => MenuBloc(
workspaceId: workspaceId, workspaceId: workspaceId,
service: WorkspaceService(),
listener: getIt<WorkspaceListener>(param1: user, param2: workspaceId), listener: getIt<WorkspaceListener>(param1: user, param2: workspaceId),
), ),
); );

View File

@ -12,11 +12,13 @@ import 'package:flutter_bloc/flutter_bloc.dart';
part 'menu_bloc.freezed.dart'; part 'menu_bloc.freezed.dart';
class MenuBloc extends Bloc<MenuEvent, MenuState> { class MenuBloc extends Bloc<MenuEvent, MenuState> {
final WorkspaceService service; final WorkspaceService _workspaceService;
final WorkspaceListener listener; final WorkspaceListener listener;
final String workspaceId; final String workspaceId;
MenuBloc({required this.workspaceId, required this.service, required this.listener}) : super(MenuState.initial()) { MenuBloc({required this.workspaceId, required this.listener})
: _workspaceService = WorkspaceService(workspaceId: workspaceId),
super(MenuState.initial()) {
on<MenuEvent>((event, emit) async { on<MenuEvent>((event, emit) async {
await event.map( await event.map(
initial: (e) async { initial: (e) async {
@ -30,15 +32,21 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> {
openPage: (e) async { openPage: (e) async {
emit(state.copyWith(plugin: e.plugin)); emit(state.copyWith(plugin: e.plugin));
}, },
createApp: (CreateApp event) async { createApp: (_CreateApp event) async {
await _performActionOnCreateApp(event, emit); await _performActionOnCreateApp(event, emit);
}, },
didReceiveApps: (e) async { didReceiveApps: (e) async {
emit(e.appsOrFail.fold( emit(e.appsOrFail.fold(
(apps) => state.copyWith(apps: some(apps), successOrFailure: left(unit)), (apps) => state.copyWith(apps: apps, successOrFailure: left(unit)),
(err) => state.copyWith(successOrFailure: right(err)), (err) => state.copyWith(successOrFailure: right(err)),
)); ));
}, },
moveApp: (_MoveApp value) {
if (state.apps.length > value.fromIndex) {
final app = state.apps[value.fromIndex];
_workspaceService.moveApp(appId: app.id, fromIndex: value.fromIndex, toIndex: value.toIndex);
}
},
); );
}); });
} }
@ -49,8 +57,8 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> {
return super.close(); return super.close();
} }
Future<void> _performActionOnCreateApp(CreateApp event, Emitter<MenuState> emit) async { Future<void> _performActionOnCreateApp(_CreateApp event, Emitter<MenuState> emit) async {
final result = await service.createApp(workspaceId: workspaceId, name: event.name, desc: event.desc ?? ""); final result = await _workspaceService.createApp(name: event.name, desc: event.desc ?? "");
result.fold( result.fold(
(app) => {}, (app) => {},
(error) { (error) {
@ -62,9 +70,9 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> {
// ignore: unused_element // ignore: unused_element
Future<void> _fetchApps(Emitter<MenuState> emit) async { Future<void> _fetchApps(Emitter<MenuState> emit) async {
final appsOrFail = await service.getApps(workspaceId: workspaceId); final appsOrFail = await _workspaceService.getApps();
emit(appsOrFail.fold( emit(appsOrFail.fold(
(apps) => state.copyWith(apps: some(apps)), (apps) => state.copyWith(apps: apps),
(error) { (error) {
Log.error(error); Log.error(error);
return state.copyWith(successOrFailure: right(error)); return state.copyWith(successOrFailure: right(error));
@ -83,24 +91,25 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> {
@freezed @freezed
class MenuEvent with _$MenuEvent { class MenuEvent with _$MenuEvent {
const factory MenuEvent.initial() = _Initial; const factory MenuEvent.initial() = _Initial;
const factory MenuEvent.collapse() = Collapse; const factory MenuEvent.collapse() = _Collapse;
const factory MenuEvent.openPage(Plugin plugin) = OpenPage; const factory MenuEvent.openPage(Plugin plugin) = _OpenPage;
const factory MenuEvent.createApp(String name, {String? desc}) = CreateApp; const factory MenuEvent.createApp(String name, {String? desc}) = _CreateApp;
const factory MenuEvent.didReceiveApps(Either<List<App>, FlowyError> appsOrFail) = ReceiveApps; const factory MenuEvent.moveApp(int fromIndex, int toIndex) = _MoveApp;
const factory MenuEvent.didReceiveApps(Either<List<App>, FlowyError> appsOrFail) = _ReceiveApps;
} }
@freezed @freezed
class MenuState with _$MenuState { class MenuState with _$MenuState {
const factory MenuState({ const factory MenuState({
required bool isCollapse, required bool isCollapse,
required Option<List<App>> apps, required List<App> apps,
required Either<Unit, FlowyError> successOrFailure, required Either<Unit, FlowyError> successOrFailure,
required Plugin plugin, required Plugin plugin,
}) = _MenuState; }) = _MenuState;
factory MenuState.initial() => MenuState( factory MenuState.initial() => MenuState(
isCollapse: false, isCollapse: false,
apps: none(), apps: [],
successOrFailure: left(unit), successOrFailure: left(unit),
plugin: makePlugin(pluginType: DefaultPlugin.blank.type()), plugin: makePlugin(pluginType: DefaultPlugin.blank.type()),
); );

View File

@ -21,25 +21,32 @@ class _$MenuEventTearOff {
return const _Initial(); return const _Initial();
} }
Collapse collapse() { _Collapse collapse() {
return const Collapse(); return const _Collapse();
} }
OpenPage openPage(Plugin plugin) { _OpenPage openPage(Plugin plugin) {
return OpenPage( return _OpenPage(
plugin, plugin,
); );
} }
CreateApp createApp(String name, {String? desc}) { _CreateApp createApp(String name, {String? desc}) {
return CreateApp( return _CreateApp(
name, name,
desc: desc, desc: desc,
); );
} }
ReceiveApps didReceiveApps(Either<List<App>, FlowyError> appsOrFail) { _MoveApp moveApp(int fromIndex, int toIndex) {
return ReceiveApps( return _MoveApp(
fromIndex,
toIndex,
);
}
_ReceiveApps didReceiveApps(Either<List<App>, FlowyError> appsOrFail) {
return _ReceiveApps(
appsOrFail, appsOrFail,
); );
} }
@ -56,6 +63,7 @@ mixin _$MenuEvent {
required TResult Function() collapse, required TResult Function() collapse,
required TResult Function(Plugin plugin) openPage, required TResult Function(Plugin plugin) openPage,
required TResult Function(String name, String? desc) createApp, required TResult Function(String name, String? desc) createApp,
required TResult Function(int fromIndex, int toIndex) moveApp,
required TResult Function(Either<List<App>, FlowyError> appsOrFail) required TResult Function(Either<List<App>, FlowyError> appsOrFail)
didReceiveApps, didReceiveApps,
}) => }) =>
@ -66,6 +74,7 @@ mixin _$MenuEvent {
TResult Function()? collapse, TResult Function()? collapse,
TResult Function(Plugin plugin)? openPage, TResult Function(Plugin plugin)? openPage,
TResult Function(String name, String? desc)? createApp, TResult Function(String name, String? desc)? createApp,
TResult Function(int fromIndex, int toIndex)? moveApp,
TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps, TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@ -75,6 +84,7 @@ mixin _$MenuEvent {
TResult Function()? collapse, TResult Function()? collapse,
TResult Function(Plugin plugin)? openPage, TResult Function(Plugin plugin)? openPage,
TResult Function(String name, String? desc)? createApp, TResult Function(String name, String? desc)? createApp,
TResult Function(int fromIndex, int toIndex)? moveApp,
TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps, TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps,
required TResult orElse(), required TResult orElse(),
}) => }) =>
@ -82,28 +92,31 @@ mixin _$MenuEvent {
@optionalTypeArgs @optionalTypeArgs
TResult map<TResult extends Object?>({ TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(Collapse value) collapse, required TResult Function(_Collapse value) collapse,
required TResult Function(OpenPage value) openPage, required TResult Function(_OpenPage value) openPage,
required TResult Function(CreateApp value) createApp, required TResult Function(_CreateApp value) createApp,
required TResult Function(ReceiveApps value) didReceiveApps, required TResult Function(_MoveApp value) moveApp,
required TResult Function(_ReceiveApps value) didReceiveApps,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({ TResult? mapOrNull<TResult extends Object?>({
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(Collapse value)? collapse, TResult Function(_Collapse value)? collapse,
TResult Function(OpenPage value)? openPage, TResult Function(_OpenPage value)? openPage,
TResult Function(CreateApp value)? createApp, TResult Function(_CreateApp value)? createApp,
TResult Function(ReceiveApps value)? didReceiveApps, TResult Function(_MoveApp value)? moveApp,
TResult Function(_ReceiveApps value)? didReceiveApps,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
TResult maybeMap<TResult extends Object?>({ TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(Collapse value)? collapse, TResult Function(_Collapse value)? collapse,
TResult Function(OpenPage value)? openPage, TResult Function(_OpenPage value)? openPage,
TResult Function(CreateApp value)? createApp, TResult Function(_CreateApp value)? createApp,
TResult Function(ReceiveApps value)? didReceiveApps, TResult Function(_MoveApp value)? moveApp,
TResult Function(_ReceiveApps value)? didReceiveApps,
required TResult orElse(), required TResult orElse(),
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@ -165,6 +178,7 @@ class _$_Initial implements _Initial {
required TResult Function() collapse, required TResult Function() collapse,
required TResult Function(Plugin plugin) openPage, required TResult Function(Plugin plugin) openPage,
required TResult Function(String name, String? desc) createApp, required TResult Function(String name, String? desc) createApp,
required TResult Function(int fromIndex, int toIndex) moveApp,
required TResult Function(Either<List<App>, FlowyError> appsOrFail) required TResult Function(Either<List<App>, FlowyError> appsOrFail)
didReceiveApps, didReceiveApps,
}) { }) {
@ -178,6 +192,7 @@ class _$_Initial implements _Initial {
TResult Function()? collapse, TResult Function()? collapse,
TResult Function(Plugin plugin)? openPage, TResult Function(Plugin plugin)? openPage,
TResult Function(String name, String? desc)? createApp, TResult Function(String name, String? desc)? createApp,
TResult Function(int fromIndex, int toIndex)? moveApp,
TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps, TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps,
}) { }) {
return initial?.call(); return initial?.call();
@ -190,6 +205,7 @@ class _$_Initial implements _Initial {
TResult Function()? collapse, TResult Function()? collapse,
TResult Function(Plugin plugin)? openPage, TResult Function(Plugin plugin)? openPage,
TResult Function(String name, String? desc)? createApp, TResult Function(String name, String? desc)? createApp,
TResult Function(int fromIndex, int toIndex)? moveApp,
TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps, TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps,
required TResult orElse(), required TResult orElse(),
}) { }) {
@ -203,10 +219,11 @@ class _$_Initial implements _Initial {
@optionalTypeArgs @optionalTypeArgs
TResult map<TResult extends Object?>({ TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(Collapse value) collapse, required TResult Function(_Collapse value) collapse,
required TResult Function(OpenPage value) openPage, required TResult Function(_OpenPage value) openPage,
required TResult Function(CreateApp value) createApp, required TResult Function(_CreateApp value) createApp,
required TResult Function(ReceiveApps value) didReceiveApps, required TResult Function(_MoveApp value) moveApp,
required TResult Function(_ReceiveApps value) didReceiveApps,
}) { }) {
return initial(this); return initial(this);
} }
@ -215,10 +232,11 @@ class _$_Initial implements _Initial {
@optionalTypeArgs @optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({ TResult? mapOrNull<TResult extends Object?>({
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(Collapse value)? collapse, TResult Function(_Collapse value)? collapse,
TResult Function(OpenPage value)? openPage, TResult Function(_OpenPage value)? openPage,
TResult Function(CreateApp value)? createApp, TResult Function(_CreateApp value)? createApp,
TResult Function(ReceiveApps value)? didReceiveApps, TResult Function(_MoveApp value)? moveApp,
TResult Function(_ReceiveApps value)? didReceiveApps,
}) { }) {
return initial?.call(this); return initial?.call(this);
} }
@ -227,10 +245,11 @@ class _$_Initial implements _Initial {
@optionalTypeArgs @optionalTypeArgs
TResult maybeMap<TResult extends Object?>({ TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(Collapse value)? collapse, TResult Function(_Collapse value)? collapse,
TResult Function(OpenPage value)? openPage, TResult Function(_OpenPage value)? openPage,
TResult Function(CreateApp value)? createApp, TResult Function(_CreateApp value)? createApp,
TResult Function(ReceiveApps value)? didReceiveApps, TResult Function(_MoveApp value)? moveApp,
TResult Function(_ReceiveApps value)? didReceiveApps,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (initial != null) { if (initial != null) {
@ -245,25 +264,25 @@ abstract class _Initial implements MenuEvent {
} }
/// @nodoc /// @nodoc
abstract class $CollapseCopyWith<$Res> { abstract class _$CollapseCopyWith<$Res> {
factory $CollapseCopyWith(Collapse value, $Res Function(Collapse) then) = factory _$CollapseCopyWith(_Collapse value, $Res Function(_Collapse) then) =
_$CollapseCopyWithImpl<$Res>; __$CollapseCopyWithImpl<$Res>;
} }
/// @nodoc /// @nodoc
class _$CollapseCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res> class __$CollapseCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res>
implements $CollapseCopyWith<$Res> { implements _$CollapseCopyWith<$Res> {
_$CollapseCopyWithImpl(Collapse _value, $Res Function(Collapse) _then) __$CollapseCopyWithImpl(_Collapse _value, $Res Function(_Collapse) _then)
: super(_value, (v) => _then(v as Collapse)); : super(_value, (v) => _then(v as _Collapse));
@override @override
Collapse get _value => super._value as Collapse; _Collapse get _value => super._value as _Collapse;
} }
/// @nodoc /// @nodoc
class _$Collapse implements Collapse { class _$_Collapse implements _Collapse {
const _$Collapse(); const _$_Collapse();
@override @override
String toString() { String toString() {
@ -272,7 +291,7 @@ class _$Collapse implements Collapse {
@override @override
bool operator ==(dynamic other) { bool operator ==(dynamic other) {
return identical(this, other) || (other is Collapse); return identical(this, other) || (other is _Collapse);
} }
@override @override
@ -285,6 +304,7 @@ class _$Collapse implements Collapse {
required TResult Function() collapse, required TResult Function() collapse,
required TResult Function(Plugin plugin) openPage, required TResult Function(Plugin plugin) openPage,
required TResult Function(String name, String? desc) createApp, required TResult Function(String name, String? desc) createApp,
required TResult Function(int fromIndex, int toIndex) moveApp,
required TResult Function(Either<List<App>, FlowyError> appsOrFail) required TResult Function(Either<List<App>, FlowyError> appsOrFail)
didReceiveApps, didReceiveApps,
}) { }) {
@ -298,6 +318,7 @@ class _$Collapse implements Collapse {
TResult Function()? collapse, TResult Function()? collapse,
TResult Function(Plugin plugin)? openPage, TResult Function(Plugin plugin)? openPage,
TResult Function(String name, String? desc)? createApp, TResult Function(String name, String? desc)? createApp,
TResult Function(int fromIndex, int toIndex)? moveApp,
TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps, TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps,
}) { }) {
return collapse?.call(); return collapse?.call();
@ -310,6 +331,7 @@ class _$Collapse implements Collapse {
TResult Function()? collapse, TResult Function()? collapse,
TResult Function(Plugin plugin)? openPage, TResult Function(Plugin plugin)? openPage,
TResult Function(String name, String? desc)? createApp, TResult Function(String name, String? desc)? createApp,
TResult Function(int fromIndex, int toIndex)? moveApp,
TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps, TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps,
required TResult orElse(), required TResult orElse(),
}) { }) {
@ -323,10 +345,11 @@ class _$Collapse implements Collapse {
@optionalTypeArgs @optionalTypeArgs
TResult map<TResult extends Object?>({ TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(Collapse value) collapse, required TResult Function(_Collapse value) collapse,
required TResult Function(OpenPage value) openPage, required TResult Function(_OpenPage value) openPage,
required TResult Function(CreateApp value) createApp, required TResult Function(_CreateApp value) createApp,
required TResult Function(ReceiveApps value) didReceiveApps, required TResult Function(_MoveApp value) moveApp,
required TResult Function(_ReceiveApps value) didReceiveApps,
}) { }) {
return collapse(this); return collapse(this);
} }
@ -335,10 +358,11 @@ class _$Collapse implements Collapse {
@optionalTypeArgs @optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({ TResult? mapOrNull<TResult extends Object?>({
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(Collapse value)? collapse, TResult Function(_Collapse value)? collapse,
TResult Function(OpenPage value)? openPage, TResult Function(_OpenPage value)? openPage,
TResult Function(CreateApp value)? createApp, TResult Function(_CreateApp value)? createApp,
TResult Function(ReceiveApps value)? didReceiveApps, TResult Function(_MoveApp value)? moveApp,
TResult Function(_ReceiveApps value)? didReceiveApps,
}) { }) {
return collapse?.call(this); return collapse?.call(this);
} }
@ -347,10 +371,11 @@ class _$Collapse implements Collapse {
@optionalTypeArgs @optionalTypeArgs
TResult maybeMap<TResult extends Object?>({ TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(Collapse value)? collapse, TResult Function(_Collapse value)? collapse,
TResult Function(OpenPage value)? openPage, TResult Function(_OpenPage value)? openPage,
TResult Function(CreateApp value)? createApp, TResult Function(_CreateApp value)? createApp,
TResult Function(ReceiveApps value)? didReceiveApps, TResult Function(_MoveApp value)? moveApp,
TResult Function(_ReceiveApps value)? didReceiveApps,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (collapse != null) { if (collapse != null) {
@ -360,31 +385,31 @@ class _$Collapse implements Collapse {
} }
} }
abstract class Collapse implements MenuEvent { abstract class _Collapse implements MenuEvent {
const factory Collapse() = _$Collapse; const factory _Collapse() = _$_Collapse;
} }
/// @nodoc /// @nodoc
abstract class $OpenPageCopyWith<$Res> { abstract class _$OpenPageCopyWith<$Res> {
factory $OpenPageCopyWith(OpenPage value, $Res Function(OpenPage) then) = factory _$OpenPageCopyWith(_OpenPage value, $Res Function(_OpenPage) then) =
_$OpenPageCopyWithImpl<$Res>; __$OpenPageCopyWithImpl<$Res>;
$Res call({Plugin plugin}); $Res call({Plugin plugin});
} }
/// @nodoc /// @nodoc
class _$OpenPageCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res> class __$OpenPageCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res>
implements $OpenPageCopyWith<$Res> { implements _$OpenPageCopyWith<$Res> {
_$OpenPageCopyWithImpl(OpenPage _value, $Res Function(OpenPage) _then) __$OpenPageCopyWithImpl(_OpenPage _value, $Res Function(_OpenPage) _then)
: super(_value, (v) => _then(v as OpenPage)); : super(_value, (v) => _then(v as _OpenPage));
@override @override
OpenPage get _value => super._value as OpenPage; _OpenPage get _value => super._value as _OpenPage;
@override @override
$Res call({ $Res call({
Object? plugin = freezed, Object? plugin = freezed,
}) { }) {
return _then(OpenPage( return _then(_OpenPage(
plugin == freezed plugin == freezed
? _value.plugin ? _value.plugin
: plugin // ignore: cast_nullable_to_non_nullable : plugin // ignore: cast_nullable_to_non_nullable
@ -395,8 +420,8 @@ class _$OpenPageCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res>
/// @nodoc /// @nodoc
class _$OpenPage implements OpenPage { class _$_OpenPage implements _OpenPage {
const _$OpenPage(this.plugin); const _$_OpenPage(this.plugin);
@override @override
final Plugin plugin; final Plugin plugin;
@ -409,7 +434,7 @@ class _$OpenPage implements OpenPage {
@override @override
bool operator ==(dynamic other) { bool operator ==(dynamic other) {
return identical(this, other) || return identical(this, other) ||
(other is OpenPage && (other is _OpenPage &&
(identical(other.plugin, plugin) || (identical(other.plugin, plugin) ||
const DeepCollectionEquality().equals(other.plugin, plugin))); const DeepCollectionEquality().equals(other.plugin, plugin)));
} }
@ -420,8 +445,8 @@ class _$OpenPage implements OpenPage {
@JsonKey(ignore: true) @JsonKey(ignore: true)
@override @override
$OpenPageCopyWith<OpenPage> get copyWith => _$OpenPageCopyWith<_OpenPage> get copyWith =>
_$OpenPageCopyWithImpl<OpenPage>(this, _$identity); __$OpenPageCopyWithImpl<_OpenPage>(this, _$identity);
@override @override
@optionalTypeArgs @optionalTypeArgs
@ -430,6 +455,7 @@ class _$OpenPage implements OpenPage {
required TResult Function() collapse, required TResult Function() collapse,
required TResult Function(Plugin plugin) openPage, required TResult Function(Plugin plugin) openPage,
required TResult Function(String name, String? desc) createApp, required TResult Function(String name, String? desc) createApp,
required TResult Function(int fromIndex, int toIndex) moveApp,
required TResult Function(Either<List<App>, FlowyError> appsOrFail) required TResult Function(Either<List<App>, FlowyError> appsOrFail)
didReceiveApps, didReceiveApps,
}) { }) {
@ -443,6 +469,7 @@ class _$OpenPage implements OpenPage {
TResult Function()? collapse, TResult Function()? collapse,
TResult Function(Plugin plugin)? openPage, TResult Function(Plugin plugin)? openPage,
TResult Function(String name, String? desc)? createApp, TResult Function(String name, String? desc)? createApp,
TResult Function(int fromIndex, int toIndex)? moveApp,
TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps, TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps,
}) { }) {
return openPage?.call(plugin); return openPage?.call(plugin);
@ -455,6 +482,7 @@ class _$OpenPage implements OpenPage {
TResult Function()? collapse, TResult Function()? collapse,
TResult Function(Plugin plugin)? openPage, TResult Function(Plugin plugin)? openPage,
TResult Function(String name, String? desc)? createApp, TResult Function(String name, String? desc)? createApp,
TResult Function(int fromIndex, int toIndex)? moveApp,
TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps, TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps,
required TResult orElse(), required TResult orElse(),
}) { }) {
@ -468,10 +496,11 @@ class _$OpenPage implements OpenPage {
@optionalTypeArgs @optionalTypeArgs
TResult map<TResult extends Object?>({ TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(Collapse value) collapse, required TResult Function(_Collapse value) collapse,
required TResult Function(OpenPage value) openPage, required TResult Function(_OpenPage value) openPage,
required TResult Function(CreateApp value) createApp, required TResult Function(_CreateApp value) createApp,
required TResult Function(ReceiveApps value) didReceiveApps, required TResult Function(_MoveApp value) moveApp,
required TResult Function(_ReceiveApps value) didReceiveApps,
}) { }) {
return openPage(this); return openPage(this);
} }
@ -480,10 +509,11 @@ class _$OpenPage implements OpenPage {
@optionalTypeArgs @optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({ TResult? mapOrNull<TResult extends Object?>({
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(Collapse value)? collapse, TResult Function(_Collapse value)? collapse,
TResult Function(OpenPage value)? openPage, TResult Function(_OpenPage value)? openPage,
TResult Function(CreateApp value)? createApp, TResult Function(_CreateApp value)? createApp,
TResult Function(ReceiveApps value)? didReceiveApps, TResult Function(_MoveApp value)? moveApp,
TResult Function(_ReceiveApps value)? didReceiveApps,
}) { }) {
return openPage?.call(this); return openPage?.call(this);
} }
@ -492,10 +522,11 @@ class _$OpenPage implements OpenPage {
@optionalTypeArgs @optionalTypeArgs
TResult maybeMap<TResult extends Object?>({ TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(Collapse value)? collapse, TResult Function(_Collapse value)? collapse,
TResult Function(OpenPage value)? openPage, TResult Function(_OpenPage value)? openPage,
TResult Function(CreateApp value)? createApp, TResult Function(_CreateApp value)? createApp,
TResult Function(ReceiveApps value)? didReceiveApps, TResult Function(_MoveApp value)? moveApp,
TResult Function(_ReceiveApps value)? didReceiveApps,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (openPage != null) { if (openPage != null) {
@ -505,37 +536,38 @@ class _$OpenPage implements OpenPage {
} }
} }
abstract class OpenPage implements MenuEvent { abstract class _OpenPage implements MenuEvent {
const factory OpenPage(Plugin plugin) = _$OpenPage; const factory _OpenPage(Plugin plugin) = _$_OpenPage;
Plugin get plugin => throw _privateConstructorUsedError; Plugin get plugin => throw _privateConstructorUsedError;
@JsonKey(ignore: true) @JsonKey(ignore: true)
$OpenPageCopyWith<OpenPage> get copyWith => _$OpenPageCopyWith<_OpenPage> get copyWith =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
} }
/// @nodoc /// @nodoc
abstract class $CreateAppCopyWith<$Res> { abstract class _$CreateAppCopyWith<$Res> {
factory $CreateAppCopyWith(CreateApp value, $Res Function(CreateApp) then) = factory _$CreateAppCopyWith(
_$CreateAppCopyWithImpl<$Res>; _CreateApp value, $Res Function(_CreateApp) then) =
__$CreateAppCopyWithImpl<$Res>;
$Res call({String name, String? desc}); $Res call({String name, String? desc});
} }
/// @nodoc /// @nodoc
class _$CreateAppCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res> class __$CreateAppCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res>
implements $CreateAppCopyWith<$Res> { implements _$CreateAppCopyWith<$Res> {
_$CreateAppCopyWithImpl(CreateApp _value, $Res Function(CreateApp) _then) __$CreateAppCopyWithImpl(_CreateApp _value, $Res Function(_CreateApp) _then)
: super(_value, (v) => _then(v as CreateApp)); : super(_value, (v) => _then(v as _CreateApp));
@override @override
CreateApp get _value => super._value as CreateApp; _CreateApp get _value => super._value as _CreateApp;
@override @override
$Res call({ $Res call({
Object? name = freezed, Object? name = freezed,
Object? desc = freezed, Object? desc = freezed,
}) { }) {
return _then(CreateApp( return _then(_CreateApp(
name == freezed name == freezed
? _value.name ? _value.name
: name // ignore: cast_nullable_to_non_nullable : name // ignore: cast_nullable_to_non_nullable
@ -550,8 +582,8 @@ class _$CreateAppCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res>
/// @nodoc /// @nodoc
class _$CreateApp implements CreateApp { class _$_CreateApp implements _CreateApp {
const _$CreateApp(this.name, {this.desc}); const _$_CreateApp(this.name, {this.desc});
@override @override
final String name; final String name;
@ -566,7 +598,7 @@ class _$CreateApp implements CreateApp {
@override @override
bool operator ==(dynamic other) { bool operator ==(dynamic other) {
return identical(this, other) || return identical(this, other) ||
(other is CreateApp && (other is _CreateApp &&
(identical(other.name, name) || (identical(other.name, name) ||
const DeepCollectionEquality().equals(other.name, name)) && const DeepCollectionEquality().equals(other.name, name)) &&
(identical(other.desc, desc) || (identical(other.desc, desc) ||
@ -581,8 +613,8 @@ class _$CreateApp implements CreateApp {
@JsonKey(ignore: true) @JsonKey(ignore: true)
@override @override
$CreateAppCopyWith<CreateApp> get copyWith => _$CreateAppCopyWith<_CreateApp> get copyWith =>
_$CreateAppCopyWithImpl<CreateApp>(this, _$identity); __$CreateAppCopyWithImpl<_CreateApp>(this, _$identity);
@override @override
@optionalTypeArgs @optionalTypeArgs
@ -591,6 +623,7 @@ class _$CreateApp implements CreateApp {
required TResult Function() collapse, required TResult Function() collapse,
required TResult Function(Plugin plugin) openPage, required TResult Function(Plugin plugin) openPage,
required TResult Function(String name, String? desc) createApp, required TResult Function(String name, String? desc) createApp,
required TResult Function(int fromIndex, int toIndex) moveApp,
required TResult Function(Either<List<App>, FlowyError> appsOrFail) required TResult Function(Either<List<App>, FlowyError> appsOrFail)
didReceiveApps, didReceiveApps,
}) { }) {
@ -604,6 +637,7 @@ class _$CreateApp implements CreateApp {
TResult Function()? collapse, TResult Function()? collapse,
TResult Function(Plugin plugin)? openPage, TResult Function(Plugin plugin)? openPage,
TResult Function(String name, String? desc)? createApp, TResult Function(String name, String? desc)? createApp,
TResult Function(int fromIndex, int toIndex)? moveApp,
TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps, TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps,
}) { }) {
return createApp?.call(name, desc); return createApp?.call(name, desc);
@ -616,6 +650,7 @@ class _$CreateApp implements CreateApp {
TResult Function()? collapse, TResult Function()? collapse,
TResult Function(Plugin plugin)? openPage, TResult Function(Plugin plugin)? openPage,
TResult Function(String name, String? desc)? createApp, TResult Function(String name, String? desc)? createApp,
TResult Function(int fromIndex, int toIndex)? moveApp,
TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps, TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps,
required TResult orElse(), required TResult orElse(),
}) { }) {
@ -629,10 +664,11 @@ class _$CreateApp implements CreateApp {
@optionalTypeArgs @optionalTypeArgs
TResult map<TResult extends Object?>({ TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(Collapse value) collapse, required TResult Function(_Collapse value) collapse,
required TResult Function(OpenPage value) openPage, required TResult Function(_OpenPage value) openPage,
required TResult Function(CreateApp value) createApp, required TResult Function(_CreateApp value) createApp,
required TResult Function(ReceiveApps value) didReceiveApps, required TResult Function(_MoveApp value) moveApp,
required TResult Function(_ReceiveApps value) didReceiveApps,
}) { }) {
return createApp(this); return createApp(this);
} }
@ -641,10 +677,11 @@ class _$CreateApp implements CreateApp {
@optionalTypeArgs @optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({ TResult? mapOrNull<TResult extends Object?>({
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(Collapse value)? collapse, TResult Function(_Collapse value)? collapse,
TResult Function(OpenPage value)? openPage, TResult Function(_OpenPage value)? openPage,
TResult Function(CreateApp value)? createApp, TResult Function(_CreateApp value)? createApp,
TResult Function(ReceiveApps value)? didReceiveApps, TResult Function(_MoveApp value)? moveApp,
TResult Function(_ReceiveApps value)? didReceiveApps,
}) { }) {
return createApp?.call(this); return createApp?.call(this);
} }
@ -653,10 +690,11 @@ class _$CreateApp implements CreateApp {
@optionalTypeArgs @optionalTypeArgs
TResult maybeMap<TResult extends Object?>({ TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(Collapse value)? collapse, TResult Function(_Collapse value)? collapse,
TResult Function(OpenPage value)? openPage, TResult Function(_OpenPage value)? openPage,
TResult Function(CreateApp value)? createApp, TResult Function(_CreateApp value)? createApp,
TResult Function(ReceiveApps value)? didReceiveApps, TResult Function(_MoveApp value)? moveApp,
TResult Function(_ReceiveApps value)? didReceiveApps,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (createApp != null) { if (createApp != null) {
@ -666,39 +704,208 @@ class _$CreateApp implements CreateApp {
} }
} }
abstract class CreateApp implements MenuEvent { abstract class _CreateApp implements MenuEvent {
const factory CreateApp(String name, {String? desc}) = _$CreateApp; const factory _CreateApp(String name, {String? desc}) = _$_CreateApp;
String get name => throw _privateConstructorUsedError; String get name => throw _privateConstructorUsedError;
String? get desc => throw _privateConstructorUsedError; String? get desc => throw _privateConstructorUsedError;
@JsonKey(ignore: true) @JsonKey(ignore: true)
$CreateAppCopyWith<CreateApp> get copyWith => _$CreateAppCopyWith<_CreateApp> get copyWith =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
} }
/// @nodoc /// @nodoc
abstract class $ReceiveAppsCopyWith<$Res> { abstract class _$MoveAppCopyWith<$Res> {
factory $ReceiveAppsCopyWith( factory _$MoveAppCopyWith(_MoveApp value, $Res Function(_MoveApp) then) =
ReceiveApps value, $Res Function(ReceiveApps) then) = __$MoveAppCopyWithImpl<$Res>;
_$ReceiveAppsCopyWithImpl<$Res>; $Res call({int fromIndex, int toIndex});
}
/// @nodoc
class __$MoveAppCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res>
implements _$MoveAppCopyWith<$Res> {
__$MoveAppCopyWithImpl(_MoveApp _value, $Res Function(_MoveApp) _then)
: super(_value, (v) => _then(v as _MoveApp));
@override
_MoveApp get _value => super._value as _MoveApp;
@override
$Res call({
Object? fromIndex = freezed,
Object? toIndex = freezed,
}) {
return _then(_MoveApp(
fromIndex == freezed
? _value.fromIndex
: fromIndex // ignore: cast_nullable_to_non_nullable
as int,
toIndex == freezed
? _value.toIndex
: toIndex // ignore: cast_nullable_to_non_nullable
as int,
));
}
}
/// @nodoc
class _$_MoveApp implements _MoveApp {
const _$_MoveApp(this.fromIndex, this.toIndex);
@override
final int fromIndex;
@override
final int toIndex;
@override
String toString() {
return 'MenuEvent.moveApp(fromIndex: $fromIndex, toIndex: $toIndex)';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other is _MoveApp &&
(identical(other.fromIndex, fromIndex) ||
const DeepCollectionEquality()
.equals(other.fromIndex, fromIndex)) &&
(identical(other.toIndex, toIndex) ||
const DeepCollectionEquality().equals(other.toIndex, toIndex)));
}
@override
int get hashCode =>
runtimeType.hashCode ^
const DeepCollectionEquality().hash(fromIndex) ^
const DeepCollectionEquality().hash(toIndex);
@JsonKey(ignore: true)
@override
_$MoveAppCopyWith<_MoveApp> get copyWith =>
__$MoveAppCopyWithImpl<_MoveApp>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() collapse,
required TResult Function(Plugin plugin) openPage,
required TResult Function(String name, String? desc) createApp,
required TResult Function(int fromIndex, int toIndex) moveApp,
required TResult Function(Either<List<App>, FlowyError> appsOrFail)
didReceiveApps,
}) {
return moveApp(fromIndex, toIndex);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? collapse,
TResult Function(Plugin plugin)? openPage,
TResult Function(String name, String? desc)? createApp,
TResult Function(int fromIndex, int toIndex)? moveApp,
TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps,
}) {
return moveApp?.call(fromIndex, toIndex);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? collapse,
TResult Function(Plugin plugin)? openPage,
TResult Function(String name, String? desc)? createApp,
TResult Function(int fromIndex, int toIndex)? moveApp,
TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps,
required TResult orElse(),
}) {
if (moveApp != null) {
return moveApp(fromIndex, toIndex);
}
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(_MoveApp value) moveApp,
required TResult Function(_ReceiveApps value) didReceiveApps,
}) {
return moveApp(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<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(_MoveApp value)? moveApp,
TResult Function(_ReceiveApps value)? didReceiveApps,
}) {
return moveApp?.call(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(_MoveApp value)? moveApp,
TResult Function(_ReceiveApps value)? didReceiveApps,
required TResult orElse(),
}) {
if (moveApp != null) {
return moveApp(this);
}
return orElse();
}
}
abstract class _MoveApp implements MenuEvent {
const factory _MoveApp(int fromIndex, int toIndex) = _$_MoveApp;
int get fromIndex => throw _privateConstructorUsedError;
int get toIndex => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
_$MoveAppCopyWith<_MoveApp> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class _$ReceiveAppsCopyWith<$Res> {
factory _$ReceiveAppsCopyWith(
_ReceiveApps value, $Res Function(_ReceiveApps) then) =
__$ReceiveAppsCopyWithImpl<$Res>;
$Res call({Either<List<App>, FlowyError> appsOrFail}); $Res call({Either<List<App>, FlowyError> appsOrFail});
} }
/// @nodoc /// @nodoc
class _$ReceiveAppsCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res> class __$ReceiveAppsCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res>
implements $ReceiveAppsCopyWith<$Res> { implements _$ReceiveAppsCopyWith<$Res> {
_$ReceiveAppsCopyWithImpl( __$ReceiveAppsCopyWithImpl(
ReceiveApps _value, $Res Function(ReceiveApps) _then) _ReceiveApps _value, $Res Function(_ReceiveApps) _then)
: super(_value, (v) => _then(v as ReceiveApps)); : super(_value, (v) => _then(v as _ReceiveApps));
@override @override
ReceiveApps get _value => super._value as ReceiveApps; _ReceiveApps get _value => super._value as _ReceiveApps;
@override @override
$Res call({ $Res call({
Object? appsOrFail = freezed, Object? appsOrFail = freezed,
}) { }) {
return _then(ReceiveApps( return _then(_ReceiveApps(
appsOrFail == freezed appsOrFail == freezed
? _value.appsOrFail ? _value.appsOrFail
: appsOrFail // ignore: cast_nullable_to_non_nullable : appsOrFail // ignore: cast_nullable_to_non_nullable
@ -709,8 +916,8 @@ class _$ReceiveAppsCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res>
/// @nodoc /// @nodoc
class _$ReceiveApps implements ReceiveApps { class _$_ReceiveApps implements _ReceiveApps {
const _$ReceiveApps(this.appsOrFail); const _$_ReceiveApps(this.appsOrFail);
@override @override
final Either<List<App>, FlowyError> appsOrFail; final Either<List<App>, FlowyError> appsOrFail;
@ -723,7 +930,7 @@ class _$ReceiveApps implements ReceiveApps {
@override @override
bool operator ==(dynamic other) { bool operator ==(dynamic other) {
return identical(this, other) || return identical(this, other) ||
(other is ReceiveApps && (other is _ReceiveApps &&
(identical(other.appsOrFail, appsOrFail) || (identical(other.appsOrFail, appsOrFail) ||
const DeepCollectionEquality() const DeepCollectionEquality()
.equals(other.appsOrFail, appsOrFail))); .equals(other.appsOrFail, appsOrFail)));
@ -735,8 +942,8 @@ class _$ReceiveApps implements ReceiveApps {
@JsonKey(ignore: true) @JsonKey(ignore: true)
@override @override
$ReceiveAppsCopyWith<ReceiveApps> get copyWith => _$ReceiveAppsCopyWith<_ReceiveApps> get copyWith =>
_$ReceiveAppsCopyWithImpl<ReceiveApps>(this, _$identity); __$ReceiveAppsCopyWithImpl<_ReceiveApps>(this, _$identity);
@override @override
@optionalTypeArgs @optionalTypeArgs
@ -745,6 +952,7 @@ class _$ReceiveApps implements ReceiveApps {
required TResult Function() collapse, required TResult Function() collapse,
required TResult Function(Plugin plugin) openPage, required TResult Function(Plugin plugin) openPage,
required TResult Function(String name, String? desc) createApp, required TResult Function(String name, String? desc) createApp,
required TResult Function(int fromIndex, int toIndex) moveApp,
required TResult Function(Either<List<App>, FlowyError> appsOrFail) required TResult Function(Either<List<App>, FlowyError> appsOrFail)
didReceiveApps, didReceiveApps,
}) { }) {
@ -758,6 +966,7 @@ class _$ReceiveApps implements ReceiveApps {
TResult Function()? collapse, TResult Function()? collapse,
TResult Function(Plugin plugin)? openPage, TResult Function(Plugin plugin)? openPage,
TResult Function(String name, String? desc)? createApp, TResult Function(String name, String? desc)? createApp,
TResult Function(int fromIndex, int toIndex)? moveApp,
TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps, TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps,
}) { }) {
return didReceiveApps?.call(appsOrFail); return didReceiveApps?.call(appsOrFail);
@ -770,6 +979,7 @@ class _$ReceiveApps implements ReceiveApps {
TResult Function()? collapse, TResult Function()? collapse,
TResult Function(Plugin plugin)? openPage, TResult Function(Plugin plugin)? openPage,
TResult Function(String name, String? desc)? createApp, TResult Function(String name, String? desc)? createApp,
TResult Function(int fromIndex, int toIndex)? moveApp,
TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps, TResult Function(Either<List<App>, FlowyError> appsOrFail)? didReceiveApps,
required TResult orElse(), required TResult orElse(),
}) { }) {
@ -783,10 +993,11 @@ class _$ReceiveApps implements ReceiveApps {
@optionalTypeArgs @optionalTypeArgs
TResult map<TResult extends Object?>({ TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(Collapse value) collapse, required TResult Function(_Collapse value) collapse,
required TResult Function(OpenPage value) openPage, required TResult Function(_OpenPage value) openPage,
required TResult Function(CreateApp value) createApp, required TResult Function(_CreateApp value) createApp,
required TResult Function(ReceiveApps value) didReceiveApps, required TResult Function(_MoveApp value) moveApp,
required TResult Function(_ReceiveApps value) didReceiveApps,
}) { }) {
return didReceiveApps(this); return didReceiveApps(this);
} }
@ -795,10 +1006,11 @@ class _$ReceiveApps implements ReceiveApps {
@optionalTypeArgs @optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({ TResult? mapOrNull<TResult extends Object?>({
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(Collapse value)? collapse, TResult Function(_Collapse value)? collapse,
TResult Function(OpenPage value)? openPage, TResult Function(_OpenPage value)? openPage,
TResult Function(CreateApp value)? createApp, TResult Function(_CreateApp value)? createApp,
TResult Function(ReceiveApps value)? didReceiveApps, TResult Function(_MoveApp value)? moveApp,
TResult Function(_ReceiveApps value)? didReceiveApps,
}) { }) {
return didReceiveApps?.call(this); return didReceiveApps?.call(this);
} }
@ -807,10 +1019,11 @@ class _$ReceiveApps implements ReceiveApps {
@optionalTypeArgs @optionalTypeArgs
TResult maybeMap<TResult extends Object?>({ TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(Collapse value)? collapse, TResult Function(_Collapse value)? collapse,
TResult Function(OpenPage value)? openPage, TResult Function(_OpenPage value)? openPage,
TResult Function(CreateApp value)? createApp, TResult Function(_CreateApp value)? createApp,
TResult Function(ReceiveApps value)? didReceiveApps, TResult Function(_MoveApp value)? moveApp,
TResult Function(_ReceiveApps value)? didReceiveApps,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (didReceiveApps != null) { if (didReceiveApps != null) {
@ -820,14 +1033,14 @@ class _$ReceiveApps implements ReceiveApps {
} }
} }
abstract class ReceiveApps implements MenuEvent { abstract class _ReceiveApps implements MenuEvent {
const factory ReceiveApps(Either<List<App>, FlowyError> appsOrFail) = const factory _ReceiveApps(Either<List<App>, FlowyError> appsOrFail) =
_$ReceiveApps; _$_ReceiveApps;
Either<List<App>, FlowyError> get appsOrFail => Either<List<App>, FlowyError> get appsOrFail =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@JsonKey(ignore: true) @JsonKey(ignore: true)
$ReceiveAppsCopyWith<ReceiveApps> get copyWith => _$ReceiveAppsCopyWith<_ReceiveApps> get copyWith =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
} }
@ -837,7 +1050,7 @@ class _$MenuStateTearOff {
_MenuState call( _MenuState call(
{required bool isCollapse, {required bool isCollapse,
required Option<List<App>> apps, required List<App> apps,
required Either<Unit, FlowyError> successOrFailure, required Either<Unit, FlowyError> successOrFailure,
required Plugin plugin}) { required Plugin plugin}) {
return _MenuState( return _MenuState(
@ -855,7 +1068,7 @@ const $MenuState = _$MenuStateTearOff();
/// @nodoc /// @nodoc
mixin _$MenuState { mixin _$MenuState {
bool get isCollapse => throw _privateConstructorUsedError; bool get isCollapse => throw _privateConstructorUsedError;
Option<List<App>> get apps => throw _privateConstructorUsedError; List<App> get apps => throw _privateConstructorUsedError;
Either<Unit, FlowyError> get successOrFailure => Either<Unit, FlowyError> get successOrFailure =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
Plugin get plugin => throw _privateConstructorUsedError; Plugin get plugin => throw _privateConstructorUsedError;
@ -871,7 +1084,7 @@ abstract class $MenuStateCopyWith<$Res> {
_$MenuStateCopyWithImpl<$Res>; _$MenuStateCopyWithImpl<$Res>;
$Res call( $Res call(
{bool isCollapse, {bool isCollapse,
Option<List<App>> apps, List<App> apps,
Either<Unit, FlowyError> successOrFailure, Either<Unit, FlowyError> successOrFailure,
Plugin plugin}); Plugin plugin});
} }
@ -899,7 +1112,7 @@ class _$MenuStateCopyWithImpl<$Res> implements $MenuStateCopyWith<$Res> {
apps: apps == freezed apps: apps == freezed
? _value.apps ? _value.apps
: apps // ignore: cast_nullable_to_non_nullable : apps // ignore: cast_nullable_to_non_nullable
as Option<List<App>>, as List<App>,
successOrFailure: successOrFailure == freezed successOrFailure: successOrFailure == freezed
? _value.successOrFailure ? _value.successOrFailure
: successOrFailure // ignore: cast_nullable_to_non_nullable : successOrFailure // ignore: cast_nullable_to_non_nullable
@ -920,7 +1133,7 @@ abstract class _$MenuStateCopyWith<$Res> implements $MenuStateCopyWith<$Res> {
@override @override
$Res call( $Res call(
{bool isCollapse, {bool isCollapse,
Option<List<App>> apps, List<App> apps,
Either<Unit, FlowyError> successOrFailure, Either<Unit, FlowyError> successOrFailure,
Plugin plugin}); Plugin plugin});
} }
@ -949,7 +1162,7 @@ class __$MenuStateCopyWithImpl<$Res> extends _$MenuStateCopyWithImpl<$Res>
apps: apps == freezed apps: apps == freezed
? _value.apps ? _value.apps
: apps // ignore: cast_nullable_to_non_nullable : apps // ignore: cast_nullable_to_non_nullable
as Option<List<App>>, as List<App>,
successOrFailure: successOrFailure == freezed successOrFailure: successOrFailure == freezed
? _value.successOrFailure ? _value.successOrFailure
: successOrFailure // ignore: cast_nullable_to_non_nullable : successOrFailure // ignore: cast_nullable_to_non_nullable
@ -974,7 +1187,7 @@ class _$_MenuState implements _MenuState {
@override @override
final bool isCollapse; final bool isCollapse;
@override @override
final Option<List<App>> apps; final List<App> apps;
@override @override
final Either<Unit, FlowyError> successOrFailure; final Either<Unit, FlowyError> successOrFailure;
@override @override
@ -1018,14 +1231,14 @@ class _$_MenuState implements _MenuState {
abstract class _MenuState implements MenuState { abstract class _MenuState implements MenuState {
const factory _MenuState( const factory _MenuState(
{required bool isCollapse, {required bool isCollapse,
required Option<List<App>> apps, required List<App> apps,
required Either<Unit, FlowyError> successOrFailure, required Either<Unit, FlowyError> successOrFailure,
required Plugin plugin}) = _$_MenuState; required Plugin plugin}) = _$_MenuState;
@override @override
bool get isCollapse => throw _privateConstructorUsedError; bool get isCollapse => throw _privateConstructorUsedError;
@override @override
Option<List<App>> get apps => throw _privateConstructorUsedError; List<App> get apps => throw _privateConstructorUsedError;
@override @override
Either<Unit, FlowyError> get successOrFailure => Either<Unit, FlowyError> get successOrFailure =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;

View File

@ -1,15 +1,21 @@
import 'dart:async'; import 'dart:async';
import 'package:dartz/dartz.dart'; import 'package:dartz/dartz.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_sdk/dispatch/dispatch.dart'; import 'package:flowy_sdk/dispatch/dispatch.dart';
import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart' show MoveFolderItemPayload, MoveItemType;
import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart' show MoveFolderItemPayload, MoveFolderItemType;
import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart';
import 'package:app_flowy/generated/locale_keys.g.dart'; import 'package:app_flowy/generated/locale_keys.g.dart';
class WorkspaceService { class WorkspaceService {
Future<Either<App, FlowyError>> createApp({required String workspaceId, required String name, required String desc}) { final String workspaceId;
WorkspaceService({
required this.workspaceId,
});
Future<Either<App, FlowyError>> createApp({required String name, required String desc}) {
final payload = CreateAppPayload.create() final payload = CreateAppPayload.create()
..name = name ..name = name
..workspaceId = workspaceId ..workspaceId = workspaceId
@ -17,7 +23,7 @@ class WorkspaceService {
return FolderEventCreateApp(payload).send(); return FolderEventCreateApp(payload).send();
} }
Future<Either<Workspace, FlowyError>> getWorkspace({required String workspaceId}) { Future<Either<Workspace, FlowyError>> getWorkspace() {
final payload = WorkspaceId.create()..value = workspaceId; final payload = WorkspaceId.create()..value = workspaceId;
return FolderEventReadWorkspaces(payload).send().then((result) { return FolderEventReadWorkspaces(payload).send().then((result) {
return result.fold( return result.fold(
@ -35,7 +41,7 @@ class WorkspaceService {
}); });
} }
Future<Either<List<App>, FlowyError>> getApps({required String workspaceId}) { Future<Either<List<App>, FlowyError>> getApps() {
final payload = WorkspaceId.create()..value = workspaceId; final payload = WorkspaceId.create()..value = workspaceId;
return FolderEventReadWorkspaceApps(payload).send().then((result) { return FolderEventReadWorkspaceApps(payload).send().then((result) {
return result.fold( return result.fold(
@ -54,7 +60,7 @@ class WorkspaceService {
..itemId = appId ..itemId = appId
..from = fromIndex ..from = fromIndex
..to = toIndex ..to = toIndex
..ty = MoveItemType.MoveApp; ..ty = MoveFolderItemType.MoveApp;
return FolderEventMoveItem(payload).send(); return FolderEventMoveItem(payload).send();
} }

View File

@ -26,7 +26,7 @@ import 'app/menu_app.dart';
import 'app/create_button.dart'; import 'app/create_button.dart';
import 'menu_user.dart'; import 'menu_user.dart';
class HomeMenu extends StatefulWidget { class HomeMenu extends StatelessWidget {
final PublishNotifier<bool> _collapsedNotifier; final PublishNotifier<bool> _collapsedNotifier;
final UserProfile user; final UserProfile user;
final CurrentWorkspaceSetting workspaceSetting; final CurrentWorkspaceSetting workspaceSetting;
@ -39,22 +39,13 @@ class HomeMenu extends StatefulWidget {
}) : _collapsedNotifier = collapsedNotifier, }) : _collapsedNotifier = collapsedNotifier,
super(key: key); super(key: key);
@override
State<HomeMenu> createState() => _HomeMenuState();
}
class _HomeMenuState extends State<HomeMenu> {
/// Maps the hashmap of the menu items to their index in reorderable list view.
//TODO @gaganyadav80: Retain this map to persist on app restarts.
final Map<int, int> _menuItemIndex = <int, int>{};
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MultiBlocProvider( return MultiBlocProvider(
providers: [ providers: [
BlocProvider<MenuBloc>( BlocProvider<MenuBloc>(
create: (context) { create: (context) {
final menuBloc = getIt<MenuBloc>(param1: widget.user, param2: widget.workspaceSetting.workspace.id); final menuBloc = getIt<MenuBloc>(param1: user, param2: workspaceSetting.workspace.id);
menuBloc.add(const MenuEvent.initial()); menuBloc.add(const MenuEvent.initial());
return menuBloc; return menuBloc;
}, },
@ -71,7 +62,7 @@ class _HomeMenuState extends State<HomeMenu> {
BlocListener<MenuBloc, MenuState>( BlocListener<MenuBloc, MenuState>(
listenWhen: (p, c) => p.isCollapse != c.isCollapse, listenWhen: (p, c) => p.isCollapse != c.isCollapse,
listener: (context, state) { listener: (context, state) {
widget._collapsedNotifier.value = state.isCollapse; _collapsedNotifier.value = state.isCollapse;
}, },
) )
], ],
@ -101,7 +92,7 @@ class _HomeMenuState extends State<HomeMenu> {
).padding(horizontal: Insets.l), ).padding(horizontal: Insets.l),
), ),
const VSpace(20), const VSpace(20),
_renderTrash(context).padding(horizontal: Insets.l), const MenuTrash().padding(horizontal: Insets.l),
const VSpace(20), const VSpace(20),
_renderNewAppButton(context), _renderNewAppButton(context),
], ],
@ -116,56 +107,18 @@ class _HomeMenuState extends State<HomeMenu> {
child: ScrollConfiguration( child: ScrollConfiguration(
behavior: const ScrollBehavior().copyWith(scrollbars: false), behavior: const ScrollBehavior().copyWith(scrollbars: false),
child: BlocSelector<MenuBloc, MenuState, List<Widget>>( child: BlocSelector<MenuBloc, MenuState, List<Widget>>(
selector: (state) { selector: (state) => state.apps.map((app) => MenuApp(app)).toList(),
List<Widget> menuItems = [];
// menuItems.add(MenuUser(user));
List<MenuApp> appWidgets =
state.apps.foldRight([], (apps, _) => apps.map((app) => MenuApp(app)).toList());
// menuItems.addAll(appWidgets);
for (int i = 0; i < appWidgets.length; i++) {
if (_menuItemIndex[appWidgets[i].key.hashCode] == null) {
_menuItemIndex[appWidgets[i].key.hashCode] = i;
}
menuItems.insert(_menuItemIndex[appWidgets[i].key.hashCode]!, appWidgets[i]);
}
return menuItems;
},
builder: (context, menuItems) { builder: (context, menuItems) {
return ReorderableListView.builder( return ReorderableListView.builder(
itemCount: menuItems.length, itemCount: menuItems.length,
buildDefaultDragHandles: false, buildDefaultDragHandles: false,
header: Padding( header: Padding(
padding: EdgeInsets.only(bottom: 20.0 - MenuAppSizes.appVPadding), padding: EdgeInsets.only(bottom: 20.0 - MenuAppSizes.appVPadding),
child: MenuUser(widget.user), child: MenuUser(user),
), ),
onReorder: (oldIndex, newIndex) { onReorder: (oldIndex, newIndex) => context.read<MenuBloc>().add(MenuEvent.moveApp(oldIndex, newIndex)),
int index = newIndex > oldIndex ? newIndex - 1 : newIndex;
Widget menu = menuItems.removeAt(oldIndex);
menuItems.insert(index, menu);
final menuBloc = context.read<MenuBloc>();
menuBloc.state.apps.forEach((a) {
var app = a.removeAt(oldIndex);
a.insert(index, app);
});
_menuItemIndex[menu.key.hashCode] = index;
},
physics: StyledScrollPhysics(), physics: StyledScrollPhysics(),
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
//? @gaganyadav80: To mimic the ListView.separated behavior, we need to add a padding.
// EdgeInsets padding = EdgeInsets.zero;
// if (index == 0) {
// padding = EdgeInsets.only(bottom: MenuAppSizes.appVPadding / 2);
// } else if (index == menuItems.length - 1) {
// padding = EdgeInsets.only(top: MenuAppSizes.appVPadding / 2);
// } else {
// padding = EdgeInsets.symmetric(vertical: MenuAppSizes.appVPadding / 2);
// }
return ReorderableDragStartListener( return ReorderableDragStartListener(
key: ValueKey(menuItems[index].hashCode), key: ValueKey(menuItems[index].hashCode),
index: index, index: index,
@ -183,10 +136,6 @@ class _HomeMenuState extends State<HomeMenu> {
); );
} }
Widget _renderTrash(BuildContext context) {
return const MenuTrash();
}
Widget _renderNewAppButton(BuildContext context) { Widget _renderNewAppButton(BuildContext context) {
return NewAppButton( return NewAppButton(
press: (appName) => context.read<MenuBloc>().add(MenuEvent.createApp(appName, desc: "")), press: (appName) => context.read<MenuBloc>().add(MenuEvent.createApp(appName, desc: "")),

View File

@ -169,6 +169,21 @@ impl FolderPad {
}) })
} }
#[tracing::instrument(level = "trace", skip(self), err)]
pub fn move_app(&mut self, app_id: &str, _from: usize, to: usize) -> CollaborateResult<Option<FolderChange>> {
let app = self.read_app(app_id)?;
self.with_workspace(&app.workspace_id, |workspace| {
match workspace.apps.iter().position(|app| app.id == app_id) {
None => Ok(None),
Some(index) => {
let app = workspace.apps.remove(index);
workspace.apps.insert(to, app);
Ok(Some(()))
}
}
})
}
#[tracing::instrument(level = "trace", skip(self), fields(view_name=%view.name), err)] #[tracing::instrument(level = "trace", skip(self), fields(view_name=%view.name), err)]
pub fn create_view(&mut self, view: View) -> CollaborateResult<Option<FolderChange>> { pub fn create_view(&mut self, view: View) -> CollaborateResult<Option<FolderChange>> {
let app_id = view.belong_to_id.clone(); let app_id = view.belong_to_id.clone();