From 70abe546a1b8208e591d6b14eeed03828c3d4160 Mon Sep 17 00:00:00 2001 From: appflowy Date: Wed, 27 Apr 2022 09:12:27 +0800 Subject: [PATCH 1/8] chore: remove freeze file --- .../application/menu/menu_bloc.freezed.dart | 1251 ----------------- 1 file changed, 1251 deletions(-) delete mode 100644 frontend/app_flowy/lib/workspace/application/menu/menu_bloc.freezed.dart diff --git a/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.freezed.dart b/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.freezed.dart deleted file mode 100644 index 633357d4cc811..0000000000000 --- a/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.freezed.dart +++ /dev/null @@ -1,1251 +0,0 @@ -// coverage:ignore-file -// 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_bloc.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(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 _$MenuEventTearOff { - const _$MenuEventTearOff(); - - _Initial initial() { - return const _Initial(); - } - - _Collapse collapse() { - return const _Collapse(); - } - - _OpenPage openPage(Plugin plugin) { - return _OpenPage( - plugin, - ); - } - - _CreateApp createApp(String name, {String? desc}) { - return _CreateApp( - name, - desc: desc, - ); - } - - _MoveApp moveApp(int fromIndex, int toIndex) { - return _MoveApp( - fromIndex, - toIndex, - ); - } - - _ReceiveApps didReceiveApps(Either, FlowyError> appsOrFail) { - return _ReceiveApps( - appsOrFail, - ); - } -} - -/// @nodoc -const $MenuEvent = _$MenuEventTearOff(); - -/// @nodoc -mixin _$MenuEvent { - @optionalTypeArgs - TResult when({ - 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, FlowyError> appsOrFail) - didReceiveApps, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - 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, FlowyError> appsOrFail)? didReceiveApps, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - 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, FlowyError> appsOrFail)? didReceiveApps, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - 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, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - 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, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - 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(), - }) => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $MenuEventCopyWith<$Res> { - factory $MenuEventCopyWith(MenuEvent value, $Res Function(MenuEvent) then) = - _$MenuEventCopyWithImpl<$Res>; -} - -/// @nodoc -class _$MenuEventCopyWithImpl<$Res> implements $MenuEventCopyWith<$Res> { - _$MenuEventCopyWithImpl(this._value, this._then); - - final MenuEvent _value; - // ignore: unused_field - final $Res Function(MenuEvent) _then; -} - -/// @nodoc -abstract class _$InitialCopyWith<$Res> { - factory _$InitialCopyWith(_Initial value, $Res Function(_Initial) then) = - __$InitialCopyWithImpl<$Res>; -} - -/// @nodoc -class __$InitialCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$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 'MenuEvent.initial()'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || (other is _Initial); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - 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, FlowyError> appsOrFail) - didReceiveApps, - }) { - return initial(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - 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, FlowyError> appsOrFail)? didReceiveApps, - }) { - return initial?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - 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, FlowyError> appsOrFail)? didReceiveApps, - required TResult orElse(), - }) { - if (initial != null) { - return initial(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - 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 initial(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - 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 initial?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - 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 (initial != null) { - return initial(this); - } - return orElse(); - } -} - -abstract class _Initial implements MenuEvent { - const factory _Initial() = _$_Initial; -} - -/// @nodoc -abstract class _$CollapseCopyWith<$Res> { - factory _$CollapseCopyWith(_Collapse value, $Res Function(_Collapse) then) = - __$CollapseCopyWithImpl<$Res>; -} - -/// @nodoc -class __$CollapseCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res> - implements _$CollapseCopyWith<$Res> { - __$CollapseCopyWithImpl(_Collapse _value, $Res Function(_Collapse) _then) - : super(_value, (v) => _then(v as _Collapse)); - - @override - _Collapse get _value => super._value as _Collapse; -} - -/// @nodoc - -class _$_Collapse implements _Collapse { - const _$_Collapse(); - - @override - String toString() { - return 'MenuEvent.collapse()'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || (other is _Collapse); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - 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, FlowyError> appsOrFail) - didReceiveApps, - }) { - return collapse(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - 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, FlowyError> appsOrFail)? didReceiveApps, - }) { - return collapse?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - 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, FlowyError> appsOrFail)? didReceiveApps, - required TResult orElse(), - }) { - if (collapse != null) { - return collapse(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - 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 collapse(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - 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 collapse?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - 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 (collapse != null) { - return collapse(this); - } - return orElse(); - } -} - -abstract class _Collapse implements MenuEvent { - const factory _Collapse() = _$_Collapse; -} - -/// @nodoc -abstract class _$OpenPageCopyWith<$Res> { - factory _$OpenPageCopyWith(_OpenPage value, $Res Function(_OpenPage) then) = - __$OpenPageCopyWithImpl<$Res>; - $Res call({Plugin plugin}); -} - -/// @nodoc -class __$OpenPageCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res> - implements _$OpenPageCopyWith<$Res> { - __$OpenPageCopyWithImpl(_OpenPage _value, $Res Function(_OpenPage) _then) - : super(_value, (v) => _then(v as _OpenPage)); - - @override - _OpenPage get _value => super._value as _OpenPage; - - @override - $Res call({ - Object? plugin = freezed, - }) { - return _then(_OpenPage( - plugin == freezed - ? _value.plugin - : plugin // ignore: cast_nullable_to_non_nullable - as Plugin, - )); - } -} - -/// @nodoc - -class _$_OpenPage implements _OpenPage { - const _$_OpenPage(this.plugin); - - @override - final Plugin plugin; - - @override - String toString() { - return 'MenuEvent.openPage(plugin: $plugin)'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other is _OpenPage && - (identical(other.plugin, plugin) || - const DeepCollectionEquality().equals(other.plugin, plugin))); - } - - @override - int get hashCode => - runtimeType.hashCode ^ const DeepCollectionEquality().hash(plugin); - - @JsonKey(ignore: true) - @override - _$OpenPageCopyWith<_OpenPage> get copyWith => - __$OpenPageCopyWithImpl<_OpenPage>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - 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, FlowyError> appsOrFail) - didReceiveApps, - }) { - return openPage(plugin); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - 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, FlowyError> appsOrFail)? didReceiveApps, - }) { - return openPage?.call(plugin); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - 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, FlowyError> appsOrFail)? didReceiveApps, - required TResult orElse(), - }) { - if (openPage != null) { - return openPage(plugin); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - 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 openPage(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - 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 openPage?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - 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 (openPage != null) { - return openPage(this); - } - return orElse(); - } -} - -abstract class _OpenPage implements MenuEvent { - const factory _OpenPage(Plugin plugin) = _$_OpenPage; - - Plugin get plugin => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - _$OpenPageCopyWith<_OpenPage> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class _$CreateAppCopyWith<$Res> { - factory _$CreateAppCopyWith( - _CreateApp value, $Res Function(_CreateApp) then) = - __$CreateAppCopyWithImpl<$Res>; - $Res call({String name, String? desc}); -} - -/// @nodoc -class __$CreateAppCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res> - implements _$CreateAppCopyWith<$Res> { - __$CreateAppCopyWithImpl(_CreateApp _value, $Res Function(_CreateApp) _then) - : super(_value, (v) => _then(v as _CreateApp)); - - @override - _CreateApp get _value => super._value as _CreateApp; - - @override - $Res call({ - Object? name = freezed, - Object? desc = freezed, - }) { - return _then(_CreateApp( - name == freezed - ? _value.name - : name // ignore: cast_nullable_to_non_nullable - as String, - desc: desc == freezed - ? _value.desc - : desc // ignore: cast_nullable_to_non_nullable - as String?, - )); - } -} - -/// @nodoc - -class _$_CreateApp implements _CreateApp { - const _$_CreateApp(this.name, {this.desc}); - - @override - final String name; - @override - final String? desc; - - @override - String toString() { - return 'MenuEvent.createApp(name: $name, desc: $desc)'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other is _CreateApp && - (identical(other.name, name) || - const DeepCollectionEquality().equals(other.name, name)) && - (identical(other.desc, desc) || - const DeepCollectionEquality().equals(other.desc, desc))); - } - - @override - int get hashCode => - runtimeType.hashCode ^ - const DeepCollectionEquality().hash(name) ^ - const DeepCollectionEquality().hash(desc); - - @JsonKey(ignore: true) - @override - _$CreateAppCopyWith<_CreateApp> get copyWith => - __$CreateAppCopyWithImpl<_CreateApp>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - 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, FlowyError> appsOrFail) - didReceiveApps, - }) { - return createApp(name, desc); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - 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, FlowyError> appsOrFail)? didReceiveApps, - }) { - return createApp?.call(name, desc); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - 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, FlowyError> appsOrFail)? didReceiveApps, - required TResult orElse(), - }) { - if (createApp != null) { - return createApp(name, desc); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - 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 createApp(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - 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 createApp?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - 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 (createApp != null) { - return createApp(this); - } - return orElse(); - } -} - -abstract class _CreateApp implements MenuEvent { - const factory _CreateApp(String name, {String? desc}) = _$_CreateApp; - - String get name => throw _privateConstructorUsedError; - String? get desc => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - _$CreateAppCopyWith<_CreateApp> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class _$MoveAppCopyWith<$Res> { - factory _$MoveAppCopyWith(_MoveApp value, $Res Function(_MoveApp) then) = - __$MoveAppCopyWithImpl<$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({ - 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, FlowyError> appsOrFail) - didReceiveApps, - }) { - return moveApp(fromIndex, toIndex); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - 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, FlowyError> appsOrFail)? didReceiveApps, - }) { - return moveApp?.call(fromIndex, toIndex); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - 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, FlowyError> appsOrFail)? didReceiveApps, - required TResult orElse(), - }) { - if (moveApp != null) { - return moveApp(fromIndex, toIndex); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - 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 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 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, FlowyError> 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, FlowyError>, - )); - } -} - -/// @nodoc - -class _$_ReceiveApps implements _ReceiveApps { - const _$_ReceiveApps(this.appsOrFail); - - @override - final Either, FlowyError> 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({ - 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, FlowyError> appsOrFail) - didReceiveApps, - }) { - return didReceiveApps(appsOrFail); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - 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, FlowyError> appsOrFail)? didReceiveApps, - }) { - return didReceiveApps?.call(appsOrFail); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - 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, FlowyError> appsOrFail)? didReceiveApps, - required TResult orElse(), - }) { - if (didReceiveApps != null) { - return didReceiveApps(appsOrFail); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - 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 didReceiveApps(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - 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 didReceiveApps?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - 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 (didReceiveApps != null) { - return didReceiveApps(this); - } - return orElse(); - } -} - -abstract class _ReceiveApps implements MenuEvent { - const factory _ReceiveApps(Either, FlowyError> appsOrFail) = - _$_ReceiveApps; - - Either, FlowyError> get appsOrFail => - throw _privateConstructorUsedError; - @JsonKey(ignore: true) - _$ReceiveAppsCopyWith<_ReceiveApps> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -class _$MenuStateTearOff { - const _$MenuStateTearOff(); - - _MenuState call( - {required bool isCollapse, - required List apps, - required Either successOrFailure, - required Plugin plugin}) { - return _MenuState( - isCollapse: isCollapse, - apps: apps, - successOrFailure: successOrFailure, - plugin: plugin, - ); - } -} - -/// @nodoc -const $MenuState = _$MenuStateTearOff(); - -/// @nodoc -mixin _$MenuState { - bool get isCollapse => throw _privateConstructorUsedError; - List get apps => throw _privateConstructorUsedError; - Either get successOrFailure => - throw _privateConstructorUsedError; - Plugin get plugin => throw _privateConstructorUsedError; - - @JsonKey(ignore: true) - $MenuStateCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $MenuStateCopyWith<$Res> { - factory $MenuStateCopyWith(MenuState value, $Res Function(MenuState) then) = - _$MenuStateCopyWithImpl<$Res>; - $Res call( - {bool isCollapse, - List apps, - Either successOrFailure, - Plugin plugin}); -} - -/// @nodoc -class _$MenuStateCopyWithImpl<$Res> implements $MenuStateCopyWith<$Res> { - _$MenuStateCopyWithImpl(this._value, this._then); - - final MenuState _value; - // ignore: unused_field - final $Res Function(MenuState) _then; - - @override - $Res call({ - Object? isCollapse = freezed, - Object? apps = freezed, - Object? successOrFailure = freezed, - Object? plugin = freezed, - }) { - return _then(_value.copyWith( - isCollapse: isCollapse == freezed - ? _value.isCollapse - : isCollapse // ignore: cast_nullable_to_non_nullable - as bool, - apps: apps == freezed - ? _value.apps - : apps // ignore: cast_nullable_to_non_nullable - as List, - successOrFailure: successOrFailure == freezed - ? _value.successOrFailure - : successOrFailure // ignore: cast_nullable_to_non_nullable - as Either, - plugin: plugin == freezed - ? _value.plugin - : plugin // ignore: cast_nullable_to_non_nullable - as Plugin, - )); - } -} - -/// @nodoc -abstract class _$MenuStateCopyWith<$Res> implements $MenuStateCopyWith<$Res> { - factory _$MenuStateCopyWith( - _MenuState value, $Res Function(_MenuState) then) = - __$MenuStateCopyWithImpl<$Res>; - @override - $Res call( - {bool isCollapse, - List apps, - Either successOrFailure, - Plugin plugin}); -} - -/// @nodoc -class __$MenuStateCopyWithImpl<$Res> extends _$MenuStateCopyWithImpl<$Res> - implements _$MenuStateCopyWith<$Res> { - __$MenuStateCopyWithImpl(_MenuState _value, $Res Function(_MenuState) _then) - : super(_value, (v) => _then(v as _MenuState)); - - @override - _MenuState get _value => super._value as _MenuState; - - @override - $Res call({ - Object? isCollapse = freezed, - Object? apps = freezed, - Object? successOrFailure = freezed, - Object? plugin = freezed, - }) { - return _then(_MenuState( - isCollapse: isCollapse == freezed - ? _value.isCollapse - : isCollapse // ignore: cast_nullable_to_non_nullable - as bool, - apps: apps == freezed - ? _value.apps - : apps // ignore: cast_nullable_to_non_nullable - as List, - successOrFailure: successOrFailure == freezed - ? _value.successOrFailure - : successOrFailure // ignore: cast_nullable_to_non_nullable - as Either, - plugin: plugin == freezed - ? _value.plugin - : plugin // ignore: cast_nullable_to_non_nullable - as Plugin, - )); - } -} - -/// @nodoc - -class _$_MenuState implements _MenuState { - const _$_MenuState( - {required this.isCollapse, - required this.apps, - required this.successOrFailure, - required this.plugin}); - - @override - final bool isCollapse; - @override - final List apps; - @override - final Either successOrFailure; - @override - final Plugin plugin; - - @override - String toString() { - return 'MenuState(isCollapse: $isCollapse, apps: $apps, successOrFailure: $successOrFailure, plugin: $plugin)'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other is _MenuState && - (identical(other.isCollapse, isCollapse) || - const DeepCollectionEquality() - .equals(other.isCollapse, isCollapse)) && - (identical(other.apps, apps) || - const DeepCollectionEquality().equals(other.apps, apps)) && - (identical(other.successOrFailure, successOrFailure) || - const DeepCollectionEquality() - .equals(other.successOrFailure, successOrFailure)) && - (identical(other.plugin, plugin) || - const DeepCollectionEquality().equals(other.plugin, plugin))); - } - - @override - int get hashCode => - runtimeType.hashCode ^ - const DeepCollectionEquality().hash(isCollapse) ^ - const DeepCollectionEquality().hash(apps) ^ - const DeepCollectionEquality().hash(successOrFailure) ^ - const DeepCollectionEquality().hash(plugin); - - @JsonKey(ignore: true) - @override - _$MenuStateCopyWith<_MenuState> get copyWith => - __$MenuStateCopyWithImpl<_MenuState>(this, _$identity); -} - -abstract class _MenuState implements MenuState { - const factory _MenuState( - {required bool isCollapse, - required List apps, - required Either successOrFailure, - required Plugin plugin}) = _$_MenuState; - - @override - bool get isCollapse => throw _privateConstructorUsedError; - @override - List get apps => throw _privateConstructorUsedError; - @override - Either get successOrFailure => - throw _privateConstructorUsedError; - @override - Plugin get plugin => throw _privateConstructorUsedError; - @override - @JsonKey(ignore: true) - _$MenuStateCopyWith<_MenuState> get copyWith => - throw _privateConstructorUsedError; -} From d0b4abb0c839c46ed273ef75ef509736ff2e48ad Mon Sep 17 00:00:00 2001 From: appflowy Date: Wed, 27 Apr 2022 13:31:54 +0800 Subject: [PATCH 2/8] refactor: cell context builder --- .../application/grid/cell/cell_service.dart | 43 +++++++++++++++++- .../grid/src/widgets/cell/cell_builder.dart | 44 ++++--------------- .../grid/src/widgets/cell/checkbox_cell.dart | 8 ++-- .../grid/src/widgets/cell/date_cell.dart | 7 +-- .../grid/src/widgets/cell/number_cell.dart | 7 +-- .../cell/selection_cell/selection_cell.dart | 30 +++++++------ .../grid/src/widgets/cell/text_cell.dart | 7 +-- 7 files changed, 82 insertions(+), 64 deletions(-) diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service.dart b/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service.dart index 1aa090d443707..251ca0ef2945d 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service.dart @@ -1,7 +1,9 @@ import 'dart:async'; import 'dart:collection'; +import 'package:app_flowy/workspace/application/grid/cell/select_option_service.dart'; import 'package:dartz/dartz.dart'; +import 'package:equatable/equatable.dart'; import 'package:flowy_sdk/dispatch/dispatch.dart'; import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; @@ -10,13 +12,52 @@ import 'package:flowy_sdk/protobuf/flowy-grid/cell_entities.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/selection_type_option.pb.dart'; import 'package:flutter/foundation.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; + import 'package:app_flowy/workspace/application/grid/cell/cell_listener.dart'; -import 'package:equatable/equatable.dart'; + part 'cell_service.freezed.dart'; typedef GridDefaultCellContext = GridCellContext; typedef GridSelectOptionCellContext = GridCellContext; +class GridCellContextBuilder { + final GridCellCache _cellCache; + final GridCell _gridCell; + GridCellContextBuilder({ + required GridCellCache cellCache, + required GridCell gridCell, + }) : _cellCache = cellCache, + _gridCell = gridCell; + + GridCellContext build() { + switch (_gridCell.field.fieldType) { + case FieldType.Checkbox: + case FieldType.DateTime: + case FieldType.Number: + return GridDefaultCellContext( + gridCell: _gridCell, + cellCache: _cellCache, + cellDataLoader: DefaultCellDataLoader(gridCell: _gridCell, reloadOnCellChanged: true), + ); + case FieldType.RichText: + return GridDefaultCellContext( + gridCell: _gridCell, + cellCache: _cellCache, + cellDataLoader: DefaultCellDataLoader(gridCell: _gridCell), + ); + case FieldType.MultiSelect: + case FieldType.SingleSelect: + return GridSelectOptionCellContext( + gridCell: _gridCell, + cellCache: _cellCache, + cellDataLoader: SelectOptionCellDataLoader(gridCell: _gridCell), + ); + default: + throw UnimplementedError; + } + } +} + // ignore: must_be_immutable class GridCellContext extends Equatable { final GridCell gridCell; diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart index df72ba3ae1047..8ebc70352b98e 100755 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart @@ -1,5 +1,4 @@ import 'package:app_flowy/workspace/application/grid/cell/cell_service.dart'; -import 'package:app_flowy/workspace/application/grid/cell/select_option_service.dart'; import 'package:flowy_infra_ui/style_widget/hover.dart'; import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart' show FieldType; import 'package:flutter/widgets.dart'; @@ -12,49 +11,22 @@ import 'text_cell.dart'; GridCellWidget buildGridCellWidget(GridCell gridCell, GridCellCache cellCache, {GridCellStyle? style}) { final key = ValueKey(gridCell.rowId + gridCell.field.id); - final cellContext = makeCellContext(gridCell, cellCache); + final cellContextBuilder = GridCellContextBuilder(gridCell: gridCell, cellCache: cellCache); switch (gridCell.field.fieldType) { case FieldType.Checkbox: - return CheckboxCell(cellContext: cellContext, key: key); + return CheckboxCell(cellContextBuilder: cellContextBuilder, key: key); case FieldType.DateTime: - return DateCell(cellContext: cellContext, key: key); + return DateCell(cellContextBuilder: cellContextBuilder, key: key); + case FieldType.SingleSelect: + return SingleSelectCell(cellContextBuilder: cellContextBuilder, style: style, key: key); case FieldType.MultiSelect: - return MultiSelectCell(cellContext: cellContext as GridSelectOptionCellContext, style: style, key: key); + return MultiSelectCell(cellContextBuilder: cellContextBuilder, style: style, key: key); case FieldType.Number: - return NumberCell(cellContext: cellContext, key: key); + return NumberCell(cellContextBuilder: cellContextBuilder, key: key); case FieldType.RichText: - return GridTextCell(cellContext: cellContext, style: style, key: key); - case FieldType.SingleSelect: - return SingleSelectCell(cellContext: cellContext as GridSelectOptionCellContext, style: style, key: key); - default: - throw UnimplementedError; - } -} + return GridTextCell(cellContextBuilder: cellContextBuilder, style: style, key: key); -GridCellContext makeCellContext(GridCell gridCell, GridCellCache cellCache) { - switch (gridCell.field.fieldType) { - case FieldType.Checkbox: - case FieldType.DateTime: - case FieldType.Number: - return GridDefaultCellContext( - gridCell: gridCell, - cellCache: cellCache, - cellDataLoader: DefaultCellDataLoader(gridCell: gridCell, reloadOnCellChanged: true), - ); - case FieldType.RichText: - return GridDefaultCellContext( - gridCell: gridCell, - cellCache: cellCache, - cellDataLoader: DefaultCellDataLoader(gridCell: gridCell), - ); - case FieldType.MultiSelect: - case FieldType.SingleSelect: - return GridSelectOptionCellContext( - gridCell: gridCell, - cellCache: cellCache, - cellDataLoader: SelectOptionCellDataLoader(gridCell: gridCell), - ); default: throw UnimplementedError; } diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart index 991b56a832b21..80d5c70f8d6d1 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart @@ -7,10 +7,9 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'cell_builder.dart'; class CheckboxCell extends GridCellWidget { - final GridCellContext cellContext; - + final GridCellContextBuilder cellContextBuilder; CheckboxCell({ - required this.cellContext, + required this.cellContextBuilder, Key? key, }) : super(key: key); @@ -23,7 +22,8 @@ class _CheckboxCellState extends State { @override void initState() { - _cellBloc = getIt(param1: widget.cellContext)..add(const CheckboxCellEvent.initial()); + final cellContext = widget.cellContextBuilder.build(); + _cellBloc = getIt(param1: cellContext)..add(const CheckboxCellEvent.initial()); super.initState(); } diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/date_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/date_cell.dart index a3cc807266da8..a68bfcb4bc35c 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/date_cell.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/date_cell.dart @@ -14,10 +14,10 @@ abstract class GridCellDelegate { } class DateCell extends GridCellWidget { - final GridCellContext cellContext; + final GridCellContextBuilder cellContextBuilder; DateCell({ - required this.cellContext, + required this.cellContextBuilder, Key? key, }) : super(key: key); @@ -30,7 +30,8 @@ class _DateCellState extends State { @override void initState() { - _cellBloc = getIt(param1: widget.cellContext)..add(const DateCellEvent.initial()); + final cellContext = widget.cellContextBuilder.build(); + _cellBloc = getIt(param1: cellContext)..add(const DateCellEvent.initial()); super.initState(); } diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart index 168d2258d3484..6d66ab7c3e3ca 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart @@ -8,10 +8,10 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'cell_builder.dart'; class NumberCell extends GridCellWidget { - final GridCellContext cellContext; + final GridCellContextBuilder cellContextBuilder; NumberCell({ - required this.cellContext, + required this.cellContextBuilder, Key? key, }) : super(key: key); @@ -27,7 +27,8 @@ class _NumberCellState extends State { @override void initState() { - _cellBloc = getIt(param1: widget.cellContext)..add(const NumberCellEvent.initial()); + final cellContext = widget.cellContextBuilder.build(); + _cellBloc = getIt(param1: cellContext)..add(const NumberCellEvent.initial()); _controller = TextEditingController(text: _cellBloc.state.content); _focusNode = FocusNode(); _focusNode.addListener(() { diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/selection_cell/selection_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/selection_cell/selection_cell.dart index 939594f19c928..fe10341dcfb1a 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/selection_cell/selection_cell.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/selection_cell/selection_cell.dart @@ -20,11 +20,11 @@ class SelectOptionCellStyle extends GridCellStyle { } class SingleSelectCell extends GridCellWidget { - final GridSelectOptionCellContext cellContext; + final GridCellContextBuilder cellContextBuilder; late final SelectOptionCellStyle? cellStyle; SingleSelectCell({ - required this.cellContext, + required this.cellContextBuilder, GridCellStyle? style, Key? key, }) : super(key: key) { @@ -45,7 +45,8 @@ class _SingleSelectCellState extends State { @override void initState() { // Log.trace("init widget $hashCode"); - _cellBloc = getIt(param1: widget.cellContext)..add(const SelectionCellEvent.initial()); + final cellContext = _buildCellContext(); + _cellBloc = getIt(param1: cellContext)..add(const SelectionCellEvent.initial()); super.initState(); } @@ -69,7 +70,7 @@ class _SingleSelectCellState extends State { widget.onFocus.value = true; SelectOptionCellEditor.show( context, - widget.cellContext.clone(), + _buildCellContext(), () => widget.onFocus.value = false, ); }, @@ -81,12 +82,8 @@ class _SingleSelectCellState extends State { ); } - @override - void didUpdateWidget(covariant SingleSelectCell oldWidget) { - if (oldWidget.cellContext != widget.cellContext) { - // Log.trace("did update widget $hashCode"); - } - super.didUpdateWidget(oldWidget); + GridSelectOptionCellContext _buildCellContext() { + return widget.cellContextBuilder.build() as GridSelectOptionCellContext; } @override @@ -99,11 +96,11 @@ class _SingleSelectCellState extends State { //---------------------------------------------------------------- class MultiSelectCell extends GridCellWidget { - final GridSelectOptionCellContext cellContext; + final GridCellContextBuilder cellContextBuilder; late final SelectOptionCellStyle? cellStyle; MultiSelectCell({ - required this.cellContext, + required this.cellContextBuilder, GridCellStyle? style, Key? key, }) : super(key: key) { @@ -123,7 +120,8 @@ class _MultiSelectCellState extends State { @override void initState() { - _cellBloc = getIt(param1: widget.cellContext)..add(const SelectionCellEvent.initial()); + final cellContext = _buildCellContext(); + _cellBloc = getIt(param1: cellContext)..add(const SelectionCellEvent.initial()); super.initState(); } @@ -145,7 +143,7 @@ class _MultiSelectCellState extends State { widget.onFocus.value = true; SelectOptionCellEditor.show( context, - widget.cellContext, + _buildCellContext(), () => widget.onFocus.value = false, ); }, @@ -162,4 +160,8 @@ class _MultiSelectCellState extends State { _cellBloc.close(); super.dispose(); } + + GridSelectOptionCellContext _buildCellContext() { + return widget.cellContextBuilder.build() as GridSelectOptionCellContext; + } } diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart index 6d77f5f2cf4f4..a9d3d135328eb 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart @@ -14,10 +14,10 @@ class GridTextCellStyle extends GridCellStyle { } class GridTextCell extends GridCellWidget { - final GridCellContext cellContext; + final GridCellContextBuilder cellContextBuilder; late final GridTextCellStyle? cellStyle; GridTextCell({ - required this.cellContext, + required this.cellContextBuilder, GridCellStyle? style, Key? key, }) : super(key: key) { @@ -41,7 +41,8 @@ class _GridTextCellState extends State { @override void initState() { - _cellBloc = getIt(param1: widget.cellContext); + final cellContext = widget.cellContextBuilder.build(); + _cellBloc = getIt(param1: cellContext); _cellBloc.add(const TextCellEvent.initial()); _controller = TextEditingController(text: _cellBloc.state.content); _focusNode = FocusNode(); From f972cdd3fb2d07e23bf565f2d9d906900f0b23a5 Mon Sep 17 00:00:00 2001 From: appflowy Date: Wed, 27 Apr 2022 14:24:50 +0800 Subject: [PATCH 3/8] chore: optimize cell focus --- .../grid/src/widgets/cell/cell_builder.dart | 9 ++++++++ .../grid/src/widgets/cell/cell_container.dart | 20 +++++++++++----- .../grid/src/widgets/cell/checkbox_cell.dart | 13 +++++++++++ .../grid/src/widgets/cell/number_cell.dart | 20 ++++++++++++++++ .../grid/src/widgets/cell/text_cell.dart | 23 ++++++++++++++++++- .../grid/src/widgets/row/grid_row.dart | 13 ++++++----- 6 files changed, 85 insertions(+), 13 deletions(-) diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart index 8ebc70352b98e..4d62dc9eb213d 100755 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart @@ -44,7 +44,16 @@ class BlankCell extends StatelessWidget { abstract class GridCellWidget extends HoverWidget { @override final ValueNotifier onFocus = ValueNotifier(false); + + final GridCellRequestFocusNotifier requestFocus = GridCellRequestFocusNotifier(); + GridCellWidget({Key? key}) : super(key: key); } +class GridCellRequestFocusNotifier extends ChangeNotifier { + void notify() { + notifyListeners(); + } +} + abstract class GridCellStyle {} diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_container.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_container.dart index 17c1e8771057f..89f3700a0d230 100755 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_container.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_container.dart @@ -1,3 +1,4 @@ +import 'package:app_flowy/workspace/presentation/plugins/grid/src/widgets/row/grid_row.dart'; import 'package:flowy_infra/theme.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -31,17 +32,20 @@ class CellContainer extends StatelessWidget { final GridCellWidget child; final Widget? expander; final double width; + final RegionStateNotifier rowStateNotifier; const CellContainer({ Key? key, required this.child, required this.width, + required this.rowStateNotifier, this.expander, }) : super(key: key); @override Widget build(BuildContext context) { - return ChangeNotifierProvider( + return ChangeNotifierProxyProvider( create: (_) => CellStateNotifier(), + update: (_, row, cell) => cell!..onEnter = row.onEnter, child: Selector( selector: (context, notifier) => notifier.isFocus, builder: (context, isFocus, _) { @@ -54,11 +58,15 @@ class CellContainer extends StatelessWidget { container = _CellEnterRegion(child: container, expander: expander!); } - return Container( - constraints: BoxConstraints(maxWidth: width), - decoration: _makeBoxDecoration(context, isFocus), - padding: GridSize.cellContentInsets, - child: container, + return GestureDetector( + behavior: HitTestBehavior.translucent, + onTap: () => child.requestFocus.notify(), + child: Container( + constraints: BoxConstraints(maxWidth: width), + decoration: _makeBoxDecoration(context, isFocus), + padding: GridSize.cellContentInsets, + child: container, + ), ); }, ), diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart index 80d5c70f8d6d1..99fcd4a26fd56 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart @@ -24,6 +24,7 @@ class _CheckboxCellState extends State { void initState() { final cellContext = widget.cellContextBuilder.build(); _cellBloc = getIt(param1: cellContext)..add(const CheckboxCellEvent.initial()); + _listenCellRequestFocus(); super.initState(); } @@ -48,9 +49,21 @@ class _CheckboxCellState extends State { ); } + @override + void didUpdateWidget(covariant CheckboxCell oldWidget) { + _listenCellRequestFocus(); + super.didUpdateWidget(oldWidget); + } + @override Future dispose() async { _cellBloc.close(); super.dispose(); } + + void _listenCellRequestFocus() { + widget.requestFocus.addListener(() { + _cellBloc.add(const CheckboxCellEvent.select()); + }); + } } diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart index 6d66ab7c3e3ca..9901790fa5c84 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart @@ -23,6 +23,7 @@ class _NumberCellState extends State { late NumberCellBloc _cellBloc; late TextEditingController _controller; late FocusNode _focusNode; + VoidCallback? _focusListener; Timer? _delayOperation; @override @@ -40,6 +41,7 @@ class _NumberCellState extends State { @override Widget build(BuildContext context) { + _listenCellRequestFocus(context); return BlocProvider.value( value: _cellBloc, child: BlocConsumer( @@ -68,6 +70,9 @@ class _NumberCellState extends State { @override Future dispose() async { + if (_focusListener != null) { + widget.requestFocus.removeListener(_focusListener!); + } _delayOperation?.cancel(); _cellBloc.close(); _focusNode.dispose(); @@ -89,4 +94,19 @@ class _NumberCellState extends State { }); } } + + void _listenCellRequestFocus(BuildContext context) { + if (_focusListener != null) { + widget.requestFocus.removeListener(_focusListener!); + } + + focusListener() { + if (_focusNode.hasFocus == false && _focusNode.canRequestFocus) { + FocusScope.of(context).requestFocus(_focusNode); + } + } + + _focusListener = focusListener; + widget.requestFocus.addListener(focusListener); + } } diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart index a9d3d135328eb..822dc69fb94d4 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart @@ -36,7 +36,7 @@ class _GridTextCellState extends State { late TextCellBloc _cellBloc; late TextEditingController _controller; late FocusNode _focusNode; - + VoidCallback? _focusListener; Timer? _delayOperation; @override @@ -50,11 +50,14 @@ class _GridTextCellState extends State { widget.onFocus.value = _focusNode.hasFocus; focusChanged(); }); + super.initState(); } @override Widget build(BuildContext context) { + _listenCellRequestFocus(context); + return BlocProvider.value( value: _cellBloc, child: BlocConsumer( @@ -84,8 +87,26 @@ class _GridTextCellState extends State { ); } + void _listenCellRequestFocus(BuildContext context) { + if (_focusListener != null) { + widget.requestFocus.removeListener(_focusListener!); + } + + focusListener() { + if (_focusNode.hasFocus == false && _focusNode.canRequestFocus) { + FocusScope.of(context).requestFocus(_focusNode); + } + } + + _focusListener = focusListener; + widget.requestFocus.addListener(focusListener); + } + @override Future dispose() async { + if (_focusListener != null) { + widget.requestFocus.removeListener(_focusListener!); + } _delayOperation?.cancel(); _cellBloc.close(); _focusNode.dispose(); diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/grid_row.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/grid_row.dart index 62cdc5c53fa9b..eb744af7b20d3 100755 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/grid_row.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/grid_row.dart @@ -88,7 +88,7 @@ class _RowLeading extends StatelessWidget { @override Widget build(BuildContext context) { - return Consumer<_RegionStateNotifier>( + return Consumer( builder: (context, state, _) { return SizedBox(width: GridSize.leadingHeaderPadding, child: state.onEnter ? _activeWidget() : null); }, @@ -164,13 +164,13 @@ class _RowCells extends StatelessWidget { return Row( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.center, - children: _makeCells(state.cellDataMap), + children: _makeCells(context, state.cellDataMap), ); }, ); } - List _makeCells(GridCellMap gridCellMap) { + List _makeCells(BuildContext context, GridCellMap gridCellMap) { return gridCellMap.values.map( (gridCell) { Widget? expander; @@ -181,6 +181,7 @@ class _RowCells extends StatelessWidget { return CellContainer( width: gridCell.field.width.toDouble(), child: buildGridCellWidget(gridCell, cellCache), + rowStateNotifier: Provider.of(context, listen: false), expander: expander, ); }, @@ -188,7 +189,7 @@ class _RowCells extends StatelessWidget { } } -class _RegionStateNotifier extends ChangeNotifier { +class RegionStateNotifier extends ChangeNotifier { bool _onEnter = false; set onEnter(bool value) { @@ -226,11 +227,11 @@ class _RowEnterRegion extends StatefulWidget { } class _RowEnterRegionState extends State<_RowEnterRegion> { - late _RegionStateNotifier _rowStateNotifier; + late RegionStateNotifier _rowStateNotifier; @override void initState() { - _rowStateNotifier = _RegionStateNotifier(); + _rowStateNotifier = RegionStateNotifier(); super.initState(); } From ecd2dc3e7263bd74d5d07802f3043695111900f4 Mon Sep 17 00:00:00 2001 From: appflowy Date: Thu, 28 Apr 2022 16:02:03 +0800 Subject: [PATCH 4/8] fix: reorder bugs --- .../workspace/application/app/app_bloc.dart | 11 ++++++- .../workspace/application/menu/menu_bloc.dart | 3 ++ .../presentation/home/menu/menu.dart | 10 +++++- .../persistence/version_1/view_sql.rs | 2 +- .../flowy-net/src/local_server/server.rs | 2 +- .../src/client_folder/folder_pad.rs | 26 ++++++--------- shared-lib/lib-infra/src/lib.rs | 6 +--- shared-lib/lib-infra/src/util.rs | 32 +++++++++++++++++++ 8 files changed, 67 insertions(+), 25 deletions(-) create mode 100644 shared-lib/lib-infra/src/util.rs diff --git a/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart b/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart index 5f97e7028ecaa..4dd10675e0722 100644 --- a/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart @@ -161,11 +161,12 @@ class AppViewDataContext extends ChangeNotifier { final String appId; final ValueNotifier> _viewsNotifier = ValueNotifier([]); final ValueNotifier _selectedViewNotifier = ValueNotifier(null); + VoidCallback? _menuSharedStateListener; ExpandableController expandController = ExpandableController(initialExpanded: false); AppViewDataContext({required this.appId}) { _setLatestView(getIt().latestOpenView); - getIt().addLatestViewListener((view) { + _menuSharedStateListener = getIt().addLatestViewListener((view) { _setLatestView(view); }); } @@ -234,4 +235,12 @@ class AppViewDataContext extends ChangeNotifier { }); } } + + @override + void dispose() { + if (_menuSharedStateListener != null) { + getIt().removeLatestViewListener(_menuSharedStateListener!); + } + super.dispose(); + } } diff --git a/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.dart b/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.dart index 558c84b83ae53..a2c167cde4794 100644 --- a/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.dart @@ -45,6 +45,9 @@ class MenuBloc extends Bloc { if (state.apps.length > value.fromIndex) { final app = state.apps[value.fromIndex]; _workspaceService.moveApp(appId: app.id, fromIndex: value.fromIndex, toIndex: value.toIndex); + final apps = List.from(state.apps); + apps.insert(value.toIndex, apps.removeAt(value.fromIndex)); + emit(state.copyWith(apps: apps)); } }, ); diff --git a/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart b/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart index b8c116a45adb1..bf35ada57675c 100644 --- a/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart +++ b/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart @@ -8,6 +8,7 @@ import 'package:flowy_infra/size.dart'; import 'package:flowy_infra/theme.dart'; import 'package:flowy_infra_ui/style_widget/scrolling/styled_list.dart'; import 'package:flowy_infra_ui/widget/spacing.dart'; +import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart' show UserProfile; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; @@ -116,7 +117,14 @@ class HomeMenu extends StatelessWidget { padding: EdgeInsets.only(bottom: 20.0 - MenuAppSizes.appVPadding), child: MenuUser(user), ), - onReorder: (oldIndex, newIndex) => context.read().add(MenuEvent.moveApp(oldIndex, newIndex)), + onReorder: (oldIndex, newIndex) { + // Moving item1 from index 0 to index 1 + // expect: oldIndex: 0, newIndex: 1 + // receive: oldIndex: 0, newIndex: 2 + // Workaround: if newIndex > oldIndex, we just minus one + int index = newIndex > oldIndex ? newIndex - 1 : newIndex; + context.read().add(MenuEvent.moveApp(oldIndex, index)); + }, physics: StyledScrollPhysics(), itemBuilder: (BuildContext context, int index) { return ReorderableDragStartListener( diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs index a41f3c49c2462..bda73dd71d63b 100644 --- a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs +++ b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs @@ -12,7 +12,7 @@ use flowy_database::{ schema::{view_table, view_table::dsl}, SqliteConnection, }; -use lib_infra::timestamp; +use lib_infra::util::timestamp; pub struct ViewTableSql(); impl ViewTableSql { diff --git a/frontend/rust-lib/flowy-net/src/local_server/server.rs b/frontend/rust-lib/flowy-net/src/local_server/server.rs index e2eaf7de95236..c9a6d20cf3951 100644 --- a/frontend/rust-lib/flowy-net/src/local_server/server.rs +++ b/frontend/rust-lib/flowy-net/src/local_server/server.rs @@ -265,7 +265,7 @@ use flowy_user::event_map::UserCloudService; use flowy_user_data_model::entities::{ SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserParams, UserProfile, }; -use lib_infra::{future::FutureResult, timestamp}; +use lib_infra::{future::FutureResult, util::timestamp}; impl FolderCouldServiceV1 for LocalServer { fn init(&self) {} diff --git a/shared-lib/flowy-sync/src/client_folder/folder_pad.rs b/shared-lib/flowy-sync/src/client_folder/folder_pad.rs index f1eb3aba5d4ec..1cb590eb52edb 100644 --- a/shared-lib/flowy-sync/src/client_folder/folder_pad.rs +++ b/shared-lib/flowy-sync/src/client_folder/folder_pad.rs @@ -10,6 +10,8 @@ use crate::{ use flowy_folder_data_model::entities::{app::App, trash::Trash, view::View, workspace::Workspace}; use lib_ot::core::*; +use crate::errors::internal_error; +use lib_infra::util::move_vec_element; use serde::{Deserialize, Serialize}; use std::sync::Arc; @@ -170,16 +172,12 @@ impl FolderPad { } #[tracing::instrument(level = "trace", skip(self), err)] - pub fn move_app(&mut self, app_id: &str, _from: usize, to: usize) -> CollaborateResult> { + pub fn move_app(&mut self, app_id: &str, from: usize, to: usize) -> CollaborateResult> { 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(())) - } + match move_vec_element(&mut workspace.apps, |app| app.id == app_id, from, to).map_err(internal_error)? { + true => Ok(Some(())), + false => Ok(None), } }) } @@ -251,16 +249,12 @@ impl FolderPad { } #[tracing::instrument(level = "trace", skip(self), err)] - pub fn move_view(&mut self, view_id: &str, _from: usize, to: usize) -> CollaborateResult> { + pub fn move_view(&mut self, view_id: &str, from: usize, to: usize) -> CollaborateResult> { let view = self.read_view(view_id)?; self.with_app(&view.belong_to_id, |app| { - match app.belongings.iter().position(|view| view.id == view_id) { - None => Ok(None), - Some(index) => { - let view = app.belongings.remove(index); - app.belongings.insert(to, view); - Ok(Some(())) - } + match move_vec_element(&mut app.belongings, |view| view.id == view_id, from, to).map_err(internal_error)? { + true => Ok(Some(())), + false => Ok(None), } }) } diff --git a/shared-lib/lib-infra/src/lib.rs b/shared-lib/lib-infra/src/lib.rs index cb6aee91b0710..f304749731a3c 100644 --- a/shared-lib/lib-infra/src/lib.rs +++ b/shared-lib/lib-infra/src/lib.rs @@ -1,8 +1,4 @@ pub mod code_gen; pub mod future; pub mod retry; - -#[allow(dead_code)] -pub fn timestamp() -> i64 { - chrono::Utc::now().timestamp() -} +pub mod util; diff --git a/shared-lib/lib-infra/src/util.rs b/shared-lib/lib-infra/src/util.rs new file mode 100644 index 0000000000000..3d26cfa3f9de6 --- /dev/null +++ b/shared-lib/lib-infra/src/util.rs @@ -0,0 +1,32 @@ +pub fn move_vec_element( + vec: &mut Vec, + filter: F, + _from_index: usize, + mut to_index: usize, +) -> Result +where + F: FnMut(&T) -> bool, +{ + match vec.iter().position(filter) { + None => Ok(false), + Some(index) => { + if vec.len() > to_index { + let removed_element = vec.remove(index); + vec.insert(to_index, removed_element); + Ok(true) + } else { + let msg = format!( + "Move element to invalid index: {}, current len: {}", + to_index, + vec.len() + ); + Err(msg) + } + } + } +} + +#[allow(dead_code)] +pub fn timestamp() -> i64 { + chrono::Utc::now().timestamp() +} From 0285b286a6b31d781debcb51805e0461989a9be2 Mon Sep 17 00:00:00 2001 From: appflowy Date: Thu, 28 Apr 2022 16:30:04 +0800 Subject: [PATCH 5/8] fix: auto expand again after reorder app --- .../lib/workspace/presentation/home/menu/app/menu_app.dart | 7 ++++++- .../lib/workspace/presentation/home/menu/menu.dart | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/frontend/app_flowy/lib/workspace/presentation/home/menu/app/menu_app.dart b/frontend/app_flowy/lib/workspace/presentation/home/menu/app/menu_app.dart index 67b52481e73bf..ae7345612acdf 100644 --- a/frontend/app_flowy/lib/workspace/presentation/home/menu/app/menu_app.dart +++ b/frontend/app_flowy/lib/workspace/presentation/home/menu/app/menu_app.dart @@ -11,7 +11,7 @@ import 'section/section.dart'; class MenuApp extends StatefulWidget { final App app; - MenuApp(this.app, {Key? key}) : super(key: ValueKey(app.hashCode)); + const MenuApp(this.app, {Key? key}) : super(key: key); @override State createState() => _MenuAppState(); @@ -95,6 +95,11 @@ class _MenuAppState extends State { ); } + @override + void didUpdateWidget(covariant MenuApp oldWidget) { + super.didUpdateWidget(oldWidget); + } + @override void dispose() { viewDataContext.dispose(); diff --git a/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart b/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart index bf35ada57675c..4c71bba3b21a6 100644 --- a/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart +++ b/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart @@ -108,7 +108,7 @@ class HomeMenu extends StatelessWidget { child: ScrollConfiguration( behavior: const ScrollBehavior().copyWith(scrollbars: false), child: BlocSelector>( - selector: (state) => state.apps.map((app) => MenuApp(app)).toList(), + selector: (state) => state.apps.map((app) => MenuApp(app, key: ValueKey(app.id))).toList(), builder: (context, menuItems) { return ReorderableListView.builder( itemCount: menuItems.length, @@ -128,7 +128,7 @@ class HomeMenu extends StatelessWidget { physics: StyledScrollPhysics(), itemBuilder: (BuildContext context, int index) { return ReorderableDragStartListener( - key: ValueKey(menuItems[index].hashCode), + key: ValueKey(menuItems[index].key), index: index, child: Padding( padding: EdgeInsets.symmetric(vertical: MenuAppSizes.appVPadding / 2), From 371c52022bf11f0ba1b97d6b7ab6504ad82f9f93 Mon Sep 17 00:00:00 2001 From: appflowy Date: Thu, 28 Apr 2022 16:44:35 +0800 Subject: [PATCH 6/8] fix: reorder view and field animation --- .../application/grid/grid_header_bloc.dart | 16 ++++++++++++++-- .../application/menu/menu_view_section_bloc.dart | 8 ++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/frontend/app_flowy/lib/workspace/application/grid/grid_header_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/grid_header_bloc.dart index 90007ba8c292a..2473bc607fd10 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/grid_header_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/grid_header_bloc.dart @@ -27,14 +27,26 @@ class GridHeaderBloc extends Bloc { emit(state.copyWith(fields: value.fields)); }, moveField: (_MoveField value) async { - final result = await _fieldService.moveField(value.field.id, value.fromIndex, value.toIndex); - result.fold((l) {}, (err) => Log.error(err)); + await _moveField(value, emit); }, ); }, ); } + Future _moveField(_MoveField value, Emitter emit) async { + final fields = List.from(state.fields); + fields.insert(value.toIndex, fields.removeAt(value.fromIndex)); + emit(state.copyWith(fields: fields)); + + final result = await _fieldService.moveField( + value.field.id, + value.fromIndex, + value.toIndex, + ); + result.fold((l) {}, (err) => Log.error(err)); + } + Future _startListening() async { fieldCache.addListener( onChanged: (fields) => add(GridHeaderEvent.didReceiveFieldUpdate(fields)), diff --git a/frontend/app_flowy/lib/workspace/application/menu/menu_view_section_bloc.dart b/frontend/app_flowy/lib/workspace/application/menu/menu_view_section_bloc.dart index 10f4058a97da6..c74472aa5d890 100644 --- a/frontend/app_flowy/lib/workspace/application/menu/menu_view_section_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/menu/menu_view_section_bloc.dart @@ -32,7 +32,7 @@ class ViewSectionBloc extends Bloc { emit(state.copyWith(views: value.views)); }, moveView: (_MoveView value) async { - await _moveView(value); + _moveView(value, emit); }, ); }); @@ -59,9 +59,13 @@ class ViewSectionBloc extends Bloc { } } - Future _moveView(_MoveView value) async { + Future _moveView(_MoveView value, Emitter emit) async { if (value.fromIndex < state.views.length) { final viewId = state.views[value.fromIndex].id; + final views = List.from(state.views); + views.insert(value.toIndex, views.removeAt(value.fromIndex)); + emit(state.copyWith(views: views)); + final result = await _appService.moveView( viewId: viewId, fromIndex: value.fromIndex, From 296013dcbf13c34d7870845c550a53ec3d2cb190 Mon Sep 17 00:00:00 2001 From: appflowy Date: Thu, 28 Apr 2022 16:45:33 +0800 Subject: [PATCH 7/8] chore: fix wanrings --- .../app_flowy/lib/workspace/presentation/home/menu/menu.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart b/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart index 4c71bba3b21a6..b888ab7631de0 100644 --- a/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart +++ b/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart @@ -8,7 +8,6 @@ import 'package:flowy_infra/size.dart'; import 'package:flowy_infra/theme.dart'; import 'package:flowy_infra_ui/style_widget/scrolling/styled_list.dart'; import 'package:flowy_infra_ui/widget/spacing.dart'; -import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart' show UserProfile; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; From 66cf0ca544928a85a031b5ddc45b36c2b7f5a61a Mon Sep 17 00:00:00 2001 From: appflowy Date: Thu, 28 Apr 2022 16:54:04 +0800 Subject: [PATCH 8/8] chore: refactor move field func --- .../src/client_grid/grid_meta_pad.rs | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/shared-lib/flowy-sync/src/client_grid/grid_meta_pad.rs b/shared-lib/flowy-sync/src/client_grid/grid_meta_pad.rs index d91265e896f2b..bda9e056ca9eb 100644 --- a/shared-lib/flowy-sync/src/client_grid/grid_meta_pad.rs +++ b/shared-lib/flowy-sync/src/client_grid/grid_meta_pad.rs @@ -6,6 +6,7 @@ use flowy_grid_data_model::entities::{ gen_grid_id, FieldChangesetParams, FieldMeta, FieldOrder, FieldType, GridBlockMeta, GridBlockMetaChangeset, GridMeta, }; +use lib_infra::util::move_vec_element; use lib_ot::core::{OperationTransformable, PlainTextAttributes, PlainTextDelta, PlainTextDeltaBuilder}; use std::collections::HashMap; use std::sync::Arc; @@ -208,20 +209,22 @@ impl GridMetaPad { pub fn move_field( &mut self, field_id: &str, - _from_index: usize, + from_index: usize, to_index: usize, ) -> CollaborateResult> { - self.modify_grid( - |grid_meta| match grid_meta.fields.iter().position(|field| field.id == field_id) { - None => Ok(None), - Some(index) => { - // debug_assert_eq!(index, from_index); - let field_meta = grid_meta.fields.remove(index); - grid_meta.fields.insert(to_index, field_meta); - Ok(Some(())) - } - }, - ) + self.modify_grid(|grid_meta| { + match move_vec_element( + &mut grid_meta.fields, + |field| field.id == field_id, + from_index, + to_index, + ) + .map_err(internal_error)? + { + true => Ok(Some(())), + false => Ok(None), + } + }) } pub fn contain_field(&self, field_id: &str) -> bool {