From 274666612362c8ef010ada80381a93109f22af7e Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Wed, 24 May 2023 10:45:28 +0800 Subject: [PATCH] feat: optimzie the hover block action (#2607) * feat: optimzie the hover block action * fix: duplicate view CI error --- .../actions/block_action_add_button.dart | 2 +- .../actions/block_action_list.dart | 2 +- .../actions/block_action_option_button.dart | 2 +- .../actions/option_action_button.dart | 2 +- .../board/board_node_widget.dart | 30 ++++++++++---- .../callout/callout_block_component.dart | 30 ++++++++++---- .../code_block/code_block_component.dart | 33 +++++++++++----- .../divider/divider_node_widget.dart | 39 ++++++++++++++----- .../editor_plugins/grid/grid_node_widget.dart | 30 ++++++++++---- .../math_equation_block_component.dart | 34 +++++++++++----- .../widgets/auto_completion_node_widget.dart | 16 +++++--- .../widgets/smart_edit_node_widget.dart | 18 ++++++--- .../toggle/toggle_block_component.dart | 21 ++++++---- frontend/appflowy_flutter/pubspec.lock | 4 +- frontend/appflowy_flutter/pubspec.yaml | 2 +- frontend/appflowy_flutter/test/util.dart | 6 ++- .../src/deps_resolve/folder2_deps.rs | 5 ++- 17 files changed, 194 insertions(+), 82 deletions(-) diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_add_button.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_add_button.dart index 017a1adbb4..f05c6244c8 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_add_button.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_add_button.dart @@ -12,7 +12,7 @@ class BlockAddButton extends StatelessWidget { }) : super(key: key); final BlockComponentContext blockComponentContext; - final BlockComponentState blockComponentState; + final BlockComponentActionState blockComponentState; final EditorState editorState; final VoidCallback showSlashMenu; diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_list.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_list.dart index 445e6f02b6..40ae6feb00 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_list.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_list.dart @@ -15,7 +15,7 @@ class BlockActionList extends StatelessWidget { }); final BlockComponentContext blockComponentContext; - final BlockComponentState blockComponentState; + final BlockComponentActionState blockComponentState; final List actions; final VoidCallback showSlashMenu; final EditorState editorState; diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_option_button.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_option_button.dart index 4b49a19220..d55ad9f6ed 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_option_button.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_option_button.dart @@ -17,7 +17,7 @@ class BlockOptionButton extends StatelessWidget { }) : super(key: key); final BlockComponentContext blockComponentContext; - final BlockComponentState blockComponentState; + final BlockComponentActionState blockComponentState; final List actions; final EditorState editorState; diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/option_action_button.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/option_action_button.dart index 3fbe11984b..cca05e45ae 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/option_action_button.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/option_action_button.dart @@ -16,7 +16,7 @@ class OptionActionList extends StatelessWidget { }) : super(key: key); final BlockComponentContext blockComponentContext; - final BlockComponentState blockComponentState; + final BlockComponentActionState blockComponentState; final List actions; final EditorState editorState; diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/board/board_node_widget.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/board/board_node_widget.dart index 39cdbc52fa..f17c96fd42 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/board/board_node_widget.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/board/board_node_widget.dart @@ -20,12 +20,17 @@ class BoardBlockComponentBuilder extends BlockComponentBuilder { final BlockComponentConfiguration configuration; @override - Widget build(BlockComponentContext blockComponentContext) { + BlockComponentWidget build(BlockComponentContext blockComponentContext) { final node = blockComponentContext.node; return BoardBlockComponentWidget( key: node.key, node: node, configuration: configuration, + showActions: showActions(node), + actionBuilder: (context, state) => actionBuilder( + blockComponentContext, + state, + ), ); } @@ -36,16 +41,15 @@ class BoardBlockComponentBuilder extends BlockComponentBuilder { node.attributes[DatabaseBlockKeys.kViewID] is String; } -class BoardBlockComponentWidget extends StatefulWidget { +class BoardBlockComponentWidget extends BlockComponentStatefulWidget { const BoardBlockComponentWidget({ super.key, - required this.configuration, - required this.node, + required super.node, + super.showActions, + super.actionBuilder, + super.configuration = const BlockComponentConfiguration(), }); - final Node node; - final BlockComponentConfiguration configuration; - @override State createState() => _BoardBlockComponentWidgetState(); @@ -62,7 +66,7 @@ class _BoardBlockComponentWidgetState extends State @override Widget build(BuildContext context) { final editorState = Provider.of(context, listen: false); - return BuiltInPageWidget( + Widget child = BuiltInPageWidget( node: widget.node, editorState: editorState, builder: (viewPB) { @@ -72,5 +76,15 @@ class _BoardBlockComponentWidgetState extends State ); }, ); + + if (widget.actionBuilder != null) { + child = BlockComponentActionWrapper( + node: widget.node, + actionBuilder: widget.actionBuilder!, + child: child, + ); + } + + return child; } } diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart index 94c534467c..a486ad8363 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart @@ -65,12 +65,17 @@ class CalloutBlockComponentBuilder extends BlockComponentBuilder { final BlockComponentConfiguration configuration; @override - Widget build(BlockComponentContext blockComponentContext) { + BlockComponentWidget build(BlockComponentContext blockComponentContext) { final node = blockComponentContext.node; return CalloutBlockComponentWidget( key: node.key, node: node, configuration: configuration, + showActions: showActions(node), + actionBuilder: (context, state) => actionBuilder( + blockComponentContext, + state, + ), ); } @@ -84,16 +89,15 @@ class CalloutBlockComponentBuilder extends BlockComponentBuilder { } // the main widget for rendering the callout block -class CalloutBlockComponentWidget extends StatefulWidget { +class CalloutBlockComponentWidget extends BlockComponentStatefulWidget { const CalloutBlockComponentWidget({ super.key, - required this.node, - required this.configuration, + required super.node, + super.showActions, + super.actionBuilder, + super.configuration = const BlockComponentConfiguration(), }); - final Node node; - final BlockComponentConfiguration configuration; - @override State createState() => _CalloutBlockComponentWidgetState(); @@ -135,7 +139,7 @@ class _CalloutBlockComponentWidgetState // build the callout block widget @override Widget build(BuildContext context) { - return Container( + Widget child = Container( decoration: BoxDecoration( borderRadius: const BorderRadius.all(Radius.circular(8.0)), color: backgroundColor, @@ -168,6 +172,16 @@ class _CalloutBlockComponentWidgetState ], ), ); + + if (widget.actionBuilder != null) { + child = BlockComponentActionWrapper( + node: widget.node, + actionBuilder: widget.actionBuilder!, + child: child, + ); + } + + return child; } // build the richtext child diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_component.dart index 094626fad1..c413d14140 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_component.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_component.dart @@ -59,13 +59,18 @@ class CodeBlockComponentBuilder extends BlockComponentBuilder { final EdgeInsets padding; @override - Widget build(BlockComponentContext blockComponentContext) { + BlockComponentWidget build(BlockComponentContext blockComponentContext) { final node = blockComponentContext.node; return CodeBlockComponentWidget( key: node.key, node: node, configuration: configuration, padding: padding, + showActions: showActions(node), + actionBuilder: (context, state) => actionBuilder( + blockComponentContext, + state, + ), ); } @@ -73,16 +78,16 @@ class CodeBlockComponentBuilder extends BlockComponentBuilder { bool validate(Node node) => node.delta != null; } -class CodeBlockComponentWidget extends StatefulWidget { +class CodeBlockComponentWidget extends BlockComponentStatefulWidget { const CodeBlockComponentWidget({ - Key? key, - required this.node, - this.configuration = const BlockComponentConfiguration(), + super.key, + required super.node, + super.showActions, + super.actionBuilder, + super.configuration = const BlockComponentConfiguration(), this.padding = const EdgeInsets.all(0), - }) : super(key: key); + }); - final Node node; - final BlockComponentConfiguration configuration; final EdgeInsets padding; @override @@ -166,7 +171,7 @@ class _CodeBlockComponentWidgetState extends State @override Widget build(BuildContext context) { - return Container( + Widget child = Container( decoration: BoxDecoration( borderRadius: const BorderRadius.all(Radius.circular(8.0)), color: Colors.grey.withOpacity(0.1), @@ -181,6 +186,16 @@ class _CodeBlockComponentWidgetState extends State ], ), ); + + if (widget.actionBuilder != null) { + child = BlockComponentActionWrapper( + node: widget.node, + actionBuilder: widget.actionBuilder!, + child: child, + ); + } + + return child; } Widget _buildCodeBlock(BuildContext context) { diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/divider/divider_node_widget.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/divider/divider_node_widget.dart index bd78fc5353..18ec16fa48 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/divider/divider_node_widget.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/divider/divider_node_widget.dart @@ -24,13 +24,18 @@ class DividerBlockComponentBuilder extends BlockComponentBuilder { final Color lineColor; @override - Widget build(BlockComponentContext blockComponentContext) { + BlockComponentWidget build(BlockComponentContext blockComponentContext) { final node = blockComponentContext.node; return DividerBlockComponentWidget( key: node.key, node: node, padding: padding, lineColor: lineColor, + showActions: showActions(node), + actionBuilder: (context, state) => actionBuilder( + blockComponentContext, + state, + ), ); } @@ -38,15 +43,17 @@ class DividerBlockComponentBuilder extends BlockComponentBuilder { bool validate(Node node) => node.children.isEmpty; } -class DividerBlockComponentWidget extends StatefulWidget { +class DividerBlockComponentWidget extends BlockComponentStatefulWidget { const DividerBlockComponentWidget({ - Key? key, - required this.node, + super.key, + required super.node, + super.showActions, + super.actionBuilder, + super.configuration = const BlockComponentConfiguration(), this.padding = const EdgeInsets.symmetric(vertical: 8.0), this.lineColor = Colors.grey, - }) : super(key: key); + }); - final Node node; final EdgeInsets padding; final Color lineColor; @@ -61,13 +68,27 @@ class _DividerBlockComponentWidgetState @override Widget build(BuildContext context) { - return Padding( + Widget child = Padding( padding: widget.padding, child: Container( - height: 1, - color: widget.lineColor, + height: 10, + alignment: Alignment.center, + child: Divider( + color: widget.lineColor, + thickness: 1, + ), ), ); + + if (widget.actionBuilder != null) { + child = BlockComponentActionWrapper( + node: widget.node, + actionBuilder: widget.actionBuilder!, + child: child, + ); + } + + return child; } @override diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/grid/grid_node_widget.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/grid/grid_node_widget.dart index 24fbbaae7e..580991e178 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/grid/grid_node_widget.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/grid/grid_node_widget.dart @@ -20,12 +20,17 @@ class GridBlockComponentBuilder extends BlockComponentBuilder { final BlockComponentConfiguration configuration; @override - Widget build(BlockComponentContext blockComponentContext) { + BlockComponentWidget build(BlockComponentContext blockComponentContext) { final node = blockComponentContext.node; return GridBlockComponentWidget( key: node.key, node: node, configuration: configuration, + showActions: showActions(node), + actionBuilder: (context, state) => actionBuilder( + blockComponentContext, + state, + ), ); } @@ -36,16 +41,15 @@ class GridBlockComponentBuilder extends BlockComponentBuilder { node.attributes[DatabaseBlockKeys.kViewID] is String; } -class GridBlockComponentWidget extends StatefulWidget { +class GridBlockComponentWidget extends BlockComponentStatefulWidget { const GridBlockComponentWidget({ super.key, - required this.configuration, - required this.node, + required super.node, + super.showActions, + super.actionBuilder, + super.configuration = const BlockComponentConfiguration(), }); - final Node node; - final BlockComponentConfiguration configuration; - @override State createState() => _GridBlockComponentWidgetState(); @@ -62,7 +66,7 @@ class _GridBlockComponentWidgetState extends State @override Widget build(BuildContext context) { final editorState = Provider.of(context, listen: false); - return BuiltInPageWidget( + Widget child = BuiltInPageWidget( node: widget.node, editorState: editorState, builder: (viewPB) { @@ -72,5 +76,15 @@ class _GridBlockComponentWidgetState extends State ); }, ); + + if (widget.actionBuilder != null) { + child = BlockComponentActionWrapper( + node: widget.node, + actionBuilder: widget.actionBuilder!, + child: child, + ); + } + + return child; } } diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart index 0cbc6d3230..b75eabb615 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart @@ -61,12 +61,17 @@ class MathEquationBlockComponentBuilder extends BlockComponentBuilder { final BlockComponentConfiguration configuration; @override - Widget build(BlockComponentContext blockComponentContext) { + BlockComponentWidget build(BlockComponentContext blockComponentContext) { final node = blockComponentContext.node; return MathEquationBlockComponentWidget( key: node.key, node: node, configuration: configuration, + showActions: showActions(node), + actionBuilder: (context, state) => actionBuilder( + blockComponentContext, + state, + ), ); } @@ -76,15 +81,14 @@ class MathEquationBlockComponentBuilder extends BlockComponentBuilder { node.attributes[MathEquationBlockKeys.formula] is String; } -class MathEquationBlockComponentWidget extends StatefulWidget { +class MathEquationBlockComponentWidget extends BlockComponentStatefulWidget { const MathEquationBlockComponentWidget({ - Key? key, - required this.node, - this.configuration = const BlockComponentConfiguration(), - }) : super(key: key); - - final Node node; - final BlockComponentConfiguration configuration; + super.key, + required super.node, + super.showActions, + super.actionBuilder, + super.configuration = const BlockComponentConfiguration(), + }); @override State createState() => @@ -116,7 +120,7 @@ class _MathEquationBlockComponentWidgetState } Widget _buildMathEquation(BuildContext context) { - return Container( + Widget child = Container( width: double.infinity, constraints: const BoxConstraints(minHeight: 50), padding: padding, @@ -139,6 +143,16 @@ class _MathEquationBlockComponentWidgetState ), ), ); + + if (widget.actionBuilder != null) { + child = BlockComponentActionWrapper( + node: node, + actionBuilder: widget.actionBuilder!, + child: child, + ); + } + + return child; } void showEditingDialog() { diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/auto_completion_node_widget.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/auto_completion_node_widget.dart index 3c80c65342..025ee5480d 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/auto_completion_node_widget.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/auto_completion_node_widget.dart @@ -56,11 +56,16 @@ class AutoCompletionBlockComponentBuilder extends BlockComponentBuilder { AutoCompletionBlockComponentBuilder(); @override - Widget build(BlockComponentContext blockComponentContext) { + BlockComponentWidget build(BlockComponentContext blockComponentContext) { final node = blockComponentContext.node; return AutoCompletionBlockComponent( key: node.key, node: node, + showActions: showActions(node), + actionBuilder: (context, state) => actionBuilder( + blockComponentContext, + state, + ), ); } @@ -72,14 +77,15 @@ class AutoCompletionBlockComponentBuilder extends BlockComponentBuilder { } } -class AutoCompletionBlockComponent extends StatefulWidget { +class AutoCompletionBlockComponent extends BlockComponentStatefulWidget { const AutoCompletionBlockComponent({ super.key, - required this.node, + required super.node, + super.showActions, + super.actionBuilder, + super.configuration = const BlockComponentConfiguration(), }); - final Node node; - @override State createState() => _AutoCompletionBlockComponentState(); diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/smart_edit_node_widget.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/smart_edit_node_widget.dart index 35bbfc6987..dc1e6be586 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/smart_edit_node_widget.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/smart_edit_node_widget.dart @@ -46,11 +46,16 @@ class SmartEditBlockComponentBuilder extends BlockComponentBuilder { SmartEditBlockComponentBuilder(); @override - Widget build(BlockComponentContext blockComponentContext) { + BlockComponentWidget build(BlockComponentContext blockComponentContext) { final node = blockComponentContext.node; return SmartEditBlockComponentWidget( key: node.key, node: node, + showActions: showActions(node), + actionBuilder: (context, state) => actionBuilder( + blockComponentContext, + state, + ), ); } @@ -60,14 +65,15 @@ class SmartEditBlockComponentBuilder extends BlockComponentBuilder { node.attributes[SmartEditBlockKeys.content] is String; } -class SmartEditBlockComponentWidget extends StatefulWidget { +class SmartEditBlockComponentWidget extends BlockComponentStatefulWidget { const SmartEditBlockComponentWidget({ - required super.key, - required this.node, + super.key, + required super.node, + super.showActions, + super.actionBuilder, + super.configuration = const BlockComponentConfiguration(), }); - final Node node; - @override State createState() => _SmartEditBlockComponentWidgetState(); diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart index 454ac94d2a..d15eeda269 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart @@ -44,13 +44,18 @@ class ToggleListBlockComponentBuilder extends BlockComponentBuilder { final EdgeInsets padding; @override - Widget build(BlockComponentContext blockComponentContext) { + BlockComponentWidget build(BlockComponentContext blockComponentContext) { final node = blockComponentContext.node; return ToggleListBlockComponentWidget( key: node.key, node: node, configuration: configuration, padding: padding, + showActions: showActions(node), + actionBuilder: (context, state) => actionBuilder( + blockComponentContext, + state, + ), ); } @@ -58,16 +63,16 @@ class ToggleListBlockComponentBuilder extends BlockComponentBuilder { bool validate(Node node) => node.delta != null; } -class ToggleListBlockComponentWidget extends StatefulWidget { +class ToggleListBlockComponentWidget extends BlockComponentStatefulWidget { const ToggleListBlockComponentWidget({ - Key? key, - required this.node, - this.configuration = const BlockComponentConfiguration(), + super.key, + required super.node, + super.showActions, + super.actionBuilder, + super.configuration = const BlockComponentConfiguration(), this.padding = const EdgeInsets.all(0), - }) : super(key: key); + }); - final Node node; - final BlockComponentConfiguration configuration; final EdgeInsets padding; @override diff --git a/frontend/appflowy_flutter/pubspec.lock b/frontend/appflowy_flutter/pubspec.lock index 4a59dec51a..895776f79a 100644 --- a/frontend/appflowy_flutter/pubspec.lock +++ b/frontend/appflowy_flutter/pubspec.lock @@ -53,8 +53,8 @@ packages: dependency: "direct main" description: path: "." - ref: "21f686" - resolved-ref: "21f686d6a43137cf6c6d7d040463a1679d13f858" + ref: "25eb16" + resolved-ref: "25eb1653252efa0c2695a49e7e7493c4030c11e4" url: "https://github.com/LucasXu0/appflowy-editor.git" source: git version: "0.1.12" diff --git a/frontend/appflowy_flutter/pubspec.yaml b/frontend/appflowy_flutter/pubspec.yaml index 8d9c2a001c..ecb470bb5c 100644 --- a/frontend/appflowy_flutter/pubspec.yaml +++ b/frontend/appflowy_flutter/pubspec.yaml @@ -47,7 +47,7 @@ dependencies: # path: /Users/lucas.xu/Desktop/appflowy-editor git: url: https://github.com/LucasXu0/appflowy-editor.git - ref: 21f686 + ref: 25eb16 appflowy_popover: path: packages/appflowy_popover diff --git a/frontend/appflowy_flutter/test/util.dart b/frontend/appflowy_flutter/test/util.dart index 4278ea2a1b..fa73dd2074 100644 --- a/frontend/appflowy_flutter/test/util.dart +++ b/frontend/appflowy_flutter/test/util.dart @@ -54,8 +54,10 @@ class AppFlowyUnitTest { password: password, email: userEmail, ); - return result.fold( - (error) {}, + result.fold( + (error) { + assert(false, 'Error: $error'); + }, (user) { userProfile = user; userService = UserBackendService(userId: userProfile.id); diff --git a/frontend/rust-lib/flowy-core/src/deps_resolve/folder2_deps.rs b/frontend/rust-lib/flowy-core/src/deps_resolve/folder2_deps.rs index b6f4b7d634..07f9934b0f 100644 --- a/frontend/rust-lib/flowy-core/src/deps_resolve/folder2_deps.rs +++ b/frontend/rust-lib/flowy-core/src/deps_resolve/folder2_deps.rs @@ -19,6 +19,7 @@ use flowy_folder2::manager::Folder2Manager; use flowy_folder2::view_ext::{ViewDataProcessor, ViewDataProcessorMap}; use flowy_folder2::ViewLayout; use flowy_user::services::UserSession; +use lib_dispatch::prelude::ToBytes; use lib_infra::future::FutureResult; pub struct Folder2DepsResolver(); @@ -99,8 +100,8 @@ impl ViewDataProcessor for DocumentViewDataProcessor { let view_id = view_id.to_string(); FutureResult::new(async move { let document = manager.get_document(view_id)?; - let data = document.lock().get_document()?; - let data_bytes = serde_json::to_string(&data)?.as_bytes().to_vec(); + let data: DocumentDataPB = DocumentDataWrapper(document.lock().get_document()?).into(); + let data_bytes = data.into_bytes().map_err(|_| FlowyError::invalid_data())?; Ok(Bytes::from(data_bytes)) }) }