diff --git a/app_flowy/lib/workspace/application/menu/menu_bloc.dart b/app_flowy/lib/workspace/application/menu/menu_bloc.dart index db271c6e44..39e2e09c2b 100644 --- a/app_flowy/lib/workspace/application/menu/menu_bloc.dart +++ b/app_flowy/lib/workspace/application/menu/menu_bloc.dart @@ -36,7 +36,7 @@ class MenuBloc extends Bloc { } Stream _performActionOnOpenPage(OpenPage e) async* { - yield state.copyWith(pageContext: e.context); + yield state.copyWith(stackView: e.stackView); } Stream _performActionOnCreateApp(CreateApp event) async* { @@ -65,7 +65,7 @@ class MenuBloc extends Bloc { abstract class MenuEvent with _$MenuEvent { const factory MenuEvent.initial() = _Initial; const factory MenuEvent.collapse() = Collapse; - const factory MenuEvent.openPage(HomeStackContext context) = OpenPage; + const factory MenuEvent.openPage(HomeStackView stackView) = OpenPage; const factory MenuEvent.createApp(String name, {String? desc}) = CreateApp; } @@ -75,7 +75,7 @@ abstract class MenuState implements _$MenuState { required bool isCollapse, required Option> apps, required Either successOrFailure, - HomeStackContext? pageContext, + HomeStackView? stackView, }) = _MenuState; factory MenuState.initial() => MenuState( diff --git a/app_flowy/lib/workspace/application/menu/menu_bloc.freezed.dart b/app_flowy/lib/workspace/application/menu/menu_bloc.freezed.dart index 8a8a73c583..fda402a807 100644 --- a/app_flowy/lib/workspace/application/menu/menu_bloc.freezed.dart +++ b/app_flowy/lib/workspace/application/menu/menu_bloc.freezed.dart @@ -24,9 +24,9 @@ class _$MenuEventTearOff { return const Collapse(); } - OpenPage openPage(HomeStackContext context) { + OpenPage openPage(HomeStackView stackView) { return OpenPage( - context, + stackView, ); } @@ -47,7 +47,7 @@ mixin _$MenuEvent { TResult when({ required TResult Function() initial, required TResult Function() collapse, - required TResult Function(HomeStackContext context) openPage, + required TResult Function(HomeStackView stackView) openPage, required TResult Function(String name, String? desc) createApp, }) => throw _privateConstructorUsedError; @@ -55,7 +55,7 @@ mixin _$MenuEvent { TResult maybeWhen({ TResult Function()? initial, TResult Function()? collapse, - TResult Function(HomeStackContext context)? openPage, + TResult Function(HomeStackView stackView)? openPage, TResult Function(String name, String? desc)? createApp, required TResult orElse(), }) => @@ -133,7 +133,7 @@ class _$_Initial implements _Initial { TResult when({ required TResult Function() initial, required TResult Function() collapse, - required TResult Function(HomeStackContext context) openPage, + required TResult Function(HomeStackView stackView) openPage, required TResult Function(String name, String? desc) createApp, }) { return initial(); @@ -144,7 +144,7 @@ class _$_Initial implements _Initial { TResult maybeWhen({ TResult Function()? initial, TResult Function()? collapse, - TResult Function(HomeStackContext context)? openPage, + TResult Function(HomeStackView stackView)? openPage, TResult Function(String name, String? desc)? createApp, required TResult orElse(), }) { @@ -224,7 +224,7 @@ class _$Collapse implements Collapse { TResult when({ required TResult Function() initial, required TResult Function() collapse, - required TResult Function(HomeStackContext context) openPage, + required TResult Function(HomeStackView stackView) openPage, required TResult Function(String name, String? desc) createApp, }) { return collapse(); @@ -235,7 +235,7 @@ class _$Collapse implements Collapse { TResult maybeWhen({ TResult Function()? initial, TResult Function()? collapse, - TResult Function(HomeStackContext context)? openPage, + TResult Function(HomeStackView stackView)? openPage, TResult Function(String name, String? desc)? createApp, required TResult orElse(), }) { @@ -280,7 +280,7 @@ abstract class Collapse implements MenuEvent { abstract class $OpenPageCopyWith<$Res> { factory $OpenPageCopyWith(OpenPage value, $Res Function(OpenPage) then) = _$OpenPageCopyWithImpl<$Res>; - $Res call({HomeStackContext context}); + $Res call({HomeStackView stackView}); } /// @nodoc @@ -294,13 +294,13 @@ class _$OpenPageCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res> @override $Res call({ - Object? context = freezed, + Object? stackView = freezed, }) { return _then(OpenPage( - context == freezed - ? _value.context - : context // ignore: cast_nullable_to_non_nullable - as HomeStackContext, + stackView == freezed + ? _value.stackView + : stackView // ignore: cast_nullable_to_non_nullable + as HomeStackView, )); } } @@ -308,27 +308,28 @@ class _$OpenPageCopyWithImpl<$Res> extends _$MenuEventCopyWithImpl<$Res> /// @nodoc class _$OpenPage implements OpenPage { - const _$OpenPage(this.context); + const _$OpenPage(this.stackView); @override - final HomeStackContext context; + final HomeStackView stackView; @override String toString() { - return 'MenuEvent.openPage(context: $context)'; + return 'MenuEvent.openPage(stackView: $stackView)'; } @override bool operator ==(dynamic other) { return identical(this, other) || (other is OpenPage && - (identical(other.context, context) || - const DeepCollectionEquality().equals(other.context, context))); + (identical(other.stackView, stackView) || + const DeepCollectionEquality() + .equals(other.stackView, stackView))); } @override int get hashCode => - runtimeType.hashCode ^ const DeepCollectionEquality().hash(context); + runtimeType.hashCode ^ const DeepCollectionEquality().hash(stackView); @JsonKey(ignore: true) @override @@ -340,10 +341,10 @@ class _$OpenPage implements OpenPage { TResult when({ required TResult Function() initial, required TResult Function() collapse, - required TResult Function(HomeStackContext context) openPage, + required TResult Function(HomeStackView stackView) openPage, required TResult Function(String name, String? desc) createApp, }) { - return openPage(context); + return openPage(stackView); } @override @@ -351,12 +352,12 @@ class _$OpenPage implements OpenPage { TResult maybeWhen({ TResult Function()? initial, TResult Function()? collapse, - TResult Function(HomeStackContext context)? openPage, + TResult Function(HomeStackView stackView)? openPage, TResult Function(String name, String? desc)? createApp, required TResult orElse(), }) { if (openPage != null) { - return openPage(context); + return openPage(stackView); } return orElse(); } @@ -389,9 +390,9 @@ class _$OpenPage implements OpenPage { } abstract class OpenPage implements MenuEvent { - const factory OpenPage(HomeStackContext context) = _$OpenPage; + const factory OpenPage(HomeStackView stackView) = _$OpenPage; - HomeStackContext get context => throw _privateConstructorUsedError; + HomeStackView get stackView => throw _privateConstructorUsedError; @JsonKey(ignore: true) $OpenPageCopyWith get copyWith => throw _privateConstructorUsedError; @@ -472,7 +473,7 @@ class _$CreateApp implements CreateApp { TResult when({ required TResult Function() initial, required TResult Function() collapse, - required TResult Function(HomeStackContext context) openPage, + required TResult Function(HomeStackView stackView) openPage, required TResult Function(String name, String? desc) createApp, }) { return createApp(name, desc); @@ -483,7 +484,7 @@ class _$CreateApp implements CreateApp { TResult maybeWhen({ TResult Function()? initial, TResult Function()? collapse, - TResult Function(HomeStackContext context)? openPage, + TResult Function(HomeStackView stackView)? openPage, TResult Function(String name, String? desc)? createApp, required TResult orElse(), }) { @@ -538,12 +539,12 @@ class _$MenuStateTearOff { {required bool isCollapse, required Option> apps, required Either successOrFailure, - HomeStackContext? pageContext}) { + HomeStackView? stackView}) { return _MenuState( isCollapse: isCollapse, apps: apps, successOrFailure: successOrFailure, - pageContext: pageContext, + stackView: stackView, ); } } @@ -557,7 +558,7 @@ mixin _$MenuState { Option> get apps => throw _privateConstructorUsedError; Either get successOrFailure => throw _privateConstructorUsedError; - HomeStackContext? get pageContext => throw _privateConstructorUsedError; + HomeStackView? get stackView => throw _privateConstructorUsedError; @JsonKey(ignore: true) $MenuStateCopyWith get copyWith => @@ -572,7 +573,7 @@ abstract class $MenuStateCopyWith<$Res> { {bool isCollapse, Option> apps, Either successOrFailure, - HomeStackContext? pageContext}); + HomeStackView? stackView}); } /// @nodoc @@ -588,7 +589,7 @@ class _$MenuStateCopyWithImpl<$Res> implements $MenuStateCopyWith<$Res> { Object? isCollapse = freezed, Object? apps = freezed, Object? successOrFailure = freezed, - Object? pageContext = freezed, + Object? stackView = freezed, }) { return _then(_value.copyWith( isCollapse: isCollapse == freezed @@ -603,10 +604,10 @@ class _$MenuStateCopyWithImpl<$Res> implements $MenuStateCopyWith<$Res> { ? _value.successOrFailure : successOrFailure // ignore: cast_nullable_to_non_nullable as Either, - pageContext: pageContext == freezed - ? _value.pageContext - : pageContext // ignore: cast_nullable_to_non_nullable - as HomeStackContext?, + stackView: stackView == freezed + ? _value.stackView + : stackView // ignore: cast_nullable_to_non_nullable + as HomeStackView?, )); } } @@ -621,7 +622,7 @@ abstract class _$MenuStateCopyWith<$Res> implements $MenuStateCopyWith<$Res> { {bool isCollapse, Option> apps, Either successOrFailure, - HomeStackContext? pageContext}); + HomeStackView? stackView}); } /// @nodoc @@ -638,7 +639,7 @@ class __$MenuStateCopyWithImpl<$Res> extends _$MenuStateCopyWithImpl<$Res> Object? isCollapse = freezed, Object? apps = freezed, Object? successOrFailure = freezed, - Object? pageContext = freezed, + Object? stackView = freezed, }) { return _then(_MenuState( isCollapse: isCollapse == freezed @@ -653,10 +654,10 @@ class __$MenuStateCopyWithImpl<$Res> extends _$MenuStateCopyWithImpl<$Res> ? _value.successOrFailure : successOrFailure // ignore: cast_nullable_to_non_nullable as Either, - pageContext: pageContext == freezed - ? _value.pageContext - : pageContext // ignore: cast_nullable_to_non_nullable - as HomeStackContext?, + stackView: stackView == freezed + ? _value.stackView + : stackView // ignore: cast_nullable_to_non_nullable + as HomeStackView?, )); } } @@ -668,7 +669,7 @@ class _$_MenuState implements _MenuState { {required this.isCollapse, required this.apps, required this.successOrFailure, - this.pageContext}); + this.stackView}); @override final bool isCollapse; @@ -677,11 +678,11 @@ class _$_MenuState implements _MenuState { @override final Either successOrFailure; @override - final HomeStackContext? pageContext; + final HomeStackView? stackView; @override String toString() { - return 'MenuState(isCollapse: $isCollapse, apps: $apps, successOrFailure: $successOrFailure, pageContext: $pageContext)'; + return 'MenuState(isCollapse: $isCollapse, apps: $apps, successOrFailure: $successOrFailure, stackView: $stackView)'; } @override @@ -696,9 +697,9 @@ class _$_MenuState implements _MenuState { (identical(other.successOrFailure, successOrFailure) || const DeepCollectionEquality() .equals(other.successOrFailure, successOrFailure)) && - (identical(other.pageContext, pageContext) || + (identical(other.stackView, stackView) || const DeepCollectionEquality() - .equals(other.pageContext, pageContext))); + .equals(other.stackView, stackView))); } @override @@ -707,7 +708,7 @@ class _$_MenuState implements _MenuState { const DeepCollectionEquality().hash(isCollapse) ^ const DeepCollectionEquality().hash(apps) ^ const DeepCollectionEquality().hash(successOrFailure) ^ - const DeepCollectionEquality().hash(pageContext); + const DeepCollectionEquality().hash(stackView); @JsonKey(ignore: true) @override @@ -720,7 +721,7 @@ abstract class _MenuState implements MenuState { {required bool isCollapse, required Option> apps, required Either successOrFailure, - HomeStackContext? pageContext}) = _$_MenuState; + HomeStackView? stackView}) = _$_MenuState; @override bool get isCollapse => throw _privateConstructorUsedError; @@ -730,7 +731,7 @@ abstract class _MenuState implements MenuState { Either get successOrFailure => throw _privateConstructorUsedError; @override - HomeStackContext? get pageContext => throw _privateConstructorUsedError; + HomeStackView? get stackView => throw _privateConstructorUsedError; @override @JsonKey(ignore: true) _$MenuStateCopyWith<_MenuState> get copyWith => diff --git a/app_flowy/lib/workspace/domain/i_page_stack.dart b/app_flowy/lib/workspace/domain/i_page_stack.dart index 00077f9d38..422ed2aeda 100644 --- a/app_flowy/lib/workspace/domain/i_page_stack.dart +++ b/app_flowy/lib/workspace/domain/i_page_stack.dart @@ -1,5 +1,5 @@ import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; abstract class IPageStack { - void setPageContext(HomeStackContext context); + void setPageContext(HomeStackView context); } diff --git a/app_flowy/lib/workspace/domain/page_stack/page_stack.dart b/app_flowy/lib/workspace/domain/page_stack/page_stack.dart index 8d8aac8644..4c861171db 100644 --- a/app_flowy/lib/workspace/domain/page_stack/page_stack.dart +++ b/app_flowy/lib/workspace/domain/page_stack/page_stack.dart @@ -1,4 +1,5 @@ import 'package:app_flowy/workspace/domain/page_stack/page_stack_bloc.dart'; +import 'package:app_flowy/workspace/presentation/doc/doc_widget.dart'; import 'package:equatable/equatable.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; import 'package:flutter/material.dart'; @@ -7,12 +8,10 @@ import 'package:app_flowy/workspace/presentation/widgets/fading_index_stack.dart import 'package:app_flowy/workspace/presentation/widgets/prelude.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -List pages = ViewType.values.toList(); - -abstract class HomeStackContext extends Equatable { +abstract class HomeStackView extends Equatable { final ViewType type; final String title; - const HomeStackContext({required this.type, required this.title}); + const HomeStackView({required this.type, required this.title}); } class HomePageStack { @@ -20,11 +19,11 @@ class HomePageStack { HomePageStack(); String title() { - return _bloc.state.pageContext.title; + return _bloc.state.stackView.title; } - void setPageContext(HomeStackContext? newContext) { - _bloc.add(PageStackEvent.setContext(newContext ?? BlankPageContext())); + void setStackView(HomeStackView? stackView) { + _bloc.add(PageStackEvent.setStackView(stackView ?? const BlankStackView())); } Widget stackTopBar() { @@ -33,7 +32,7 @@ class HomePageStack { child: BlocBuilder( builder: (context, state) { return HomeTopBar( - title: state.pageContext.title, + title: state.stackView.title, ); }, ), @@ -45,10 +44,9 @@ class HomePageStack { create: (context) => _bloc, child: BlocBuilder( builder: (context, state) { - final pageContext = state.pageContext; return FadingIndexedStack( - index: pages.indexOf(pageContext.type), - children: buildPagesWidget(pageContext), + index: pages.indexOf(state.stackView.type), + children: _buildStackWidget(state.stackView), ); }, ), @@ -56,31 +54,37 @@ class HomePageStack { } } -List buildPagesWidget(HomeStackContext pageContext) { +List pages = ViewType.values.toList(); + +List _buildStackWidget(HomeStackView stackView) { return ViewType.values.map((viewType) { - if (viewType == pageContext.type) { - return viewType.builderDisplayWidget(pageContext); + if (viewType == stackView.type) { + switch (stackView.type) { + case ViewType.Blank: + return BlankPage(stackView: stackView as BlankStackView); + case ViewType.Doc: + return DocPage(stackView: stackView as DocPageContext); + default: + return BlankPage(stackView: stackView as BlankStackView); + } } else { - return const BlankPage(context: BlankPageContext()); + return const BlankPage(stackView: BlankStackView()); } }).toList(); } -extension PageTypeExtension on ViewType { - HomeStackWidget builderDisplayWidget(HomeStackContext context) { - switch (this) { - case ViewType.Blank: - return BlankPage(context: context as BlankPageContext); - case ViewType.Doc: - return BlankPage(context: context as BlankPageContext); - default: - return BlankPage(context: context as BlankPageContext); - } +HomeStackView stackViewFromView(View view) { + switch (view.viewType) { + case ViewType.Blank: + return const BlankStackView(); + case ViewType.Doc: + return DocPageContext(view); + default: + return const BlankStackView(); } } abstract class HomeStackWidget extends StatefulWidget { - final HomeStackContext pageContext; - const HomeStackWidget({Key? key, required this.pageContext}) - : super(key: key); + final HomeStackView stackView; + const HomeStackWidget({Key? key, required this.stackView}) : super(key: key); } diff --git a/app_flowy/lib/workspace/domain/page_stack/page_stack_bloc.dart b/app_flowy/lib/workspace/domain/page_stack/page_stack_bloc.dart index 505aeff989..9d43af2d05 100644 --- a/app_flowy/lib/workspace/domain/page_stack/page_stack_bloc.dart +++ b/app_flowy/lib/workspace/domain/page_stack/page_stack_bloc.dart @@ -11,25 +11,25 @@ class PageStackBloc extends Bloc { Stream mapEventToState( PageStackEvent event, ) async* { - yield* event.map(setContext: (NewPageContext value) async* { - yield state.copyWith(pageContext: value.newContext); + yield* event.map(setStackView: (NewPageContext value) async* { + yield state.copyWith(stackView: value.newStackView); }); } } @freezed abstract class PageStackEvent with _$PageStackEvent { - const factory PageStackEvent.setContext(HomeStackContext newContext) = + const factory PageStackEvent.setStackView(HomeStackView newStackView) = NewPageContext; } @freezed abstract class PageStackState implements _$PageStackState { const factory PageStackState({ - required HomeStackContext pageContext, + required HomeStackView stackView, }) = _PageStackState; factory PageStackState.initial() => const PageStackState( - pageContext: BlankPageContext(), + stackView: BlankStackView(), ); } diff --git a/app_flowy/lib/workspace/domain/page_stack/page_stack_bloc.freezed.dart b/app_flowy/lib/workspace/domain/page_stack/page_stack_bloc.freezed.dart index 47e9d05548..2a7a0345d2 100644 --- a/app_flowy/lib/workspace/domain/page_stack/page_stack_bloc.freezed.dart +++ b/app_flowy/lib/workspace/domain/page_stack/page_stack_bloc.freezed.dart @@ -16,9 +16,9 @@ final _privateConstructorUsedError = UnsupportedError( class _$PageStackEventTearOff { const _$PageStackEventTearOff(); - NewPageContext setContext(HomeStackContext newContext) { + NewPageContext setStackView(HomeStackView newStackView) { return NewPageContext( - newContext, + newStackView, ); } } @@ -28,27 +28,27 @@ const $PageStackEvent = _$PageStackEventTearOff(); /// @nodoc mixin _$PageStackEvent { - HomeStackContext get newContext => throw _privateConstructorUsedError; + HomeStackView get newStackView => throw _privateConstructorUsedError; @optionalTypeArgs TResult when({ - required TResult Function(HomeStackContext newContext) setContext, + required TResult Function(HomeStackView newStackView) setStackView, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeWhen({ - TResult Function(HomeStackContext newContext)? setContext, + TResult Function(HomeStackView newStackView)? setStackView, required TResult orElse(), }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult map({ - required TResult Function(NewPageContext value) setContext, + required TResult Function(NewPageContext value) setStackView, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeMap({ - TResult Function(NewPageContext value)? setContext, + TResult Function(NewPageContext value)? setStackView, required TResult orElse(), }) => throw _privateConstructorUsedError; @@ -63,7 +63,7 @@ abstract class $PageStackEventCopyWith<$Res> { factory $PageStackEventCopyWith( PageStackEvent value, $Res Function(PageStackEvent) then) = _$PageStackEventCopyWithImpl<$Res>; - $Res call({HomeStackContext newContext}); + $Res call({HomeStackView newStackView}); } /// @nodoc @@ -77,13 +77,13 @@ class _$PageStackEventCopyWithImpl<$Res> @override $Res call({ - Object? newContext = freezed, + Object? newStackView = freezed, }) { return _then(_value.copyWith( - newContext: newContext == freezed - ? _value.newContext - : newContext // ignore: cast_nullable_to_non_nullable - as HomeStackContext, + newStackView: newStackView == freezed + ? _value.newStackView + : newStackView // ignore: cast_nullable_to_non_nullable + as HomeStackView, )); } } @@ -95,7 +95,7 @@ abstract class $NewPageContextCopyWith<$Res> NewPageContext value, $Res Function(NewPageContext) then) = _$NewPageContextCopyWithImpl<$Res>; @override - $Res call({HomeStackContext newContext}); + $Res call({HomeStackView newStackView}); } /// @nodoc @@ -111,13 +111,13 @@ class _$NewPageContextCopyWithImpl<$Res> @override $Res call({ - Object? newContext = freezed, + Object? newStackView = freezed, }) { return _then(NewPageContext( - newContext == freezed - ? _value.newContext - : newContext // ignore: cast_nullable_to_non_nullable - as HomeStackContext, + newStackView == freezed + ? _value.newStackView + : newStackView // ignore: cast_nullable_to_non_nullable + as HomeStackView, )); } } @@ -125,28 +125,28 @@ class _$NewPageContextCopyWithImpl<$Res> /// @nodoc class _$NewPageContext implements NewPageContext { - const _$NewPageContext(this.newContext); + const _$NewPageContext(this.newStackView); @override - final HomeStackContext newContext; + final HomeStackView newStackView; @override String toString() { - return 'PageStackEvent.setContext(newContext: $newContext)'; + return 'PageStackEvent.setStackView(newStackView: $newStackView)'; } @override bool operator ==(dynamic other) { return identical(this, other) || (other is NewPageContext && - (identical(other.newContext, newContext) || + (identical(other.newStackView, newStackView) || const DeepCollectionEquality() - .equals(other.newContext, newContext))); + .equals(other.newStackView, newStackView))); } @override int get hashCode => - runtimeType.hashCode ^ const DeepCollectionEquality().hash(newContext); + runtimeType.hashCode ^ const DeepCollectionEquality().hash(newStackView); @JsonKey(ignore: true) @override @@ -156,19 +156,19 @@ class _$NewPageContext implements NewPageContext { @override @optionalTypeArgs TResult when({ - required TResult Function(HomeStackContext newContext) setContext, + required TResult Function(HomeStackView newStackView) setStackView, }) { - return setContext(newContext); + return setStackView(newStackView); } @override @optionalTypeArgs TResult maybeWhen({ - TResult Function(HomeStackContext newContext)? setContext, + TResult Function(HomeStackView newStackView)? setStackView, required TResult orElse(), }) { - if (setContext != null) { - return setContext(newContext); + if (setStackView != null) { + return setStackView(newStackView); } return orElse(); } @@ -176,29 +176,29 @@ class _$NewPageContext implements NewPageContext { @override @optionalTypeArgs TResult map({ - required TResult Function(NewPageContext value) setContext, + required TResult Function(NewPageContext value) setStackView, }) { - return setContext(this); + return setStackView(this); } @override @optionalTypeArgs TResult maybeMap({ - TResult Function(NewPageContext value)? setContext, + TResult Function(NewPageContext value)? setStackView, required TResult orElse(), }) { - if (setContext != null) { - return setContext(this); + if (setStackView != null) { + return setStackView(this); } return orElse(); } } abstract class NewPageContext implements PageStackEvent { - const factory NewPageContext(HomeStackContext newContext) = _$NewPageContext; + const factory NewPageContext(HomeStackView newStackView) = _$NewPageContext; @override - HomeStackContext get newContext => throw _privateConstructorUsedError; + HomeStackView get newStackView => throw _privateConstructorUsedError; @override @JsonKey(ignore: true) $NewPageContextCopyWith get copyWith => @@ -209,9 +209,9 @@ abstract class NewPageContext implements PageStackEvent { class _$PageStackStateTearOff { const _$PageStackStateTearOff(); - _PageStackState call({required HomeStackContext pageContext}) { + _PageStackState call({required HomeStackView stackView}) { return _PageStackState( - pageContext: pageContext, + stackView: stackView, ); } } @@ -221,7 +221,7 @@ const $PageStackState = _$PageStackStateTearOff(); /// @nodoc mixin _$PageStackState { - HomeStackContext get pageContext => throw _privateConstructorUsedError; + HomeStackView get stackView => throw _privateConstructorUsedError; @JsonKey(ignore: true) $PageStackStateCopyWith get copyWith => @@ -233,7 +233,7 @@ abstract class $PageStackStateCopyWith<$Res> { factory $PageStackStateCopyWith( PageStackState value, $Res Function(PageStackState) then) = _$PageStackStateCopyWithImpl<$Res>; - $Res call({HomeStackContext pageContext}); + $Res call({HomeStackView stackView}); } /// @nodoc @@ -247,13 +247,13 @@ class _$PageStackStateCopyWithImpl<$Res> @override $Res call({ - Object? pageContext = freezed, + Object? stackView = freezed, }) { return _then(_value.copyWith( - pageContext: pageContext == freezed - ? _value.pageContext - : pageContext // ignore: cast_nullable_to_non_nullable - as HomeStackContext, + stackView: stackView == freezed + ? _value.stackView + : stackView // ignore: cast_nullable_to_non_nullable + as HomeStackView, )); } } @@ -265,7 +265,7 @@ abstract class _$PageStackStateCopyWith<$Res> _PageStackState value, $Res Function(_PageStackState) then) = __$PageStackStateCopyWithImpl<$Res>; @override - $Res call({HomeStackContext pageContext}); + $Res call({HomeStackView stackView}); } /// @nodoc @@ -281,13 +281,13 @@ class __$PageStackStateCopyWithImpl<$Res> @override $Res call({ - Object? pageContext = freezed, + Object? stackView = freezed, }) { return _then(_PageStackState( - pageContext: pageContext == freezed - ? _value.pageContext - : pageContext // ignore: cast_nullable_to_non_nullable - as HomeStackContext, + stackView: stackView == freezed + ? _value.stackView + : stackView // ignore: cast_nullable_to_non_nullable + as HomeStackView, )); } } @@ -295,28 +295,28 @@ class __$PageStackStateCopyWithImpl<$Res> /// @nodoc class _$_PageStackState implements _PageStackState { - const _$_PageStackState({required this.pageContext}); + const _$_PageStackState({required this.stackView}); @override - final HomeStackContext pageContext; + final HomeStackView stackView; @override String toString() { - return 'PageStackState(pageContext: $pageContext)'; + return 'PageStackState(stackView: $stackView)'; } @override bool operator ==(dynamic other) { return identical(this, other) || (other is _PageStackState && - (identical(other.pageContext, pageContext) || + (identical(other.stackView, stackView) || const DeepCollectionEquality() - .equals(other.pageContext, pageContext))); + .equals(other.stackView, stackView))); } @override int get hashCode => - runtimeType.hashCode ^ const DeepCollectionEquality().hash(pageContext); + runtimeType.hashCode ^ const DeepCollectionEquality().hash(stackView); @JsonKey(ignore: true) @override @@ -325,11 +325,11 @@ class _$_PageStackState implements _PageStackState { } abstract class _PageStackState implements PageStackState { - const factory _PageStackState({required HomeStackContext pageContext}) = + const factory _PageStackState({required HomeStackView stackView}) = _$_PageStackState; @override - HomeStackContext get pageContext => throw _privateConstructorUsedError; + HomeStackView get stackView => throw _privateConstructorUsedError; @override @JsonKey(ignore: true) _$PageStackStateCopyWith<_PageStackState> get copyWith => diff --git a/app_flowy/lib/workspace/presentation/doc/doc_widget.dart b/app_flowy/lib/workspace/presentation/doc/doc_widget.dart index bf44a06c90..de288eedff 100644 --- a/app_flowy/lib/workspace/presentation/doc/doc_widget.dart +++ b/app_flowy/lib/workspace/presentation/doc/doc_widget.dart @@ -2,7 +2,7 @@ import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; import 'package:flutter/material.dart'; -class DocPageContext extends HomeStackContext { +class DocPageContext extends HomeStackView { final View view; DocPageContext(this.view) : super( @@ -15,8 +15,8 @@ class DocPageContext extends HomeStackContext { } class DocPage extends HomeStackWidget { - const DocPage({Key? key, required DocPageContext context}) - : super(key: key, pageContext: context); + const DocPage({Key? key, required DocPageContext stackView}) + : super(key: key, stackView: stackView); @override _DocPageState createState() => _DocPageState(); @@ -25,9 +25,9 @@ class DocPage extends HomeStackWidget { class _DocPageState extends State { @override Widget build(BuildContext context) { - assert(widget.pageContext is DocPageContext); + assert(widget.stackView is DocPageContext); - final context = widget.pageContext as DocPageContext; + final context = widget.stackView as DocPageContext; final filename = _extractFilename(context.view.id); return Container(); } diff --git a/app_flowy/lib/workspace/presentation/home/home_screen.dart b/app_flowy/lib/workspace/presentation/home/home_screen.dart index a828c8d3e6..36adc49748 100644 --- a/app_flowy/lib/workspace/presentation/home/home_screen.dart +++ b/app_flowy/lib/workspace/presentation/home/home_screen.dart @@ -69,7 +69,7 @@ class HomeScreen extends StatelessWidget { final homeBloc = context.read(); Widget homeMenu = HomeMenu( pageContextChanged: (pageContext) { - getIt().setPageContext(pageContext); + getIt().setStackView(pageContext); }, isCollapseChanged: (isCollapse) { homeBloc.add(HomeEvent.forceCollapse(isCollapse)); diff --git a/app_flowy/lib/workspace/presentation/view/view_widget.dart b/app_flowy/lib/workspace/presentation/view/view_widget.dart index 16d6d65a93..3ecd19c194 100644 --- a/app_flowy/lib/workspace/presentation/view/view_widget.dart +++ b/app_flowy/lib/workspace/presentation/view/view_widget.dart @@ -1,3 +1,5 @@ +import 'package:app_flowy/startup/startup.dart'; +import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; import 'package:flutter/material.dart'; @@ -10,7 +12,7 @@ class ViewWidget extends StatelessWidget { @override Widget build(BuildContext context) { return InkWell( - onTap: _handleTapOnView(context), + onTap: _openView(context), child: Container( height: 30, child: buildContent(), @@ -33,14 +35,10 @@ class ViewWidget extends StatelessWidget { ); } - Function() _handleTapOnView(BuildContext context) { + Function() _openView(BuildContext context) { return () { - // if (view.id.startsWith('doc')) { - // context.read().add(MenuEvent.openPage(DocPageContext(view))); - // return; - // } - - // context.read().add(MenuEvent.openPage(GridPageContext(view))); + final stackView = stackViewFromView(view); + getIt().setStackView(stackView); }; } } diff --git a/app_flowy/lib/workspace/presentation/widgets/blank_page.dart b/app_flowy/lib/workspace/presentation/widgets/blank_page.dart index 03264b8f02..e59df39502 100644 --- a/app_flowy/lib/workspace/presentation/widgets/blank_page.dart +++ b/app_flowy/lib/workspace/presentation/widgets/blank_page.dart @@ -2,16 +2,16 @@ import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; import 'package:flutter/material.dart'; -class BlankPageContext extends HomeStackContext { - const BlankPageContext() : super(type: ViewType.Blank, title: 'Blank'); +class BlankStackView extends HomeStackView { + const BlankStackView() : super(type: ViewType.Blank, title: 'Blank'); @override List get props => []; } class BlankPage extends HomeStackWidget { - const BlankPage({Key? key, required BlankPageContext context}) - : super(key: key, pageContext: context); + const BlankPage({Key? key, required BlankStackView stackView}) + : super(key: key, stackView: stackView); @override State createState() => _BlankPageState(); diff --git a/app_flowy/lib/workspace/presentation/widgets/home_stack_page.dart b/app_flowy/lib/workspace/presentation/widgets/home_stack_page.dart index a99b097c8f..e474c01a20 100644 --- a/app_flowy/lib/workspace/presentation/widgets/home_stack_page.dart +++ b/app_flowy/lib/workspace/presentation/widgets/home_stack_page.dart @@ -2,6 +2,6 @@ import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; import 'package:flutter/material.dart'; abstract class HomeStackPage extends StatefulWidget { - final HomeStackContext pageContext; + final HomeStackView pageContext; const HomeStackPage({Key? key, required this.pageContext}) : super(key: key); } diff --git a/app_flowy/lib/workspace/presentation/widgets/menu/menu.dart b/app_flowy/lib/workspace/presentation/widgets/menu/menu.dart index 22f61bb16f..6b211a968c 100644 --- a/app_flowy/lib/workspace/presentation/widgets/menu/menu.dart +++ b/app_flowy/lib/workspace/presentation/widgets/menu/menu.dart @@ -20,7 +20,7 @@ import 'package:textstyle_extensions/textstyle_extensions.dart'; import 'app_list.dart'; class HomeMenu extends StatelessWidget { - final Function(HomeStackContext?) pageContextChanged; + final Function(HomeStackView?) pageContextChanged; final Function(bool) isCollapseChanged; final String workspaceId; @@ -45,8 +45,8 @@ class HomeMenu extends StatelessWidget { child: MultiBlocListener( listeners: [ BlocListener( - listenWhen: (p, c) => p.pageContext != c.pageContext, - listener: (context, state) => pageContextChanged(state.pageContext), + listenWhen: (p, c) => p.stackView != c.stackView, + listener: (context, state) => pageContextChanged(state.stackView), ), BlocListener( listenWhen: (p, c) => p.isCollapse != c.isCollapse,