mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-07-25 02:54:00 +00:00
replace ViewSectionItem stateful with bloc
This commit is contained in:
@ -10,14 +10,14 @@ import 'package:dartz/dartz.dart';
|
|||||||
part 'menu_listen.freezed.dart';
|
part 'menu_listen.freezed.dart';
|
||||||
|
|
||||||
class MenuListenBloc extends Bloc<MenuListenEvent, MenuListenState> {
|
class MenuListenBloc extends Bloc<MenuListenEvent, MenuListenState> {
|
||||||
final IWorkspaceWatch watch;
|
final IWorkspaceListener listener;
|
||||||
MenuListenBloc(this.watch) : super(const MenuListenState.initial());
|
MenuListenBloc(this.listener) : super(const MenuListenState.initial());
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Stream<MenuListenState> mapEventToState(MenuListenEvent event) async* {
|
Stream<MenuListenState> mapEventToState(MenuListenEvent event) async* {
|
||||||
yield* event.map(
|
yield* event.map(
|
||||||
started: (_) async* {
|
started: (_) async* {
|
||||||
watch.startWatching(
|
listener.start(
|
||||||
addAppCallback: (appsOrFail) => _handleAppsOrFail(appsOrFail),
|
addAppCallback: (appsOrFail) => _handleAppsOrFail(appsOrFail),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -32,7 +32,7 @@ class MenuListenBloc extends Bloc<MenuListenEvent, MenuListenState> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> close() async {
|
Future<void> close() async {
|
||||||
await watch.stopWatching();
|
await listener.stop();
|
||||||
return super.close();
|
return super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:app_flowy/workspace/domain/view_edit.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
|
||||||
@ -12,32 +13,46 @@ class ViewBloc extends Bloc<ViewEvent, ViewState> {
|
|||||||
|
|
||||||
ViewBloc({
|
ViewBloc({
|
||||||
required this.iViewImpl,
|
required this.iViewImpl,
|
||||||
}) : super(ViewState.initial());
|
}) : super(ViewState.initial(iViewImpl.view));
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Stream<ViewState> mapEventToState(ViewEvent event) async* {
|
Stream<ViewState> mapEventToState(ViewEvent event) async* {
|
||||||
yield* event.map(initial: (_) async* {
|
yield* event.map(
|
||||||
yield state;
|
setIsSelected: (e) async* {
|
||||||
});
|
yield state.copyWith(isSelected: e.isSelected);
|
||||||
|
},
|
||||||
|
setIsEditing: (e) async* {
|
||||||
|
yield state.copyWith(isEditing: e.isEditing);
|
||||||
|
},
|
||||||
|
setAction: (e) async* {
|
||||||
|
yield state.copyWith(action: e.action);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
class ViewEvent with _$ViewEvent {
|
class ViewEvent with _$ViewEvent {
|
||||||
const factory ViewEvent.initial() = Initial;
|
const factory ViewEvent.setIsSelected(bool isSelected) = SetSelected;
|
||||||
|
const factory ViewEvent.setIsEditing(bool isEditing) = SetEditing;
|
||||||
|
const factory ViewEvent.setAction(Option<ViewAction> action) = SetAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
class ViewState with _$ViewState {
|
class ViewState with _$ViewState {
|
||||||
const factory ViewState({
|
const factory ViewState({
|
||||||
required bool isLoading,
|
required View view,
|
||||||
required Option<View> view,
|
required bool isSelected,
|
||||||
|
required bool isEditing,
|
||||||
|
required Option<ViewAction> action,
|
||||||
required Either<Unit, WorkspaceError> successOrFailure,
|
required Either<Unit, WorkspaceError> successOrFailure,
|
||||||
}) = _ViewState;
|
}) = _ViewState;
|
||||||
|
|
||||||
factory ViewState.initial() => ViewState(
|
factory ViewState.initial(View view) => ViewState(
|
||||||
isLoading: false,
|
view: view,
|
||||||
view: none(),
|
isSelected: false,
|
||||||
|
isEditing: false,
|
||||||
|
action: none(),
|
||||||
successOrFailure: left(unit),
|
successOrFailure: left(unit),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,22 @@ final _privateConstructorUsedError = UnsupportedError(
|
|||||||
class _$ViewEventTearOff {
|
class _$ViewEventTearOff {
|
||||||
const _$ViewEventTearOff();
|
const _$ViewEventTearOff();
|
||||||
|
|
||||||
Initial initial() {
|
SetSelected setIsSelected(bool isSelected) {
|
||||||
return const Initial();
|
return SetSelected(
|
||||||
|
isSelected,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetEditing setIsEditing(bool isEditing) {
|
||||||
|
return SetEditing(
|
||||||
|
isEditing,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetAction setAction(Option<ViewAction> action) {
|
||||||
|
return SetAction(
|
||||||
|
action,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,23 +42,31 @@ const $ViewEvent = _$ViewEventTearOff();
|
|||||||
mixin _$ViewEvent {
|
mixin _$ViewEvent {
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult when<TResult extends Object?>({
|
TResult when<TResult extends Object?>({
|
||||||
required TResult Function() initial,
|
required TResult Function(bool isSelected) setIsSelected,
|
||||||
|
required TResult Function(bool isEditing) setIsEditing,
|
||||||
|
required TResult Function(Option<ViewAction> action) setAction,
|
||||||
}) =>
|
}) =>
|
||||||
throw _privateConstructorUsedError;
|
throw _privateConstructorUsedError;
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult maybeWhen<TResult extends Object?>({
|
TResult maybeWhen<TResult extends Object?>({
|
||||||
TResult Function()? initial,
|
TResult Function(bool isSelected)? setIsSelected,
|
||||||
|
TResult Function(bool isEditing)? setIsEditing,
|
||||||
|
TResult Function(Option<ViewAction> action)? setAction,
|
||||||
required TResult orElse(),
|
required TResult orElse(),
|
||||||
}) =>
|
}) =>
|
||||||
throw _privateConstructorUsedError;
|
throw _privateConstructorUsedError;
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult map<TResult extends Object?>({
|
TResult map<TResult extends Object?>({
|
||||||
required TResult Function(Initial value) initial,
|
required TResult Function(SetSelected value) setIsSelected,
|
||||||
|
required TResult Function(SetEditing value) setIsEditing,
|
||||||
|
required TResult Function(SetAction value) setAction,
|
||||||
}) =>
|
}) =>
|
||||||
throw _privateConstructorUsedError;
|
throw _privateConstructorUsedError;
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult maybeMap<TResult extends Object?>({
|
TResult maybeMap<TResult extends Object?>({
|
||||||
TResult Function(Initial value)? initial,
|
TResult Function(SetSelected value)? setIsSelected,
|
||||||
|
TResult Function(SetEditing value)? setIsEditing,
|
||||||
|
TResult Function(SetAction value)? setAction,
|
||||||
required TResult orElse(),
|
required TResult orElse(),
|
||||||
}) =>
|
}) =>
|
||||||
throw _privateConstructorUsedError;
|
throw _privateConstructorUsedError;
|
||||||
@ -66,55 +88,87 @@ class _$ViewEventCopyWithImpl<$Res> implements $ViewEventCopyWith<$Res> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @nodoc
|
/// @nodoc
|
||||||
abstract class $InitialCopyWith<$Res> {
|
abstract class $SetSelectedCopyWith<$Res> {
|
||||||
factory $InitialCopyWith(Initial value, $Res Function(Initial) then) =
|
factory $SetSelectedCopyWith(
|
||||||
_$InitialCopyWithImpl<$Res>;
|
SetSelected value, $Res Function(SetSelected) then) =
|
||||||
|
_$SetSelectedCopyWithImpl<$Res>;
|
||||||
|
$Res call({bool isSelected});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @nodoc
|
/// @nodoc
|
||||||
class _$InitialCopyWithImpl<$Res> extends _$ViewEventCopyWithImpl<$Res>
|
class _$SetSelectedCopyWithImpl<$Res> extends _$ViewEventCopyWithImpl<$Res>
|
||||||
implements $InitialCopyWith<$Res> {
|
implements $SetSelectedCopyWith<$Res> {
|
||||||
_$InitialCopyWithImpl(Initial _value, $Res Function(Initial) _then)
|
_$SetSelectedCopyWithImpl(
|
||||||
: super(_value, (v) => _then(v as Initial));
|
SetSelected _value, $Res Function(SetSelected) _then)
|
||||||
|
: super(_value, (v) => _then(v as SetSelected));
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Initial get _value => super._value as Initial;
|
SetSelected get _value => super._value as SetSelected;
|
||||||
|
|
||||||
|
@override
|
||||||
|
$Res call({
|
||||||
|
Object? isSelected = freezed,
|
||||||
|
}) {
|
||||||
|
return _then(SetSelected(
|
||||||
|
isSelected == freezed
|
||||||
|
? _value.isSelected
|
||||||
|
: isSelected // ignore: cast_nullable_to_non_nullable
|
||||||
|
as bool,
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @nodoc
|
/// @nodoc
|
||||||
|
|
||||||
class _$Initial implements Initial {
|
class _$SetSelected implements SetSelected {
|
||||||
const _$Initial();
|
const _$SetSelected(this.isSelected);
|
||||||
|
|
||||||
|
@override
|
||||||
|
final bool isSelected;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'ViewEvent.initial()';
|
return 'ViewEvent.setIsSelected(isSelected: $isSelected)';
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(dynamic other) {
|
bool operator ==(dynamic other) {
|
||||||
return identical(this, other) || (other is Initial);
|
return identical(this, other) ||
|
||||||
|
(other is SetSelected &&
|
||||||
|
(identical(other.isSelected, isSelected) ||
|
||||||
|
const DeepCollectionEquality()
|
||||||
|
.equals(other.isSelected, isSelected)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get hashCode => runtimeType.hashCode;
|
int get hashCode =>
|
||||||
|
runtimeType.hashCode ^ const DeepCollectionEquality().hash(isSelected);
|
||||||
|
|
||||||
|
@JsonKey(ignore: true)
|
||||||
|
@override
|
||||||
|
$SetSelectedCopyWith<SetSelected> get copyWith =>
|
||||||
|
_$SetSelectedCopyWithImpl<SetSelected>(this, _$identity);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult when<TResult extends Object?>({
|
TResult when<TResult extends Object?>({
|
||||||
required TResult Function() initial,
|
required TResult Function(bool isSelected) setIsSelected,
|
||||||
|
required TResult Function(bool isEditing) setIsEditing,
|
||||||
|
required TResult Function(Option<ViewAction> action) setAction,
|
||||||
}) {
|
}) {
|
||||||
return initial();
|
return setIsSelected(isSelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult maybeWhen<TResult extends Object?>({
|
TResult maybeWhen<TResult extends Object?>({
|
||||||
TResult Function()? initial,
|
TResult Function(bool isSelected)? setIsSelected,
|
||||||
|
TResult Function(bool isEditing)? setIsEditing,
|
||||||
|
TResult Function(Option<ViewAction> action)? setAction,
|
||||||
required TResult orElse(),
|
required TResult orElse(),
|
||||||
}) {
|
}) {
|
||||||
if (initial != null) {
|
if (setIsSelected != null) {
|
||||||
return initial();
|
return setIsSelected(isSelected);
|
||||||
}
|
}
|
||||||
return orElse();
|
return orElse();
|
||||||
}
|
}
|
||||||
@ -122,26 +176,271 @@ class _$Initial implements Initial {
|
|||||||
@override
|
@override
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult map<TResult extends Object?>({
|
TResult map<TResult extends Object?>({
|
||||||
required TResult Function(Initial value) initial,
|
required TResult Function(SetSelected value) setIsSelected,
|
||||||
|
required TResult Function(SetEditing value) setIsEditing,
|
||||||
|
required TResult Function(SetAction value) setAction,
|
||||||
}) {
|
}) {
|
||||||
return initial(this);
|
return setIsSelected(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult maybeMap<TResult extends Object?>({
|
TResult maybeMap<TResult extends Object?>({
|
||||||
TResult Function(Initial value)? initial,
|
TResult Function(SetSelected value)? setIsSelected,
|
||||||
|
TResult Function(SetEditing value)? setIsEditing,
|
||||||
|
TResult Function(SetAction value)? setAction,
|
||||||
required TResult orElse(),
|
required TResult orElse(),
|
||||||
}) {
|
}) {
|
||||||
if (initial != null) {
|
if (setIsSelected != null) {
|
||||||
return initial(this);
|
return setIsSelected(this);
|
||||||
}
|
}
|
||||||
return orElse();
|
return orElse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class Initial implements ViewEvent {
|
abstract class SetSelected implements ViewEvent {
|
||||||
const factory Initial() = _$Initial;
|
const factory SetSelected(bool isSelected) = _$SetSelected;
|
||||||
|
|
||||||
|
bool get isSelected => throw _privateConstructorUsedError;
|
||||||
|
@JsonKey(ignore: true)
|
||||||
|
$SetSelectedCopyWith<SetSelected> get copyWith =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
abstract class $SetEditingCopyWith<$Res> {
|
||||||
|
factory $SetEditingCopyWith(
|
||||||
|
SetEditing value, $Res Function(SetEditing) then) =
|
||||||
|
_$SetEditingCopyWithImpl<$Res>;
|
||||||
|
$Res call({bool isEditing});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class _$SetEditingCopyWithImpl<$Res> extends _$ViewEventCopyWithImpl<$Res>
|
||||||
|
implements $SetEditingCopyWith<$Res> {
|
||||||
|
_$SetEditingCopyWithImpl(SetEditing _value, $Res Function(SetEditing) _then)
|
||||||
|
: super(_value, (v) => _then(v as SetEditing));
|
||||||
|
|
||||||
|
@override
|
||||||
|
SetEditing get _value => super._value as SetEditing;
|
||||||
|
|
||||||
|
@override
|
||||||
|
$Res call({
|
||||||
|
Object? isEditing = freezed,
|
||||||
|
}) {
|
||||||
|
return _then(SetEditing(
|
||||||
|
isEditing == freezed
|
||||||
|
? _value.isEditing
|
||||||
|
: isEditing // ignore: cast_nullable_to_non_nullable
|
||||||
|
as bool,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
|
||||||
|
class _$SetEditing implements SetEditing {
|
||||||
|
const _$SetEditing(this.isEditing);
|
||||||
|
|
||||||
|
@override
|
||||||
|
final bool isEditing;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'ViewEvent.setIsEditing(isEditing: $isEditing)';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(dynamic other) {
|
||||||
|
return identical(this, other) ||
|
||||||
|
(other is SetEditing &&
|
||||||
|
(identical(other.isEditing, isEditing) ||
|
||||||
|
const DeepCollectionEquality()
|
||||||
|
.equals(other.isEditing, isEditing)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode =>
|
||||||
|
runtimeType.hashCode ^ const DeepCollectionEquality().hash(isEditing);
|
||||||
|
|
||||||
|
@JsonKey(ignore: true)
|
||||||
|
@override
|
||||||
|
$SetEditingCopyWith<SetEditing> get copyWith =>
|
||||||
|
_$SetEditingCopyWithImpl<SetEditing>(this, _$identity);
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult when<TResult extends Object?>({
|
||||||
|
required TResult Function(bool isSelected) setIsSelected,
|
||||||
|
required TResult Function(bool isEditing) setIsEditing,
|
||||||
|
required TResult Function(Option<ViewAction> action) setAction,
|
||||||
|
}) {
|
||||||
|
return setIsEditing(isEditing);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult maybeWhen<TResult extends Object?>({
|
||||||
|
TResult Function(bool isSelected)? setIsSelected,
|
||||||
|
TResult Function(bool isEditing)? setIsEditing,
|
||||||
|
TResult Function(Option<ViewAction> action)? setAction,
|
||||||
|
required TResult orElse(),
|
||||||
|
}) {
|
||||||
|
if (setIsEditing != null) {
|
||||||
|
return setIsEditing(isEditing);
|
||||||
|
}
|
||||||
|
return orElse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult map<TResult extends Object?>({
|
||||||
|
required TResult Function(SetSelected value) setIsSelected,
|
||||||
|
required TResult Function(SetEditing value) setIsEditing,
|
||||||
|
required TResult Function(SetAction value) setAction,
|
||||||
|
}) {
|
||||||
|
return setIsEditing(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult maybeMap<TResult extends Object?>({
|
||||||
|
TResult Function(SetSelected value)? setIsSelected,
|
||||||
|
TResult Function(SetEditing value)? setIsEditing,
|
||||||
|
TResult Function(SetAction value)? setAction,
|
||||||
|
required TResult orElse(),
|
||||||
|
}) {
|
||||||
|
if (setIsEditing != null) {
|
||||||
|
return setIsEditing(this);
|
||||||
|
}
|
||||||
|
return orElse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class SetEditing implements ViewEvent {
|
||||||
|
const factory SetEditing(bool isEditing) = _$SetEditing;
|
||||||
|
|
||||||
|
bool get isEditing => throw _privateConstructorUsedError;
|
||||||
|
@JsonKey(ignore: true)
|
||||||
|
$SetEditingCopyWith<SetEditing> get copyWith =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
abstract class $SetActionCopyWith<$Res> {
|
||||||
|
factory $SetActionCopyWith(SetAction value, $Res Function(SetAction) then) =
|
||||||
|
_$SetActionCopyWithImpl<$Res>;
|
||||||
|
$Res call({Option<ViewAction> action});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class _$SetActionCopyWithImpl<$Res> extends _$ViewEventCopyWithImpl<$Res>
|
||||||
|
implements $SetActionCopyWith<$Res> {
|
||||||
|
_$SetActionCopyWithImpl(SetAction _value, $Res Function(SetAction) _then)
|
||||||
|
: super(_value, (v) => _then(v as SetAction));
|
||||||
|
|
||||||
|
@override
|
||||||
|
SetAction get _value => super._value as SetAction;
|
||||||
|
|
||||||
|
@override
|
||||||
|
$Res call({
|
||||||
|
Object? action = freezed,
|
||||||
|
}) {
|
||||||
|
return _then(SetAction(
|
||||||
|
action == freezed
|
||||||
|
? _value.action
|
||||||
|
: action // ignore: cast_nullable_to_non_nullable
|
||||||
|
as Option<ViewAction>,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
|
||||||
|
class _$SetAction implements SetAction {
|
||||||
|
const _$SetAction(this.action);
|
||||||
|
|
||||||
|
@override
|
||||||
|
final Option<ViewAction> action;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'ViewEvent.setAction(action: $action)';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(dynamic other) {
|
||||||
|
return identical(this, other) ||
|
||||||
|
(other is SetAction &&
|
||||||
|
(identical(other.action, action) ||
|
||||||
|
const DeepCollectionEquality().equals(other.action, action)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode =>
|
||||||
|
runtimeType.hashCode ^ const DeepCollectionEquality().hash(action);
|
||||||
|
|
||||||
|
@JsonKey(ignore: true)
|
||||||
|
@override
|
||||||
|
$SetActionCopyWith<SetAction> get copyWith =>
|
||||||
|
_$SetActionCopyWithImpl<SetAction>(this, _$identity);
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult when<TResult extends Object?>({
|
||||||
|
required TResult Function(bool isSelected) setIsSelected,
|
||||||
|
required TResult Function(bool isEditing) setIsEditing,
|
||||||
|
required TResult Function(Option<ViewAction> action) setAction,
|
||||||
|
}) {
|
||||||
|
return setAction(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult maybeWhen<TResult extends Object?>({
|
||||||
|
TResult Function(bool isSelected)? setIsSelected,
|
||||||
|
TResult Function(bool isEditing)? setIsEditing,
|
||||||
|
TResult Function(Option<ViewAction> action)? setAction,
|
||||||
|
required TResult orElse(),
|
||||||
|
}) {
|
||||||
|
if (setAction != null) {
|
||||||
|
return setAction(action);
|
||||||
|
}
|
||||||
|
return orElse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult map<TResult extends Object?>({
|
||||||
|
required TResult Function(SetSelected value) setIsSelected,
|
||||||
|
required TResult Function(SetEditing value) setIsEditing,
|
||||||
|
required TResult Function(SetAction value) setAction,
|
||||||
|
}) {
|
||||||
|
return setAction(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult maybeMap<TResult extends Object?>({
|
||||||
|
TResult Function(SetSelected value)? setIsSelected,
|
||||||
|
TResult Function(SetEditing value)? setIsEditing,
|
||||||
|
TResult Function(SetAction value)? setAction,
|
||||||
|
required TResult orElse(),
|
||||||
|
}) {
|
||||||
|
if (setAction != null) {
|
||||||
|
return setAction(this);
|
||||||
|
}
|
||||||
|
return orElse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class SetAction implements ViewEvent {
|
||||||
|
const factory SetAction(Option<ViewAction> action) = _$SetAction;
|
||||||
|
|
||||||
|
Option<ViewAction> get action => throw _privateConstructorUsedError;
|
||||||
|
@JsonKey(ignore: true)
|
||||||
|
$SetActionCopyWith<SetAction> get copyWith =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @nodoc
|
/// @nodoc
|
||||||
@ -149,12 +448,16 @@ class _$ViewStateTearOff {
|
|||||||
const _$ViewStateTearOff();
|
const _$ViewStateTearOff();
|
||||||
|
|
||||||
_ViewState call(
|
_ViewState call(
|
||||||
{required bool isLoading,
|
{required View view,
|
||||||
required Option<View> view,
|
required bool isSelected,
|
||||||
|
required bool isEditing,
|
||||||
|
required Option<ViewAction> action,
|
||||||
required Either<Unit, WorkspaceError> successOrFailure}) {
|
required Either<Unit, WorkspaceError> successOrFailure}) {
|
||||||
return _ViewState(
|
return _ViewState(
|
||||||
isLoading: isLoading,
|
|
||||||
view: view,
|
view: view,
|
||||||
|
isSelected: isSelected,
|
||||||
|
isEditing: isEditing,
|
||||||
|
action: action,
|
||||||
successOrFailure: successOrFailure,
|
successOrFailure: successOrFailure,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -165,8 +468,10 @@ const $ViewState = _$ViewStateTearOff();
|
|||||||
|
|
||||||
/// @nodoc
|
/// @nodoc
|
||||||
mixin _$ViewState {
|
mixin _$ViewState {
|
||||||
bool get isLoading => throw _privateConstructorUsedError;
|
View get view => throw _privateConstructorUsedError;
|
||||||
Option<View> get view => throw _privateConstructorUsedError;
|
bool get isSelected => throw _privateConstructorUsedError;
|
||||||
|
bool get isEditing => throw _privateConstructorUsedError;
|
||||||
|
Option<ViewAction> get action => throw _privateConstructorUsedError;
|
||||||
Either<Unit, WorkspaceError> get successOrFailure =>
|
Either<Unit, WorkspaceError> get successOrFailure =>
|
||||||
throw _privateConstructorUsedError;
|
throw _privateConstructorUsedError;
|
||||||
|
|
||||||
@ -180,8 +485,10 @@ abstract class $ViewStateCopyWith<$Res> {
|
|||||||
factory $ViewStateCopyWith(ViewState value, $Res Function(ViewState) then) =
|
factory $ViewStateCopyWith(ViewState value, $Res Function(ViewState) then) =
|
||||||
_$ViewStateCopyWithImpl<$Res>;
|
_$ViewStateCopyWithImpl<$Res>;
|
||||||
$Res call(
|
$Res call(
|
||||||
{bool isLoading,
|
{View view,
|
||||||
Option<View> view,
|
bool isSelected,
|
||||||
|
bool isEditing,
|
||||||
|
Option<ViewAction> action,
|
||||||
Either<Unit, WorkspaceError> successOrFailure});
|
Either<Unit, WorkspaceError> successOrFailure});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,19 +502,29 @@ class _$ViewStateCopyWithImpl<$Res> implements $ViewStateCopyWith<$Res> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
$Res call({
|
$Res call({
|
||||||
Object? isLoading = freezed,
|
|
||||||
Object? view = freezed,
|
Object? view = freezed,
|
||||||
|
Object? isSelected = freezed,
|
||||||
|
Object? isEditing = freezed,
|
||||||
|
Object? action = freezed,
|
||||||
Object? successOrFailure = freezed,
|
Object? successOrFailure = freezed,
|
||||||
}) {
|
}) {
|
||||||
return _then(_value.copyWith(
|
return _then(_value.copyWith(
|
||||||
isLoading: isLoading == freezed
|
|
||||||
? _value.isLoading
|
|
||||||
: isLoading // ignore: cast_nullable_to_non_nullable
|
|
||||||
as bool,
|
|
||||||
view: view == freezed
|
view: view == freezed
|
||||||
? _value.view
|
? _value.view
|
||||||
: view // ignore: cast_nullable_to_non_nullable
|
: view // ignore: cast_nullable_to_non_nullable
|
||||||
as Option<View>,
|
as View,
|
||||||
|
isSelected: isSelected == freezed
|
||||||
|
? _value.isSelected
|
||||||
|
: isSelected // ignore: cast_nullable_to_non_nullable
|
||||||
|
as bool,
|
||||||
|
isEditing: isEditing == freezed
|
||||||
|
? _value.isEditing
|
||||||
|
: isEditing // ignore: cast_nullable_to_non_nullable
|
||||||
|
as bool,
|
||||||
|
action: action == freezed
|
||||||
|
? _value.action
|
||||||
|
: action // ignore: cast_nullable_to_non_nullable
|
||||||
|
as Option<ViewAction>,
|
||||||
successOrFailure: successOrFailure == freezed
|
successOrFailure: successOrFailure == freezed
|
||||||
? _value.successOrFailure
|
? _value.successOrFailure
|
||||||
: successOrFailure // ignore: cast_nullable_to_non_nullable
|
: successOrFailure // ignore: cast_nullable_to_non_nullable
|
||||||
@ -223,8 +540,10 @@ abstract class _$ViewStateCopyWith<$Res> implements $ViewStateCopyWith<$Res> {
|
|||||||
__$ViewStateCopyWithImpl<$Res>;
|
__$ViewStateCopyWithImpl<$Res>;
|
||||||
@override
|
@override
|
||||||
$Res call(
|
$Res call(
|
||||||
{bool isLoading,
|
{View view,
|
||||||
Option<View> view,
|
bool isSelected,
|
||||||
|
bool isEditing,
|
||||||
|
Option<ViewAction> action,
|
||||||
Either<Unit, WorkspaceError> successOrFailure});
|
Either<Unit, WorkspaceError> successOrFailure});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,19 +558,29 @@ class __$ViewStateCopyWithImpl<$Res> extends _$ViewStateCopyWithImpl<$Res>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
$Res call({
|
$Res call({
|
||||||
Object? isLoading = freezed,
|
|
||||||
Object? view = freezed,
|
Object? view = freezed,
|
||||||
|
Object? isSelected = freezed,
|
||||||
|
Object? isEditing = freezed,
|
||||||
|
Object? action = freezed,
|
||||||
Object? successOrFailure = freezed,
|
Object? successOrFailure = freezed,
|
||||||
}) {
|
}) {
|
||||||
return _then(_ViewState(
|
return _then(_ViewState(
|
||||||
isLoading: isLoading == freezed
|
|
||||||
? _value.isLoading
|
|
||||||
: isLoading // ignore: cast_nullable_to_non_nullable
|
|
||||||
as bool,
|
|
||||||
view: view == freezed
|
view: view == freezed
|
||||||
? _value.view
|
? _value.view
|
||||||
: view // ignore: cast_nullable_to_non_nullable
|
: view // ignore: cast_nullable_to_non_nullable
|
||||||
as Option<View>,
|
as View,
|
||||||
|
isSelected: isSelected == freezed
|
||||||
|
? _value.isSelected
|
||||||
|
: isSelected // ignore: cast_nullable_to_non_nullable
|
||||||
|
as bool,
|
||||||
|
isEditing: isEditing == freezed
|
||||||
|
? _value.isEditing
|
||||||
|
: isEditing // ignore: cast_nullable_to_non_nullable
|
||||||
|
as bool,
|
||||||
|
action: action == freezed
|
||||||
|
? _value.action
|
||||||
|
: action // ignore: cast_nullable_to_non_nullable
|
||||||
|
as Option<ViewAction>,
|
||||||
successOrFailure: successOrFailure == freezed
|
successOrFailure: successOrFailure == freezed
|
||||||
? _value.successOrFailure
|
? _value.successOrFailure
|
||||||
: successOrFailure // ignore: cast_nullable_to_non_nullable
|
: successOrFailure // ignore: cast_nullable_to_non_nullable
|
||||||
@ -264,31 +593,42 @@ class __$ViewStateCopyWithImpl<$Res> extends _$ViewStateCopyWithImpl<$Res>
|
|||||||
|
|
||||||
class _$_ViewState implements _ViewState {
|
class _$_ViewState implements _ViewState {
|
||||||
const _$_ViewState(
|
const _$_ViewState(
|
||||||
{required this.isLoading,
|
{required this.view,
|
||||||
required this.view,
|
required this.isSelected,
|
||||||
|
required this.isEditing,
|
||||||
|
required this.action,
|
||||||
required this.successOrFailure});
|
required this.successOrFailure});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final bool isLoading;
|
final View view;
|
||||||
@override
|
@override
|
||||||
final Option<View> view;
|
final bool isSelected;
|
||||||
|
@override
|
||||||
|
final bool isEditing;
|
||||||
|
@override
|
||||||
|
final Option<ViewAction> action;
|
||||||
@override
|
@override
|
||||||
final Either<Unit, WorkspaceError> successOrFailure;
|
final Either<Unit, WorkspaceError> successOrFailure;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'ViewState(isLoading: $isLoading, view: $view, successOrFailure: $successOrFailure)';
|
return 'ViewState(view: $view, isSelected: $isSelected, isEditing: $isEditing, action: $action, successOrFailure: $successOrFailure)';
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(dynamic other) {
|
bool operator ==(dynamic other) {
|
||||||
return identical(this, other) ||
|
return identical(this, other) ||
|
||||||
(other is _ViewState &&
|
(other is _ViewState &&
|
||||||
(identical(other.isLoading, isLoading) ||
|
|
||||||
const DeepCollectionEquality()
|
|
||||||
.equals(other.isLoading, isLoading)) &&
|
|
||||||
(identical(other.view, view) ||
|
(identical(other.view, view) ||
|
||||||
const DeepCollectionEquality().equals(other.view, view)) &&
|
const DeepCollectionEquality().equals(other.view, view)) &&
|
||||||
|
(identical(other.isSelected, isSelected) ||
|
||||||
|
const DeepCollectionEquality()
|
||||||
|
.equals(other.isSelected, isSelected)) &&
|
||||||
|
(identical(other.isEditing, isEditing) ||
|
||||||
|
const DeepCollectionEquality()
|
||||||
|
.equals(other.isEditing, isEditing)) &&
|
||||||
|
(identical(other.action, action) ||
|
||||||
|
const DeepCollectionEquality().equals(other.action, action)) &&
|
||||||
(identical(other.successOrFailure, successOrFailure) ||
|
(identical(other.successOrFailure, successOrFailure) ||
|
||||||
const DeepCollectionEquality()
|
const DeepCollectionEquality()
|
||||||
.equals(other.successOrFailure, successOrFailure)));
|
.equals(other.successOrFailure, successOrFailure)));
|
||||||
@ -297,8 +637,10 @@ class _$_ViewState implements _ViewState {
|
|||||||
@override
|
@override
|
||||||
int get hashCode =>
|
int get hashCode =>
|
||||||
runtimeType.hashCode ^
|
runtimeType.hashCode ^
|
||||||
const DeepCollectionEquality().hash(isLoading) ^
|
|
||||||
const DeepCollectionEquality().hash(view) ^
|
const DeepCollectionEquality().hash(view) ^
|
||||||
|
const DeepCollectionEquality().hash(isSelected) ^
|
||||||
|
const DeepCollectionEquality().hash(isEditing) ^
|
||||||
|
const DeepCollectionEquality().hash(action) ^
|
||||||
const DeepCollectionEquality().hash(successOrFailure);
|
const DeepCollectionEquality().hash(successOrFailure);
|
||||||
|
|
||||||
@JsonKey(ignore: true)
|
@JsonKey(ignore: true)
|
||||||
@ -309,14 +651,20 @@ class _$_ViewState implements _ViewState {
|
|||||||
|
|
||||||
abstract class _ViewState implements ViewState {
|
abstract class _ViewState implements ViewState {
|
||||||
const factory _ViewState(
|
const factory _ViewState(
|
||||||
{required bool isLoading,
|
{required View view,
|
||||||
required Option<View> view,
|
required bool isSelected,
|
||||||
|
required bool isEditing,
|
||||||
|
required Option<ViewAction> action,
|
||||||
required Either<Unit, WorkspaceError> successOrFailure}) = _$_ViewState;
|
required Either<Unit, WorkspaceError> successOrFailure}) = _$_ViewState;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get isLoading => throw _privateConstructorUsedError;
|
View get view => throw _privateConstructorUsedError;
|
||||||
@override
|
@override
|
||||||
Option<View> get view => throw _privateConstructorUsedError;
|
bool get isSelected => throw _privateConstructorUsedError;
|
||||||
|
@override
|
||||||
|
bool get isEditing => throw _privateConstructorUsedError;
|
||||||
|
@override
|
||||||
|
Option<ViewAction> get action => throw _privateConstructorUsedError;
|
||||||
@override
|
@override
|
||||||
Either<Unit, WorkspaceError> get successOrFailure =>
|
Either<Unit, WorkspaceError> get successOrFailure =>
|
||||||
throw _privateConstructorUsedError;
|
throw _privateConstructorUsedError;
|
||||||
|
43
app_flowy/lib/workspace/application/view/view_edit_bloc.dart
Normal file
43
app_flowy/lib/workspace/application/view/view_edit_bloc.dart
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import 'package:dartz/dartz.dart';
|
||||||
|
import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';
|
||||||
|
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||||
|
import 'package:app_flowy/workspace/domain/i_view.dart';
|
||||||
|
|
||||||
|
part 'view_edit_bloc.freezed.dart';
|
||||||
|
|
||||||
|
class ViewEditBloc extends Bloc<ViewEditEvent, ViewEditState> {
|
||||||
|
final IView iViewImpl;
|
||||||
|
|
||||||
|
ViewEditBloc({
|
||||||
|
required this.iViewImpl,
|
||||||
|
}) : super(ViewEditState.initial());
|
||||||
|
|
||||||
|
@override
|
||||||
|
Stream<ViewEditState> mapEventToState(ViewEditEvent event) async* {
|
||||||
|
yield* event.map(initial: (_) async* {
|
||||||
|
yield state;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@freezed
|
||||||
|
class ViewEditEvent with _$ViewEditEvent {
|
||||||
|
const factory ViewEditEvent.initial() = Initial;
|
||||||
|
}
|
||||||
|
|
||||||
|
@freezed
|
||||||
|
class ViewEditState with _$ViewEditState {
|
||||||
|
const factory ViewEditState({
|
||||||
|
required bool isLoading,
|
||||||
|
required Option<View> view,
|
||||||
|
required Either<Unit, WorkspaceError> successOrFailure,
|
||||||
|
}) = _ViewState;
|
||||||
|
|
||||||
|
factory ViewEditState.initial() => ViewEditState(
|
||||||
|
isLoading: false,
|
||||||
|
view: none(),
|
||||||
|
successOrFailure: left(unit),
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,332 @@
|
|||||||
|
// 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 'view_edit_bloc.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// FreezedGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
T _$identity<T>(T value) => value;
|
||||||
|
|
||||||
|
final _privateConstructorUsedError = UnsupportedError(
|
||||||
|
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class _$ViewEditEventTearOff {
|
||||||
|
const _$ViewEditEventTearOff();
|
||||||
|
|
||||||
|
Initial initial() {
|
||||||
|
return const Initial();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
const $ViewEditEvent = _$ViewEditEventTearOff();
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
mixin _$ViewEditEvent {
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult when<TResult extends Object?>({
|
||||||
|
required TResult Function() initial,
|
||||||
|
}) =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult maybeWhen<TResult extends Object?>({
|
||||||
|
TResult Function()? initial,
|
||||||
|
required TResult orElse(),
|
||||||
|
}) =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult map<TResult extends Object?>({
|
||||||
|
required TResult Function(Initial value) initial,
|
||||||
|
}) =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult maybeMap<TResult extends Object?>({
|
||||||
|
TResult Function(Initial value)? initial,
|
||||||
|
required TResult orElse(),
|
||||||
|
}) =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
abstract class $ViewEditEventCopyWith<$Res> {
|
||||||
|
factory $ViewEditEventCopyWith(
|
||||||
|
ViewEditEvent value, $Res Function(ViewEditEvent) then) =
|
||||||
|
_$ViewEditEventCopyWithImpl<$Res>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class _$ViewEditEventCopyWithImpl<$Res>
|
||||||
|
implements $ViewEditEventCopyWith<$Res> {
|
||||||
|
_$ViewEditEventCopyWithImpl(this._value, this._then);
|
||||||
|
|
||||||
|
final ViewEditEvent _value;
|
||||||
|
// ignore: unused_field
|
||||||
|
final $Res Function(ViewEditEvent) _then;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
abstract class $InitialCopyWith<$Res> {
|
||||||
|
factory $InitialCopyWith(Initial value, $Res Function(Initial) then) =
|
||||||
|
_$InitialCopyWithImpl<$Res>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class _$InitialCopyWithImpl<$Res> extends _$ViewEditEventCopyWithImpl<$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 'ViewEditEvent.initial()';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(dynamic other) {
|
||||||
|
return identical(this, other) || (other is Initial);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => runtimeType.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult when<TResult extends Object?>({
|
||||||
|
required TResult Function() initial,
|
||||||
|
}) {
|
||||||
|
return initial();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult maybeWhen<TResult extends Object?>({
|
||||||
|
TResult Function()? initial,
|
||||||
|
required TResult orElse(),
|
||||||
|
}) {
|
||||||
|
if (initial != null) {
|
||||||
|
return initial();
|
||||||
|
}
|
||||||
|
return orElse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult map<TResult extends Object?>({
|
||||||
|
required TResult Function(Initial value) initial,
|
||||||
|
}) {
|
||||||
|
return initial(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult maybeMap<TResult extends Object?>({
|
||||||
|
TResult Function(Initial value)? initial,
|
||||||
|
required TResult orElse(),
|
||||||
|
}) {
|
||||||
|
if (initial != null) {
|
||||||
|
return initial(this);
|
||||||
|
}
|
||||||
|
return orElse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class Initial implements ViewEditEvent {
|
||||||
|
const factory Initial() = _$Initial;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class _$ViewEditStateTearOff {
|
||||||
|
const _$ViewEditStateTearOff();
|
||||||
|
|
||||||
|
_ViewState call(
|
||||||
|
{required bool isLoading,
|
||||||
|
required Option<View> view,
|
||||||
|
required Either<Unit, WorkspaceError> successOrFailure}) {
|
||||||
|
return _ViewState(
|
||||||
|
isLoading: isLoading,
|
||||||
|
view: view,
|
||||||
|
successOrFailure: successOrFailure,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
const $ViewEditState = _$ViewEditStateTearOff();
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
mixin _$ViewEditState {
|
||||||
|
bool get isLoading => throw _privateConstructorUsedError;
|
||||||
|
Option<View> get view => throw _privateConstructorUsedError;
|
||||||
|
Either<Unit, WorkspaceError> get successOrFailure =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
|
||||||
|
@JsonKey(ignore: true)
|
||||||
|
$ViewEditStateCopyWith<ViewEditState> get copyWith =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
abstract class $ViewEditStateCopyWith<$Res> {
|
||||||
|
factory $ViewEditStateCopyWith(
|
||||||
|
ViewEditState value, $Res Function(ViewEditState) then) =
|
||||||
|
_$ViewEditStateCopyWithImpl<$Res>;
|
||||||
|
$Res call(
|
||||||
|
{bool isLoading,
|
||||||
|
Option<View> view,
|
||||||
|
Either<Unit, WorkspaceError> successOrFailure});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class _$ViewEditStateCopyWithImpl<$Res>
|
||||||
|
implements $ViewEditStateCopyWith<$Res> {
|
||||||
|
_$ViewEditStateCopyWithImpl(this._value, this._then);
|
||||||
|
|
||||||
|
final ViewEditState _value;
|
||||||
|
// ignore: unused_field
|
||||||
|
final $Res Function(ViewEditState) _then;
|
||||||
|
|
||||||
|
@override
|
||||||
|
$Res call({
|
||||||
|
Object? isLoading = freezed,
|
||||||
|
Object? view = freezed,
|
||||||
|
Object? successOrFailure = freezed,
|
||||||
|
}) {
|
||||||
|
return _then(_value.copyWith(
|
||||||
|
isLoading: isLoading == freezed
|
||||||
|
? _value.isLoading
|
||||||
|
: isLoading // ignore: cast_nullable_to_non_nullable
|
||||||
|
as bool,
|
||||||
|
view: view == freezed
|
||||||
|
? _value.view
|
||||||
|
: view // ignore: cast_nullable_to_non_nullable
|
||||||
|
as Option<View>,
|
||||||
|
successOrFailure: successOrFailure == freezed
|
||||||
|
? _value.successOrFailure
|
||||||
|
: successOrFailure // ignore: cast_nullable_to_non_nullable
|
||||||
|
as Either<Unit, WorkspaceError>,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
abstract class _$ViewStateCopyWith<$Res>
|
||||||
|
implements $ViewEditStateCopyWith<$Res> {
|
||||||
|
factory _$ViewStateCopyWith(
|
||||||
|
_ViewState value, $Res Function(_ViewState) then) =
|
||||||
|
__$ViewStateCopyWithImpl<$Res>;
|
||||||
|
@override
|
||||||
|
$Res call(
|
||||||
|
{bool isLoading,
|
||||||
|
Option<View> view,
|
||||||
|
Either<Unit, WorkspaceError> successOrFailure});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class __$ViewStateCopyWithImpl<$Res> extends _$ViewEditStateCopyWithImpl<$Res>
|
||||||
|
implements _$ViewStateCopyWith<$Res> {
|
||||||
|
__$ViewStateCopyWithImpl(_ViewState _value, $Res Function(_ViewState) _then)
|
||||||
|
: super(_value, (v) => _then(v as _ViewState));
|
||||||
|
|
||||||
|
@override
|
||||||
|
_ViewState get _value => super._value as _ViewState;
|
||||||
|
|
||||||
|
@override
|
||||||
|
$Res call({
|
||||||
|
Object? isLoading = freezed,
|
||||||
|
Object? view = freezed,
|
||||||
|
Object? successOrFailure = freezed,
|
||||||
|
}) {
|
||||||
|
return _then(_ViewState(
|
||||||
|
isLoading: isLoading == freezed
|
||||||
|
? _value.isLoading
|
||||||
|
: isLoading // ignore: cast_nullable_to_non_nullable
|
||||||
|
as bool,
|
||||||
|
view: view == freezed
|
||||||
|
? _value.view
|
||||||
|
: view // ignore: cast_nullable_to_non_nullable
|
||||||
|
as Option<View>,
|
||||||
|
successOrFailure: successOrFailure == freezed
|
||||||
|
? _value.successOrFailure
|
||||||
|
: successOrFailure // ignore: cast_nullable_to_non_nullable
|
||||||
|
as Either<Unit, WorkspaceError>,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
|
||||||
|
class _$_ViewState implements _ViewState {
|
||||||
|
const _$_ViewState(
|
||||||
|
{required this.isLoading,
|
||||||
|
required this.view,
|
||||||
|
required this.successOrFailure});
|
||||||
|
|
||||||
|
@override
|
||||||
|
final bool isLoading;
|
||||||
|
@override
|
||||||
|
final Option<View> view;
|
||||||
|
@override
|
||||||
|
final Either<Unit, WorkspaceError> successOrFailure;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'ViewEditState(isLoading: $isLoading, view: $view, successOrFailure: $successOrFailure)';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(dynamic other) {
|
||||||
|
return identical(this, other) ||
|
||||||
|
(other is _ViewState &&
|
||||||
|
(identical(other.isLoading, isLoading) ||
|
||||||
|
const DeepCollectionEquality()
|
||||||
|
.equals(other.isLoading, isLoading)) &&
|
||||||
|
(identical(other.view, view) ||
|
||||||
|
const DeepCollectionEquality().equals(other.view, view)) &&
|
||||||
|
(identical(other.successOrFailure, successOrFailure) ||
|
||||||
|
const DeepCollectionEquality()
|
||||||
|
.equals(other.successOrFailure, successOrFailure)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode =>
|
||||||
|
runtimeType.hashCode ^
|
||||||
|
const DeepCollectionEquality().hash(isLoading) ^
|
||||||
|
const DeepCollectionEquality().hash(view) ^
|
||||||
|
const DeepCollectionEquality().hash(successOrFailure);
|
||||||
|
|
||||||
|
@JsonKey(ignore: true)
|
||||||
|
@override
|
||||||
|
_$ViewStateCopyWith<_ViewState> get copyWith =>
|
||||||
|
__$ViewStateCopyWithImpl<_ViewState>(this, _$identity);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class _ViewState implements ViewEditState {
|
||||||
|
const factory _ViewState(
|
||||||
|
{required bool isLoading,
|
||||||
|
required Option<View> view,
|
||||||
|
required Either<Unit, WorkspaceError> successOrFailure}) = _$_ViewState;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get isLoading => throw _privateConstructorUsedError;
|
||||||
|
@override
|
||||||
|
Option<View> get view => throw _privateConstructorUsedError;
|
||||||
|
@override
|
||||||
|
Either<Unit, WorkspaceError> get successOrFailure =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
@override
|
||||||
|
@JsonKey(ignore: true)
|
||||||
|
_$ViewStateCopyWith<_ViewState> get copyWith =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
}
|
@ -1,44 +0,0 @@
|
|||||||
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
||||||
import 'package:dartz/dartz.dart';
|
|
||||||
|
|
||||||
part 'view_list_bloc.freezed.dart';
|
|
||||||
|
|
||||||
class ViewListBloc extends Bloc<ViewListEvent, ViewListState> {
|
|
||||||
final List<View> views;
|
|
||||||
ViewListBloc({required this.views}) : super(ViewListState.initial(views));
|
|
||||||
|
|
||||||
@override
|
|
||||||
Stream<ViewListState> mapEventToState(ViewListEvent event) async* {
|
|
||||||
yield* event.map(
|
|
||||||
initial: (s) async* {
|
|
||||||
yield ViewListState.initial(s.views);
|
|
||||||
},
|
|
||||||
openView: (s) async* {
|
|
||||||
yield state.copyWith(openedView: some(s.view.id));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@freezed
|
|
||||||
class ViewListEvent with _$ViewListEvent {
|
|
||||||
const factory ViewListEvent.initial(List<View> views) = Initial;
|
|
||||||
const factory ViewListEvent.openView(View view) = OpenView;
|
|
||||||
}
|
|
||||||
|
|
||||||
@freezed
|
|
||||||
class ViewListState with _$ViewListState {
|
|
||||||
const factory ViewListState({
|
|
||||||
required bool isLoading,
|
|
||||||
required Option<String> openedView,
|
|
||||||
required Option<List<View>> views,
|
|
||||||
}) = _ViewListState;
|
|
||||||
|
|
||||||
factory ViewListState.initial(List<View> views) => ViewListState(
|
|
||||||
isLoading: false,
|
|
||||||
openedView: none(),
|
|
||||||
views: some(views),
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,484 +0,0 @@
|
|||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
||||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target
|
|
||||||
|
|
||||||
part of 'view_list_bloc.dart';
|
|
||||||
|
|
||||||
// **************************************************************************
|
|
||||||
// FreezedGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
T _$identity<T>(T value) => value;
|
|
||||||
|
|
||||||
final _privateConstructorUsedError = UnsupportedError(
|
|
||||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
class _$ViewListEventTearOff {
|
|
||||||
const _$ViewListEventTearOff();
|
|
||||||
|
|
||||||
Initial initial(List<View> views) {
|
|
||||||
return Initial(
|
|
||||||
views,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
OpenView openView(View view) {
|
|
||||||
return OpenView(
|
|
||||||
view,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
const $ViewListEvent = _$ViewListEventTearOff();
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
mixin _$ViewListEvent {
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult when<TResult extends Object?>({
|
|
||||||
required TResult Function(List<View> views) initial,
|
|
||||||
required TResult Function(View view) openView,
|
|
||||||
}) =>
|
|
||||||
throw _privateConstructorUsedError;
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult maybeWhen<TResult extends Object?>({
|
|
||||||
TResult Function(List<View> views)? initial,
|
|
||||||
TResult Function(View view)? openView,
|
|
||||||
required TResult orElse(),
|
|
||||||
}) =>
|
|
||||||
throw _privateConstructorUsedError;
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult map<TResult extends Object?>({
|
|
||||||
required TResult Function(Initial value) initial,
|
|
||||||
required TResult Function(OpenView value) openView,
|
|
||||||
}) =>
|
|
||||||
throw _privateConstructorUsedError;
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult maybeMap<TResult extends Object?>({
|
|
||||||
TResult Function(Initial value)? initial,
|
|
||||||
TResult Function(OpenView value)? openView,
|
|
||||||
required TResult orElse(),
|
|
||||||
}) =>
|
|
||||||
throw _privateConstructorUsedError;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
abstract class $ViewListEventCopyWith<$Res> {
|
|
||||||
factory $ViewListEventCopyWith(
|
|
||||||
ViewListEvent value, $Res Function(ViewListEvent) then) =
|
|
||||||
_$ViewListEventCopyWithImpl<$Res>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
class _$ViewListEventCopyWithImpl<$Res>
|
|
||||||
implements $ViewListEventCopyWith<$Res> {
|
|
||||||
_$ViewListEventCopyWithImpl(this._value, this._then);
|
|
||||||
|
|
||||||
final ViewListEvent _value;
|
|
||||||
// ignore: unused_field
|
|
||||||
final $Res Function(ViewListEvent) _then;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
abstract class $InitialCopyWith<$Res> {
|
|
||||||
factory $InitialCopyWith(Initial value, $Res Function(Initial) then) =
|
|
||||||
_$InitialCopyWithImpl<$Res>;
|
|
||||||
$Res call({List<View> views});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
class _$InitialCopyWithImpl<$Res> extends _$ViewListEventCopyWithImpl<$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;
|
|
||||||
|
|
||||||
@override
|
|
||||||
$Res call({
|
|
||||||
Object? views = freezed,
|
|
||||||
}) {
|
|
||||||
return _then(Initial(
|
|
||||||
views == freezed
|
|
||||||
? _value.views
|
|
||||||
: views // ignore: cast_nullable_to_non_nullable
|
|
||||||
as List<View>,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
|
|
||||||
class _$Initial implements Initial {
|
|
||||||
const _$Initial(this.views);
|
|
||||||
|
|
||||||
@override
|
|
||||||
final List<View> views;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() {
|
|
||||||
return 'ViewListEvent.initial(views: $views)';
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(dynamic other) {
|
|
||||||
return identical(this, other) ||
|
|
||||||
(other is Initial &&
|
|
||||||
(identical(other.views, views) ||
|
|
||||||
const DeepCollectionEquality().equals(other.views, views)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode =>
|
|
||||||
runtimeType.hashCode ^ const DeepCollectionEquality().hash(views);
|
|
||||||
|
|
||||||
@JsonKey(ignore: true)
|
|
||||||
@override
|
|
||||||
$InitialCopyWith<Initial> get copyWith =>
|
|
||||||
_$InitialCopyWithImpl<Initial>(this, _$identity);
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult when<TResult extends Object?>({
|
|
||||||
required TResult Function(List<View> views) initial,
|
|
||||||
required TResult Function(View view) openView,
|
|
||||||
}) {
|
|
||||||
return initial(views);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult maybeWhen<TResult extends Object?>({
|
|
||||||
TResult Function(List<View> views)? initial,
|
|
||||||
TResult Function(View view)? openView,
|
|
||||||
required TResult orElse(),
|
|
||||||
}) {
|
|
||||||
if (initial != null) {
|
|
||||||
return initial(views);
|
|
||||||
}
|
|
||||||
return orElse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult map<TResult extends Object?>({
|
|
||||||
required TResult Function(Initial value) initial,
|
|
||||||
required TResult Function(OpenView value) openView,
|
|
||||||
}) {
|
|
||||||
return initial(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult maybeMap<TResult extends Object?>({
|
|
||||||
TResult Function(Initial value)? initial,
|
|
||||||
TResult Function(OpenView value)? openView,
|
|
||||||
required TResult orElse(),
|
|
||||||
}) {
|
|
||||||
if (initial != null) {
|
|
||||||
return initial(this);
|
|
||||||
}
|
|
||||||
return orElse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class Initial implements ViewListEvent {
|
|
||||||
const factory Initial(List<View> views) = _$Initial;
|
|
||||||
|
|
||||||
List<View> get views => throw _privateConstructorUsedError;
|
|
||||||
@JsonKey(ignore: true)
|
|
||||||
$InitialCopyWith<Initial> get copyWith => throw _privateConstructorUsedError;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
abstract class $OpenViewCopyWith<$Res> {
|
|
||||||
factory $OpenViewCopyWith(OpenView value, $Res Function(OpenView) then) =
|
|
||||||
_$OpenViewCopyWithImpl<$Res>;
|
|
||||||
$Res call({View view});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
class _$OpenViewCopyWithImpl<$Res> extends _$ViewListEventCopyWithImpl<$Res>
|
|
||||||
implements $OpenViewCopyWith<$Res> {
|
|
||||||
_$OpenViewCopyWithImpl(OpenView _value, $Res Function(OpenView) _then)
|
|
||||||
: super(_value, (v) => _then(v as OpenView));
|
|
||||||
|
|
||||||
@override
|
|
||||||
OpenView get _value => super._value as OpenView;
|
|
||||||
|
|
||||||
@override
|
|
||||||
$Res call({
|
|
||||||
Object? view = freezed,
|
|
||||||
}) {
|
|
||||||
return _then(OpenView(
|
|
||||||
view == freezed
|
|
||||||
? _value.view
|
|
||||||
: view // ignore: cast_nullable_to_non_nullable
|
|
||||||
as View,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
|
|
||||||
class _$OpenView implements OpenView {
|
|
||||||
const _$OpenView(this.view);
|
|
||||||
|
|
||||||
@override
|
|
||||||
final View view;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() {
|
|
||||||
return 'ViewListEvent.openView(view: $view)';
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(dynamic other) {
|
|
||||||
return identical(this, other) ||
|
|
||||||
(other is OpenView &&
|
|
||||||
(identical(other.view, view) ||
|
|
||||||
const DeepCollectionEquality().equals(other.view, view)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode =>
|
|
||||||
runtimeType.hashCode ^ const DeepCollectionEquality().hash(view);
|
|
||||||
|
|
||||||
@JsonKey(ignore: true)
|
|
||||||
@override
|
|
||||||
$OpenViewCopyWith<OpenView> get copyWith =>
|
|
||||||
_$OpenViewCopyWithImpl<OpenView>(this, _$identity);
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult when<TResult extends Object?>({
|
|
||||||
required TResult Function(List<View> views) initial,
|
|
||||||
required TResult Function(View view) openView,
|
|
||||||
}) {
|
|
||||||
return openView(view);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult maybeWhen<TResult extends Object?>({
|
|
||||||
TResult Function(List<View> views)? initial,
|
|
||||||
TResult Function(View view)? openView,
|
|
||||||
required TResult orElse(),
|
|
||||||
}) {
|
|
||||||
if (openView != null) {
|
|
||||||
return openView(view);
|
|
||||||
}
|
|
||||||
return orElse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult map<TResult extends Object?>({
|
|
||||||
required TResult Function(Initial value) initial,
|
|
||||||
required TResult Function(OpenView value) openView,
|
|
||||||
}) {
|
|
||||||
return openView(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult maybeMap<TResult extends Object?>({
|
|
||||||
TResult Function(Initial value)? initial,
|
|
||||||
TResult Function(OpenView value)? openView,
|
|
||||||
required TResult orElse(),
|
|
||||||
}) {
|
|
||||||
if (openView != null) {
|
|
||||||
return openView(this);
|
|
||||||
}
|
|
||||||
return orElse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class OpenView implements ViewListEvent {
|
|
||||||
const factory OpenView(View view) = _$OpenView;
|
|
||||||
|
|
||||||
View get view => throw _privateConstructorUsedError;
|
|
||||||
@JsonKey(ignore: true)
|
|
||||||
$OpenViewCopyWith<OpenView> get copyWith =>
|
|
||||||
throw _privateConstructorUsedError;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
class _$ViewListStateTearOff {
|
|
||||||
const _$ViewListStateTearOff();
|
|
||||||
|
|
||||||
_ViewListState call(
|
|
||||||
{required bool isLoading,
|
|
||||||
required Option<String> openedView,
|
|
||||||
required Option<List<View>> views}) {
|
|
||||||
return _ViewListState(
|
|
||||||
isLoading: isLoading,
|
|
||||||
openedView: openedView,
|
|
||||||
views: views,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
const $ViewListState = _$ViewListStateTearOff();
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
mixin _$ViewListState {
|
|
||||||
bool get isLoading => throw _privateConstructorUsedError;
|
|
||||||
Option<String> get openedView => throw _privateConstructorUsedError;
|
|
||||||
Option<List<View>> get views => throw _privateConstructorUsedError;
|
|
||||||
|
|
||||||
@JsonKey(ignore: true)
|
|
||||||
$ViewListStateCopyWith<ViewListState> get copyWith =>
|
|
||||||
throw _privateConstructorUsedError;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
abstract class $ViewListStateCopyWith<$Res> {
|
|
||||||
factory $ViewListStateCopyWith(
|
|
||||||
ViewListState value, $Res Function(ViewListState) then) =
|
|
||||||
_$ViewListStateCopyWithImpl<$Res>;
|
|
||||||
$Res call(
|
|
||||||
{bool isLoading, Option<String> openedView, Option<List<View>> views});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
class _$ViewListStateCopyWithImpl<$Res>
|
|
||||||
implements $ViewListStateCopyWith<$Res> {
|
|
||||||
_$ViewListStateCopyWithImpl(this._value, this._then);
|
|
||||||
|
|
||||||
final ViewListState _value;
|
|
||||||
// ignore: unused_field
|
|
||||||
final $Res Function(ViewListState) _then;
|
|
||||||
|
|
||||||
@override
|
|
||||||
$Res call({
|
|
||||||
Object? isLoading = freezed,
|
|
||||||
Object? openedView = freezed,
|
|
||||||
Object? views = freezed,
|
|
||||||
}) {
|
|
||||||
return _then(_value.copyWith(
|
|
||||||
isLoading: isLoading == freezed
|
|
||||||
? _value.isLoading
|
|
||||||
: isLoading // ignore: cast_nullable_to_non_nullable
|
|
||||||
as bool,
|
|
||||||
openedView: openedView == freezed
|
|
||||||
? _value.openedView
|
|
||||||
: openedView // ignore: cast_nullable_to_non_nullable
|
|
||||||
as Option<String>,
|
|
||||||
views: views == freezed
|
|
||||||
? _value.views
|
|
||||||
: views // ignore: cast_nullable_to_non_nullable
|
|
||||||
as Option<List<View>>,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
abstract class _$ViewListStateCopyWith<$Res>
|
|
||||||
implements $ViewListStateCopyWith<$Res> {
|
|
||||||
factory _$ViewListStateCopyWith(
|
|
||||||
_ViewListState value, $Res Function(_ViewListState) then) =
|
|
||||||
__$ViewListStateCopyWithImpl<$Res>;
|
|
||||||
@override
|
|
||||||
$Res call(
|
|
||||||
{bool isLoading, Option<String> openedView, Option<List<View>> views});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
class __$ViewListStateCopyWithImpl<$Res>
|
|
||||||
extends _$ViewListStateCopyWithImpl<$Res>
|
|
||||||
implements _$ViewListStateCopyWith<$Res> {
|
|
||||||
__$ViewListStateCopyWithImpl(
|
|
||||||
_ViewListState _value, $Res Function(_ViewListState) _then)
|
|
||||||
: super(_value, (v) => _then(v as _ViewListState));
|
|
||||||
|
|
||||||
@override
|
|
||||||
_ViewListState get _value => super._value as _ViewListState;
|
|
||||||
|
|
||||||
@override
|
|
||||||
$Res call({
|
|
||||||
Object? isLoading = freezed,
|
|
||||||
Object? openedView = freezed,
|
|
||||||
Object? views = freezed,
|
|
||||||
}) {
|
|
||||||
return _then(_ViewListState(
|
|
||||||
isLoading: isLoading == freezed
|
|
||||||
? _value.isLoading
|
|
||||||
: isLoading // ignore: cast_nullable_to_non_nullable
|
|
||||||
as bool,
|
|
||||||
openedView: openedView == freezed
|
|
||||||
? _value.openedView
|
|
||||||
: openedView // ignore: cast_nullable_to_non_nullable
|
|
||||||
as Option<String>,
|
|
||||||
views: views == freezed
|
|
||||||
? _value.views
|
|
||||||
: views // ignore: cast_nullable_to_non_nullable
|
|
||||||
as Option<List<View>>,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
|
|
||||||
class _$_ViewListState implements _ViewListState {
|
|
||||||
const _$_ViewListState(
|
|
||||||
{required this.isLoading, required this.openedView, required this.views});
|
|
||||||
|
|
||||||
@override
|
|
||||||
final bool isLoading;
|
|
||||||
@override
|
|
||||||
final Option<String> openedView;
|
|
||||||
@override
|
|
||||||
final Option<List<View>> views;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() {
|
|
||||||
return 'ViewListState(isLoading: $isLoading, openedView: $openedView, views: $views)';
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(dynamic other) {
|
|
||||||
return identical(this, other) ||
|
|
||||||
(other is _ViewListState &&
|
|
||||||
(identical(other.isLoading, isLoading) ||
|
|
||||||
const DeepCollectionEquality()
|
|
||||||
.equals(other.isLoading, isLoading)) &&
|
|
||||||
(identical(other.openedView, openedView) ||
|
|
||||||
const DeepCollectionEquality()
|
|
||||||
.equals(other.openedView, openedView)) &&
|
|
||||||
(identical(other.views, views) ||
|
|
||||||
const DeepCollectionEquality().equals(other.views, views)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode =>
|
|
||||||
runtimeType.hashCode ^
|
|
||||||
const DeepCollectionEquality().hash(isLoading) ^
|
|
||||||
const DeepCollectionEquality().hash(openedView) ^
|
|
||||||
const DeepCollectionEquality().hash(views);
|
|
||||||
|
|
||||||
@JsonKey(ignore: true)
|
|
||||||
@override
|
|
||||||
_$ViewListStateCopyWith<_ViewListState> get copyWith =>
|
|
||||||
__$ViewListStateCopyWithImpl<_ViewListState>(this, _$identity);
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class _ViewListState implements ViewListState {
|
|
||||||
const factory _ViewListState(
|
|
||||||
{required bool isLoading,
|
|
||||||
required Option<String> openedView,
|
|
||||||
required Option<List<View>> views}) = _$_ViewListState;
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool get isLoading => throw _privateConstructorUsedError;
|
|
||||||
@override
|
|
||||||
Option<String> get openedView => throw _privateConstructorUsedError;
|
|
||||||
@override
|
|
||||||
Option<List<View>> get views => throw _privateConstructorUsedError;
|
|
||||||
@override
|
|
||||||
@JsonKey(ignore: true)
|
|
||||||
_$ViewListStateCopyWith<_ViewListState> get copyWith =>
|
|
||||||
throw _privateConstructorUsedError;
|
|
||||||
}
|
|
@ -5,11 +5,15 @@ import 'package:dartz/dartz.dart';
|
|||||||
typedef ViewUpdatedCallback = void Function(Either<View, WorkspaceError>);
|
typedef ViewUpdatedCallback = void Function(Either<View, WorkspaceError>);
|
||||||
|
|
||||||
abstract class IView {
|
abstract class IView {
|
||||||
Future<Either<View, WorkspaceError>> readView();
|
View get view;
|
||||||
|
|
||||||
|
Future<Either<Unit, WorkspaceError>> pushIntoTrash();
|
||||||
|
|
||||||
|
Future<Either<Unit, WorkspaceError>> rename(String newName);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class IViewWatch {
|
abstract class IViewListener {
|
||||||
void startWatching({ViewUpdatedCallback? updatedCallback});
|
void start({ViewUpdatedCallback? updatedCallback});
|
||||||
|
|
||||||
Future<void> stopWatching();
|
Future<void> stop();
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,20 @@
|
|||||||
import 'package:flowy_sdk/protobuf/flowy-workspace/protobuf.dart';
|
import 'package:flowy_sdk/protobuf/flowy-workspace/protobuf.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
|
|
||||||
typedef WorkspaceCreateAppCallback = void Function(
|
typedef WorkspaceCreateAppCallback = void Function(Either<List<App>, WorkspaceError> appsOrFail);
|
||||||
Either<List<App>, WorkspaceError> appsOrFail);
|
|
||||||
|
|
||||||
typedef WorkspaceUpdatedCallback = void Function(String name, String desc);
|
typedef WorkspaceUpdatedCallback = void Function(String name, String desc);
|
||||||
|
|
||||||
typedef WorkspaceDeleteAppCallback = void Function(
|
typedef WorkspaceDeleteAppCallback = void Function(Either<List<App>, WorkspaceError> appsOrFail);
|
||||||
Either<List<App>, WorkspaceError> appsOrFail);
|
|
||||||
|
|
||||||
abstract class IWorkspace {
|
abstract class IWorkspace {
|
||||||
Future<Either<App, WorkspaceError>> createApp(
|
Future<Either<App, WorkspaceError>> createApp({required String name, String? desc});
|
||||||
{required String name, String? desc});
|
|
||||||
|
|
||||||
Future<Either<List<App>, WorkspaceError>> getApps();
|
Future<Either<List<App>, WorkspaceError>> getApps();
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class IWorkspaceWatch {
|
abstract class IWorkspaceListener {
|
||||||
void startWatching(
|
void start({WorkspaceCreateAppCallback? addAppCallback, WorkspaceUpdatedCallback? updatedCallback});
|
||||||
{WorkspaceCreateAppCallback? addAppCallback,
|
|
||||||
WorkspaceUpdatedCallback? updatedCallback});
|
|
||||||
|
|
||||||
Future<void> stopWatching();
|
Future<void> stop();
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,19 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flowy_infra/image.dart';
|
import 'package:flowy_infra/image.dart';
|
||||||
|
|
||||||
AssetImage assetImageForViewType(ViewType type) {
|
AssetImage assetImageForViewType(ViewType type) {
|
||||||
final imageName = imageNameForViewType(type);
|
final imageName = _imageNameForViewType(type);
|
||||||
return AssetImage('assets/images/$imageName');
|
return AssetImage('assets/images/$imageName');
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget svgForViewType(ViewType type) {
|
extension SvgViewType on View {
|
||||||
final imageName = imageNameForViewType(type);
|
Widget thumbnail() {
|
||||||
|
final imageName = _imageNameForViewType(viewType);
|
||||||
final Widget widget = svg(imageName);
|
final Widget widget = svg(imageName);
|
||||||
return widget;
|
return widget;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String imageNameForViewType(ViewType type) {
|
String _imageNameForViewType(ViewType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ViewType.Doc:
|
case ViewType.Doc:
|
||||||
return "file_icon";
|
return "file_icon";
|
||||||
|
@ -34,16 +34,18 @@ abstract class HomeStackContext extends Equatable with NavigationItem {
|
|||||||
Widget render();
|
Widget render();
|
||||||
}
|
}
|
||||||
|
|
||||||
HomeStackContext stackCtxFromView(View view) {
|
extension ViewStackContext on View {
|
||||||
switch (view.viewType) {
|
HomeStackContext intoStackContext() {
|
||||||
|
switch (viewType) {
|
||||||
case ViewType.Blank:
|
case ViewType.Blank:
|
||||||
return BlankStackContext();
|
return BlankStackContext();
|
||||||
case ViewType.Doc:
|
case ViewType.Doc:
|
||||||
return DocStackContext(view: view);
|
return DocStackContext(view: this);
|
||||||
default:
|
default:
|
||||||
return BlankStackContext();
|
return BlankStackContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class HomeStackNotifier extends ChangeNotifier {
|
class HomeStackNotifier extends ChangeNotifier {
|
||||||
HomeStackContext inner;
|
HomeStackContext inner;
|
||||||
|
@ -6,7 +6,7 @@ import 'package:app_flowy/workspace/application/menu/menu_bloc.dart';
|
|||||||
import 'package:app_flowy/workspace/application/menu/menu_user_bloc.dart';
|
import 'package:app_flowy/workspace/application/menu/menu_user_bloc.dart';
|
||||||
import 'package:app_flowy/workspace/application/menu/menu_listen.dart';
|
import 'package:app_flowy/workspace/application/menu/menu_listen.dart';
|
||||||
import 'package:app_flowy/workspace/application/view/view_bloc.dart';
|
import 'package:app_flowy/workspace/application/view/view_bloc.dart';
|
||||||
import 'package:app_flowy/workspace/application/view/view_list_bloc.dart';
|
import 'package:app_flowy/workspace/application/view/view_edit_bloc.dart';
|
||||||
import 'package:app_flowy/workspace/application/workspace/welcome_bloc.dart';
|
import 'package:app_flowy/workspace/application/workspace/welcome_bloc.dart';
|
||||||
import 'package:app_flowy/workspace/domain/i_doc.dart';
|
import 'package:app_flowy/workspace/domain/i_doc.dart';
|
||||||
import 'package:app_flowy/workspace/domain/i_view.dart';
|
import 'package:app_flowy/workspace/domain/i_view.dart';
|
||||||
@ -33,31 +33,31 @@ class HomeDepsResolver {
|
|||||||
//App
|
//App
|
||||||
getIt.registerFactoryParam<IApp, String, void>((appId, _) => IAppImpl(repo: AppRepository(appId: appId)));
|
getIt.registerFactoryParam<IApp, String, void>((appId, _) => IAppImpl(repo: AppRepository(appId: appId)));
|
||||||
getIt.registerFactoryParam<IAppListenr, String, void>(
|
getIt.registerFactoryParam<IAppListenr, String, void>(
|
||||||
(appId, _) => IAppWatchImpl(repo: AppWatchRepository(appId: appId)));
|
(appId, _) => IAppListenerhImpl(repo: AppListenerRepository(appId: appId)));
|
||||||
|
|
||||||
//workspace
|
//workspace
|
||||||
getIt.registerFactoryParam<IWorkspace, UserProfile, String>(
|
getIt.registerFactoryParam<IWorkspace, UserProfile, String>(
|
||||||
(user, workspaceId) => IWorkspaceImpl(repo: WorkspaceRepo(user: user, workspaceId: workspaceId)));
|
(user, workspaceId) => IWorkspaceImpl(repo: WorkspaceRepo(user: user, workspaceId: workspaceId)));
|
||||||
getIt.registerFactoryParam<IWorkspaceWatch, UserProfile, String>(
|
getIt.registerFactoryParam<IWorkspaceListener, UserProfile, String>((user, workspaceId) =>
|
||||||
(user, workspaceId) => IWorkspaceWatchImpl(repo: WorkspaceWatchRepo(user: user, workspaceId: workspaceId)));
|
IWorkspaceListenerImpl(repo: WorkspaceListenerRepo(user: user, workspaceId: workspaceId)));
|
||||||
|
|
||||||
// View
|
// View
|
||||||
getIt.registerFactoryParam<IView, View, void>((view, _) => IViewImpl(repo: ViewRepository(view: view)));
|
getIt.registerFactoryParam<IView, View, void>((view, _) => IViewImpl(repo: ViewRepository(view: view)));
|
||||||
getIt.registerFactoryParam<IViewWatch, View, void>(
|
getIt.registerFactoryParam<IViewListener, View, void>(
|
||||||
(view, _) => IViewWatchImpl(repo: ViewWatchRepository(view: view)));
|
(view, _) => IViewListenerImpl(repo: ViewListenerRepository(view: view)));
|
||||||
|
|
||||||
// Doc
|
// Doc
|
||||||
getIt.registerFactoryParam<IDoc, String, void>((docId, _) => IDocImpl(repo: DocRepository(docId: docId)));
|
getIt.registerFactoryParam<IDoc, String, void>((docId, _) => IDocImpl(repo: DocRepository(docId: docId)));
|
||||||
|
|
||||||
// User
|
// User
|
||||||
getIt.registerFactoryParam<IUser, UserProfile, void>((user, _) => IUserImpl(repo: UserRepo(user: user)));
|
getIt.registerFactoryParam<IUser, UserProfile, void>((user, _) => IUserImpl(repo: UserRepo(user: user)));
|
||||||
getIt.registerFactoryParam<IUserListener, UserProfile, void>((user, _) => IUserWatchImpl(user: user));
|
getIt.registerFactoryParam<IUserListener, UserProfile, void>((user, _) => IUserListenerImpl(user: user));
|
||||||
|
|
||||||
//Menu Bloc
|
//Menu Bloc
|
||||||
getIt.registerFactoryParam<MenuBloc, UserProfile, String>(
|
getIt.registerFactoryParam<MenuBloc, UserProfile, String>(
|
||||||
(user, workspaceId) => MenuBloc(getIt<IWorkspace>(param1: user, param2: workspaceId)));
|
(user, workspaceId) => MenuBloc(getIt<IWorkspace>(param1: user, param2: workspaceId)));
|
||||||
getIt.registerFactoryParam<MenuListenBloc, UserProfile, String>(
|
getIt.registerFactoryParam<MenuListenBloc, UserProfile, String>(
|
||||||
(user, workspaceId) => MenuListenBloc(getIt<IWorkspaceWatch>(param1: user, param2: workspaceId)));
|
(user, workspaceId) => MenuListenBloc(getIt<IWorkspaceListener>(param1: user, param2: workspaceId)));
|
||||||
|
|
||||||
getIt.registerFactoryParam<MenuUserBloc, UserProfile, void>(
|
getIt.registerFactoryParam<MenuUserBloc, UserProfile, void>(
|
||||||
(user, _) => MenuUserBloc(getIt<IUser>(param1: user), getIt<IUserListener>(param1: user)));
|
(user, _) => MenuUserBloc(getIt<IUser>(param1: user), getIt<IUserListener>(param1: user)));
|
||||||
@ -67,24 +67,17 @@ class HomeDepsResolver {
|
|||||||
getIt.registerFactoryParam<AppListenBloc, String, void>(
|
getIt.registerFactoryParam<AppListenBloc, String, void>(
|
||||||
(appId, _) => AppListenBloc(getIt<IAppListenr>(param1: appId)));
|
(appId, _) => AppListenBloc(getIt<IAppListenr>(param1: appId)));
|
||||||
|
|
||||||
getIt
|
getIt.registerFactoryParam<ViewBloc, View, void>((view, _) => ViewBloc(iViewImpl: getIt<IView>(param1: view)));
|
||||||
.registerFactoryParam<ViewBloc, String, void>((viewId, _) => ViewBloc(iViewImpl: getIt<IView>(param1: viewId)));
|
|
||||||
|
|
||||||
getIt.registerFactoryParam<DocBloc, String, void>((docId, _) => DocBloc(iDocImpl: getIt<IDoc>(param1: docId)));
|
getIt.registerFactoryParam<DocBloc, String, void>((docId, _) => DocBloc(iDocImpl: getIt<IDoc>(param1: docId)));
|
||||||
|
|
||||||
getIt.registerFactoryParam<DocEditBloc, String, void>((docId, _) => DocEditBloc(getIt<IDoc>(param1: docId)));
|
getIt.registerFactoryParam<DocEditBloc, String, void>((docId, _) => DocEditBloc(getIt<IDoc>(param1: docId)));
|
||||||
|
|
||||||
// editor
|
|
||||||
getIt.registerFactoryParam<ViewListBloc, List<View>, void>((views, _) => ViewListBloc(views: views));
|
|
||||||
|
|
||||||
getIt.registerFactoryParam<WelcomeBloc, UserProfile, void>(
|
getIt.registerFactoryParam<WelcomeBloc, UserProfile, void>(
|
||||||
(user, _) => WelcomeBloc(
|
(user, _) => WelcomeBloc(
|
||||||
repo: UserRepo(user: user),
|
repo: UserRepo(user: user),
|
||||||
watch: getIt<IUserListener>(param1: user),
|
watch: getIt<IUserListener>(param1: user),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// getIt.registerFactoryParam<ViewBloc, String, void>(
|
|
||||||
// (viewId, _) => ViewBloc(iViewImpl: getIt<IView>(param1: viewId)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,15 +28,15 @@ class IAppImpl extends IApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IAppWatchImpl extends IAppListenr {
|
class IAppListenerhImpl extends IAppListenr {
|
||||||
AppWatchRepository repo;
|
AppListenerRepository repo;
|
||||||
IAppWatchImpl({
|
IAppListenerhImpl({
|
||||||
required this.repo,
|
required this.repo,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void start({AppCreateViewCallback? addViewCallback, AppUpdatedCallback? updatedCallback}) {
|
void start({AppCreateViewCallback? addViewCallback, AppUpdatedCallback? updatedCallback}) {
|
||||||
repo.startWatching(createView: addViewCallback, update: updatedCallback);
|
repo.startListen(createView: addViewCallback, update: updatedCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -49,7 +49,7 @@ class IUserImpl extends IUser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IUserWatchImpl extends IUserListener {
|
class IUserListenerImpl extends IUserListener {
|
||||||
StreamSubscription<ObservableSubject>? _subscription;
|
StreamSubscription<ObservableSubject>? _subscription;
|
||||||
WorkspacesUpdatedCallback? _workspacesUpdated;
|
WorkspacesUpdatedCallback? _workspacesUpdated;
|
||||||
AuthChangedCallback? _authChanged;
|
AuthChangedCallback? _authChanged;
|
||||||
@ -58,7 +58,7 @@ class IUserWatchImpl extends IUserListener {
|
|||||||
late WorkspaceObservableParser _workspaceParser;
|
late WorkspaceObservableParser _workspaceParser;
|
||||||
late UserObservableParser _userParser;
|
late UserObservableParser _userParser;
|
||||||
late UserProfile _user;
|
late UserProfile _user;
|
||||||
IUserWatchImpl({
|
IUserListenerImpl({
|
||||||
required UserProfile user,
|
required UserProfile user,
|
||||||
}) {
|
}) {
|
||||||
_user = user;
|
_user = user;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import 'package:app_flowy/workspace/domain/i_view.dart';
|
import 'package:app_flowy/workspace/domain/i_view.dart';
|
||||||
import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart';
|
import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
|
|
||||||
import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
|
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
|
||||||
|
|
||||||
class IViewImpl extends IView {
|
class IViewImpl extends IView {
|
||||||
ViewRepository repo;
|
ViewRepository repo;
|
||||||
@ -10,24 +10,32 @@ class IViewImpl extends IView {
|
|||||||
IViewImpl({required this.repo});
|
IViewImpl({required this.repo});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Either<View, WorkspaceError>> readView() {
|
View get view => repo.view;
|
||||||
return repo.readView();
|
|
||||||
|
@override
|
||||||
|
Future<Either<Unit, WorkspaceError>> pushIntoTrash() {
|
||||||
|
return repo.updateView(isTrash: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Either<Unit, WorkspaceError>> rename(String newName) {
|
||||||
|
return repo.updateView(name: newName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IViewWatchImpl extends IViewWatch {
|
class IViewListenerImpl extends IViewListener {
|
||||||
final ViewWatchRepository repo;
|
final ViewListenerRepository repo;
|
||||||
IViewWatchImpl({
|
IViewListenerImpl({
|
||||||
required this.repo,
|
required this.repo,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void startWatching({ViewUpdatedCallback? updatedCallback}) {
|
void start({ViewUpdatedCallback? updatedCallback}) {
|
||||||
repo.startWatching(update: updatedCallback);
|
repo.startWatching(update: updatedCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> stopWatching() async {
|
Future<void> stop() async {
|
||||||
await repo.close();
|
await repo.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,7 @@ class IWorkspaceImpl extends IWorkspace {
|
|||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Either<App, WorkspaceError>> createApp(
|
Future<Either<App, WorkspaceError>> createApp({required String name, String? desc}) {
|
||||||
{required String name, String? desc}) {
|
|
||||||
return repo.createApp(name, desc ?? "");
|
return repo.createApp(name, desc ?? "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,21 +28,19 @@ class IWorkspaceImpl extends IWorkspace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IWorkspaceWatchImpl extends IWorkspaceWatch {
|
class IWorkspaceListenerImpl extends IWorkspaceListener {
|
||||||
WorkspaceWatchRepo repo;
|
WorkspaceListenerRepo repo;
|
||||||
IWorkspaceWatchImpl({
|
IWorkspaceListenerImpl({
|
||||||
required this.repo,
|
required this.repo,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void startWatching(
|
void start({WorkspaceCreateAppCallback? addAppCallback, WorkspaceUpdatedCallback? updatedCallback}) {
|
||||||
{WorkspaceCreateAppCallback? addAppCallback,
|
repo.startListen(createApp: addAppCallback, update: updatedCallback);
|
||||||
WorkspaceUpdatedCallback? updatedCallback}) {
|
|
||||||
repo.startWatching(createApp: addAppCallback, update: updatedCallback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> stopWatching() async {
|
Future<void> stop() async {
|
||||||
await repo.close();
|
await repo.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,7 @@ class AppRepository {
|
|||||||
return WorkspaceEventReadApp(request).send();
|
return WorkspaceEventReadApp(request).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<View, WorkspaceError>> createView(
|
Future<Either<View, WorkspaceError>> createView(String name, String desc, ViewType viewType) {
|
||||||
String name, String desc, ViewType viewType) {
|
|
||||||
final request = CreateViewRequest.create()
|
final request = CreateViewRequest.create()
|
||||||
..belongToId = appId
|
..belongToId = appId
|
||||||
..name = name
|
..name = name
|
||||||
@ -53,7 +52,7 @@ class AppRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AppWatchRepository {
|
class AppListenerRepository {
|
||||||
StreamSubscription<ObservableSubject>? _subscription;
|
StreamSubscription<ObservableSubject>? _subscription;
|
||||||
AppCreateViewCallback? _createView;
|
AppCreateViewCallback? _createView;
|
||||||
AppDeleteViewCallback? _deleteView;
|
AppDeleteViewCallback? _deleteView;
|
||||||
@ -61,25 +60,19 @@ class AppWatchRepository {
|
|||||||
late WorkspaceObservableParser _extractor;
|
late WorkspaceObservableParser _extractor;
|
||||||
String appId;
|
String appId;
|
||||||
|
|
||||||
AppWatchRepository({
|
AppListenerRepository({
|
||||||
required this.appId,
|
required this.appId,
|
||||||
});
|
});
|
||||||
|
|
||||||
void startWatching(
|
void startListen({AppCreateViewCallback? createView, AppDeleteViewCallback? deleteView, AppUpdatedCallback? update}) {
|
||||||
{AppCreateViewCallback? createView,
|
|
||||||
AppDeleteViewCallback? deleteView,
|
|
||||||
AppUpdatedCallback? update}) {
|
|
||||||
_createView = createView;
|
_createView = createView;
|
||||||
_deleteView = deleteView;
|
_deleteView = deleteView;
|
||||||
_update = update;
|
_update = update;
|
||||||
_extractor =
|
_extractor = WorkspaceObservableParser(id: appId, callback: _bservableCallback);
|
||||||
WorkspaceObservableParser(id: appId, callback: _bservableCallback);
|
_subscription = RustStreamReceiver.listen((observable) => _extractor.parse(observable));
|
||||||
_subscription =
|
|
||||||
RustStreamReceiver.listen((observable) => _extractor.parse(observable));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _bservableCallback(
|
void _bservableCallback(WorkspaceObservable ty, Either<Uint8List, WorkspaceError> result) {
|
||||||
WorkspaceObservable ty, Either<Uint8List, WorkspaceError> result) {
|
|
||||||
switch (ty) {
|
switch (ty) {
|
||||||
case WorkspaceObservable.AppCreateView:
|
case WorkspaceObservable.AppCreateView:
|
||||||
if (_createView != null) {
|
if (_createView != null) {
|
||||||
|
@ -6,7 +6,9 @@ import 'package:flowy_sdk/protobuf/flowy-dart-notify/subject.pb.dart';
|
|||||||
import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-workspace/observable.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-workspace/observable.pb.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
|
||||||
|
import 'package:flowy_sdk/protobuf/flowy-workspace/view_delete.pb.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-workspace/view_query.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-workspace/view_query.pb.dart';
|
||||||
|
import 'package:flowy_sdk/protobuf/flowy-workspace/view_update.pb.dart';
|
||||||
import 'package:flowy_sdk/rust_stream.dart';
|
import 'package:flowy_sdk/rust_stream.dart';
|
||||||
|
|
||||||
import 'package:app_flowy/workspace/domain/i_view.dart';
|
import 'package:app_flowy/workspace/domain/i_view.dart';
|
||||||
@ -23,15 +25,38 @@ class ViewRepository {
|
|||||||
final request = QueryViewRequest.create()..viewId = view.id;
|
final request = QueryViewRequest.create()..viewId = view.id;
|
||||||
return WorkspaceEventReadView(request).send();
|
return WorkspaceEventReadView(request).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<Either<Unit, WorkspaceError>> updateView({String? name, String? desc, bool? isTrash}) {
|
||||||
|
final request = UpdateViewRequest.create()..viewId = view.id;
|
||||||
|
|
||||||
|
if (name != null) {
|
||||||
|
request.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ViewWatchRepository {
|
if (desc != null) {
|
||||||
|
request.desc = desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isTrash != null) {
|
||||||
|
request.isTrash = isTrash;
|
||||||
|
}
|
||||||
|
|
||||||
|
return WorkspaceEventUpdateView(request).send();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Either<Unit, WorkspaceError>> delete() {
|
||||||
|
final request = DeleteViewRequest.create()..viewId = view.id;
|
||||||
|
return WorkspaceEventDeleteView(request).send();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ViewListenerRepository {
|
||||||
StreamSubscription<ObservableSubject>? _subscription;
|
StreamSubscription<ObservableSubject>? _subscription;
|
||||||
ViewUpdatedCallback? _update;
|
ViewUpdatedCallback? _update;
|
||||||
late WorkspaceObservableParser _extractor;
|
late WorkspaceObservableParser _extractor;
|
||||||
View view;
|
View view;
|
||||||
|
|
||||||
ViewWatchRepository({
|
ViewListenerRepository({
|
||||||
required this.view,
|
required this.view,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -46,12 +71,10 @@ class ViewWatchRepository {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
_subscription =
|
_subscription = RustStreamReceiver.listen((observable) => _extractor.parse(observable));
|
||||||
RustStreamReceiver.listen((observable) => _extractor.parse(observable));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleObservableType(
|
void _handleObservableType(WorkspaceObservable ty, Either<Uint8List, WorkspaceError> result) {
|
||||||
WorkspaceObservable ty, Either<Uint8List, WorkspaceError> result) {
|
|
||||||
switch (ty) {
|
switch (ty) {
|
||||||
case WorkspaceObservable.ViewUpdated:
|
case WorkspaceObservable.ViewUpdated:
|
||||||
if (_update != null) {
|
if (_update != null) {
|
||||||
|
@ -62,7 +62,7 @@ class WorkspaceRepo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class WorkspaceWatchRepo {
|
class WorkspaceListenerRepo {
|
||||||
StreamSubscription<ObservableSubject>? _subscription;
|
StreamSubscription<ObservableSubject>? _subscription;
|
||||||
WorkspaceCreateAppCallback? _createApp;
|
WorkspaceCreateAppCallback? _createApp;
|
||||||
WorkspaceDeleteAppCallback? _deleteApp;
|
WorkspaceDeleteAppCallback? _deleteApp;
|
||||||
@ -71,12 +71,12 @@ class WorkspaceWatchRepo {
|
|||||||
final UserProfile user;
|
final UserProfile user;
|
||||||
final String workspaceId;
|
final String workspaceId;
|
||||||
|
|
||||||
WorkspaceWatchRepo({
|
WorkspaceListenerRepo({
|
||||||
required this.user,
|
required this.user,
|
||||||
required this.workspaceId,
|
required this.workspaceId,
|
||||||
});
|
});
|
||||||
|
|
||||||
void startWatching({
|
void startListen({
|
||||||
WorkspaceCreateAppCallback? createApp,
|
WorkspaceCreateAppCallback? createApp,
|
||||||
WorkspaceDeleteAppCallback? deleteApp,
|
WorkspaceDeleteAppCallback? deleteApp,
|
||||||
WorkspaceUpdatedCallback? update,
|
WorkspaceUpdatedCallback? update,
|
||||||
@ -92,12 +92,10 @@ class WorkspaceWatchRepo {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
_subscription =
|
_subscription = RustStreamReceiver.listen((observable) => _extractor.parse(observable));
|
||||||
RustStreamReceiver.listen((observable) => _extractor.parse(observable));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleObservableType(
|
void _handleObservableType(WorkspaceObservable ty, Either<Uint8List, WorkspaceError> result) {
|
||||||
WorkspaceObservable ty, Either<Uint8List, WorkspaceError> result) {
|
|
||||||
switch (ty) {
|
switch (ty) {
|
||||||
case WorkspaceObservable.WorkspaceUpdated:
|
case WorkspaceObservable.WorkspaceUpdated:
|
||||||
if (_update != null) {
|
if (_update != null) {
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
import 'package:app_flowy/startup/startup.dart';
|
||||||
|
import 'package:app_flowy/workspace/application/view/view_bloc.dart';
|
||||||
|
import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart';
|
||||||
import 'package:dartz/dartz.dart' as dartz;
|
import 'package:dartz/dartz.dart' as dartz;
|
||||||
import 'package:flowy_infra/image.dart';
|
import 'package:flowy_infra/image.dart';
|
||||||
import 'package:flowy_infra/theme.dart';
|
import 'package:flowy_infra/theme.dart';
|
||||||
@ -6,8 +9,10 @@ import 'package:flowy_infra_ui/style_widget/hover.dart';
|
|||||||
import 'package:flowy_infra_ui/style_widget/icon_button.dart';
|
import 'package:flowy_infra_ui/style_widget/icon_button.dart';
|
||||||
import 'package:flowy_infra_ui/style_widget/text.dart';
|
import 'package:flowy_infra_ui/style_widget/text.dart';
|
||||||
import 'package:flowy_infra_ui/widget/spacing.dart';
|
import 'package:flowy_infra_ui/widget/spacing.dart';
|
||||||
|
import 'package:flowy_log/flowy_log.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:styled_widget/styled_widget.dart';
|
import 'package:styled_widget/styled_widget.dart';
|
||||||
|
|
||||||
@ -15,105 +20,92 @@ import 'package:app_flowy/workspace/domain/image.dart';
|
|||||||
import 'package:app_flowy/workspace/domain/view_edit.dart';
|
import 'package:app_flowy/workspace/domain/view_edit.dart';
|
||||||
import 'package:app_flowy/workspace/presentation/widgets/menu/widget/app/menu_app.dart';
|
import 'package:app_flowy/workspace/presentation/widgets/menu/widget/app/menu_app.dart';
|
||||||
|
|
||||||
class ViewWidgetContext {
|
|
||||||
final View view;
|
|
||||||
ViewWidgetContext(this.view);
|
|
||||||
Key valueKey() => ValueKey("${view.id}${view.version}");
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef OpenViewCallback = void Function(View);
|
|
||||||
|
|
||||||
// ignore: must_be_immutable
|
// ignore: must_be_immutable
|
||||||
class ViewSectionItem extends StatefulWidget {
|
class ViewSectionItem extends StatelessWidget {
|
||||||
final ViewWidgetContext viewCtx;
|
final ViewBloc bloc;
|
||||||
final bool isSelected;
|
final void Function(View) onSelected;
|
||||||
final OpenViewCallback onOpen;
|
|
||||||
|
|
||||||
ViewSectionItem({
|
ViewSectionItem({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.viewCtx,
|
required View view,
|
||||||
required this.isSelected,
|
required bool isSelected,
|
||||||
required this.onOpen,
|
required this.onSelected,
|
||||||
}) : super(key: viewCtx.valueKey());
|
}) : bloc = getIt<ViewBloc>(param1: view),
|
||||||
|
super(key: ValueKey(view.id)) {
|
||||||
@override
|
bloc.add(ViewEvent.setIsSelected(isSelected));
|
||||||
State<ViewSectionItem> createState() => _ViewSectionItemState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// [[Widget: LifeCycle]]
|
|
||||||
// https://flutterbyexample.com/lesson/stateful-widget-lifecycle
|
|
||||||
class _ViewSectionItemState extends State<ViewSectionItem> {
|
|
||||||
bool isOnSelected = false;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = context.watch<AppTheme>();
|
final theme = context.watch<AppTheme>();
|
||||||
final config = HoverDisplayConfig(hoverColor: theme.bg3);
|
|
||||||
|
return BlocProvider.value(
|
||||||
|
value: bloc,
|
||||||
|
child: BlocListener<ViewBloc, ViewState>(
|
||||||
|
listenWhen: (p, c) => p.action != c.action,
|
||||||
|
listener: (context, state) {
|
||||||
|
state.action.fold(() => null, (action) {
|
||||||
|
Log.info('$action');
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: BlocBuilder<ViewBloc, ViewState>(
|
||||||
|
builder: (context, state) {
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: _openView(context),
|
onTap: () => onSelected(context.read<ViewBloc>().state.view),
|
||||||
child: FlowyHover(
|
child: FlowyHover(
|
||||||
config: config,
|
config: HoverDisplayConfig(hoverColor: theme.bg3),
|
||||||
builder: (context, onHover) => _render(context, onHover, config),
|
builder: (context, onHover) => _render(context, onHover),
|
||||||
isOnSelected: () => isOnSelected || widget.isSelected,
|
isOnSelected: () => state.isEditing || state.isSelected,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _render(BuildContext context, bool onHover, HoverDisplayConfig config) {
|
Widget _render(BuildContext context, bool onHover) {
|
||||||
|
final state = context.read<ViewBloc>().state;
|
||||||
List<Widget> children = [
|
List<Widget> children = [
|
||||||
SizedBox(
|
SizedBox(width: 16, height: 16, child: state.view.thumbnail()),
|
||||||
width: 16,
|
|
||||||
height: 16,
|
|
||||||
child: svgForViewType(widget.viewCtx.view.viewType),
|
|
||||||
),
|
|
||||||
const HSpace(6),
|
const HSpace(6),
|
||||||
FlowyText.regular(
|
FlowyText.regular(state.view.name, fontSize: 12),
|
||||||
widget.viewCtx.view.name,
|
|
||||||
fontSize: 12,
|
|
||||||
),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
if (onHover || isOnSelected) {
|
if (onHover || state.isEditing) {
|
||||||
children.add(const Spacer());
|
children.add(const Spacer());
|
||||||
children.add(ViewDisclosureButton(
|
children.add(ViewDisclosureButton(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(
|
context.read<ViewBloc>().add(const ViewEvent.setIsEditing(true));
|
||||||
() => isOnSelected = true,
|
getIt<HomeStackManager>().setStack(state.view.intoStackContext());
|
||||||
);
|
|
||||||
},
|
},
|
||||||
onSelected: (selected) {
|
onSelected: (action) {
|
||||||
selected.fold(() => null, (action) {
|
context.read<ViewBloc>().add(const ViewEvent.setIsEditing(false));
|
||||||
debugPrint('$action.name');
|
context.read<ViewBloc>().add(ViewEvent.setAction(action));
|
||||||
});
|
|
||||||
setState(() {
|
|
||||||
isOnSelected = false;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Container(
|
return SizedBox(
|
||||||
|
height: 24,
|
||||||
child: Row(children: children).padding(
|
child: Row(children: children).padding(
|
||||||
left: MenuAppSizes.expandedPadding,
|
left: MenuAppSizes.expandedPadding,
|
||||||
right: MenuAppSizes.expandedIconPadding,
|
right: MenuAppSizes.expandedIconPadding,
|
||||||
),
|
),
|
||||||
height: 24,
|
|
||||||
alignment: Alignment.centerLeft,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Function() _openView(BuildContext context) {
|
// [[Widget: LifeCycle]]
|
||||||
return () => widget.onOpen(widget.viewCtx.view);
|
// https://flutterbyexample.com/lesson/stateful-widget-lifecycle
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ViewDisclosureButton extends StatelessWidget {
|
class ViewDisclosureButton extends StatelessWidget {
|
||||||
final Function(dartz.Option<ViewAction>) onSelected;
|
|
||||||
final Function() onTap;
|
final Function() onTap;
|
||||||
|
final Function(dartz.Option<ViewAction>) onSelected;
|
||||||
const ViewDisclosureButton({
|
const ViewDisclosureButton({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.onSelected,
|
|
||||||
required this.onTap,
|
required this.onTap,
|
||||||
|
required this.onSelected,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -140,16 +132,15 @@ class ViewActionList implements FlowyOverlayDelegate {
|
|||||||
const ViewActionList({required this.anchorContext, required this.onSelected});
|
const ViewActionList({required this.anchorContext, required this.onSelected});
|
||||||
|
|
||||||
void show(BuildContext buildContext) {
|
void show(BuildContext buildContext) {
|
||||||
final items = ViewAction.values.map((action) {
|
final items = ViewAction.values
|
||||||
return ActionItem(
|
.map((action) => ActionItem(
|
||||||
action: action,
|
action: action,
|
||||||
onSelected: (action) {
|
onSelected: (action) {
|
||||||
FlowyOverlay.of(buildContext).remove(_identifier);
|
FlowyOverlay.of(buildContext).remove(_identifier);
|
||||||
onSelected(dartz.some(action));
|
onSelected(dartz.some(action));
|
||||||
});
|
}))
|
||||||
}).toList();
|
.toList();
|
||||||
|
|
||||||
// TODO: make sure the delegate of this wouldn't cause retain cycle
|
|
||||||
ListOverlay.showWithAnchor(
|
ListOverlay.showWithAnchor(
|
||||||
buildContext,
|
buildContext,
|
||||||
identifier: _identifier,
|
identifier: _identifier,
|
||||||
@ -181,17 +172,19 @@ class ActionItem extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = context.watch<AppTheme>();
|
final theme = context.watch<AppTheme>();
|
||||||
final config = HoverDisplayConfig(hoverColor: theme.hover);
|
|
||||||
|
|
||||||
return FlowyHover(
|
return FlowyHover(
|
||||||
config: config,
|
config: HoverDisplayConfig(hoverColor: theme.hover),
|
||||||
builder: (context, onHover) {
|
builder: (context, onHover) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () => onSelected(action),
|
onTap: () => onSelected(action),
|
||||||
child: FlowyText.medium(
|
child: FlowyText.medium(
|
||||||
action.name,
|
action.name,
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
).padding(horizontal: 10, vertical: 6),
|
).padding(
|
||||||
|
horizontal: 10,
|
||||||
|
vertical: 6,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
import 'package:flowy_log/flowy_log.dart';
|
|
||||||
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:app_flowy/startup/startup.dart';
|
|
||||||
import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart';
|
|
||||||
import 'item.dart';
|
import 'item.dart';
|
||||||
|
|
||||||
class ViewListNotifier extends ChangeNotifier {
|
class ViewListNotifier extends ChangeNotifier {
|
||||||
@ -49,32 +46,26 @@ class ViewSection extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// The ViewListNotifier will be updated after ViewListData changed passed by parent widget
|
// The ViewListNotifier will be updated after ViewListData changed passed by parent widget
|
||||||
return ChangeNotifierProxyProvider<ViewListNotifier, ViewSectionNotifier>(
|
return ChangeNotifierProxyProvider<ViewListNotifier, ViewSectionNotifier>(
|
||||||
create: (_) => ViewSectionNotifier(
|
create: (_) {
|
||||||
Provider.of<ViewListNotifier>(
|
final views = Provider.of<ViewListNotifier>(
|
||||||
context,
|
context,
|
||||||
listen: false,
|
listen: false,
|
||||||
).items,
|
).items;
|
||||||
),
|
return ViewSectionNotifier(views);
|
||||||
|
},
|
||||||
update: (_, notifier, controller) => controller!..update(notifier),
|
update: (_, notifier, controller) => controller!..update(notifier),
|
||||||
child: Consumer(builder: (context, ViewSectionNotifier notifier, child) {
|
child: Consumer(builder: (context, ViewSectionNotifier notifier, child) {
|
||||||
return _renderItems(context, notifier.views);
|
return _renderSectionItems(context, notifier.views);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _renderItems(BuildContext context, List<View> views) {
|
Widget _renderSectionItems(BuildContext context, List<View> views) {
|
||||||
var viewWidgets = views.map((view) {
|
var viewWidgets = views.map((view) {
|
||||||
final viewCtx = ViewWidgetContext(view);
|
|
||||||
|
|
||||||
final item = ViewSectionItem(
|
final item = ViewSectionItem(
|
||||||
viewCtx: viewCtx,
|
view: view,
|
||||||
isSelected: _isViewSelected(context, view.id),
|
isSelected: _isViewSelected(context, view.id),
|
||||||
onOpen: (view) {
|
onSelected: (view) => context.read<ViewSectionNotifier>().setSelectedView(view),
|
||||||
Log.debug("Open: $view");
|
|
||||||
context.read<ViewSectionNotifier>().setSelectedView(view);
|
|
||||||
final stackView = stackCtxFromView(viewCtx.view);
|
|
||||||
getIt<HomeStackManager>().setStack(stackView);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
@ -83,17 +74,14 @@ class ViewSection extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}).toList(growable: false);
|
}).toList(growable: false);
|
||||||
|
|
||||||
return Column(
|
return Column(children: viewWidgets);
|
||||||
children: viewWidgets,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _isViewSelected(BuildContext context, String viewId) {
|
bool _isViewSelected(BuildContext context, String viewId) {
|
||||||
final view = context.read<ViewSectionNotifier>().selectedView;
|
final view = context.read<ViewSectionNotifier>().selectedView;
|
||||||
if (view != null) {
|
if (view == null) {
|
||||||
return view.id == viewId;
|
|
||||||
} else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return view.id == viewId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user