From af3bfebb64c7ae6c189a1512524f99ae0c4e39c8 Mon Sep 17 00:00:00 2001 From: appflowy Date: Mon, 29 Aug 2022 16:32:20 +0800 Subject: [PATCH] chore: become editing when creating a new card --- .../plugins/board/application/board_bloc.dart | 19 +++++++++++---- .../board/application/group_controller.dart | 7 +++++- .../board/presentation/board_page.dart | 9 ++------ .../board/presentation/card/board_cell.dart | 3 +++ .../presentation/card/board_text_cell.dart | 9 +++++++- .../plugins/board/presentation/card/card.dart | 23 +++++++++++-------- .../presentation/card/card_cell_builder.dart | 7 +++++- .../packages/appflowy_board/CHANGELOG.md | 4 ++++ .../widgets/reorder_flex/reorder_flex.dart | 1 - .../reorder_phantom/phantom_controller.dart | 1 - .../packages/appflowy_board/pubspec.yaml | 2 +- .../flowy-grid/src/entities/block_entities.rs | 15 ++++++++++-- .../flowy-grid/src/services/block_manager.rs | 1 + .../src/services/grid_view_editor.rs | 1 + 14 files changed, 73 insertions(+), 29 deletions(-) create mode 100644 frontend/app_flowy/lib/plugins/board/presentation/card/board_cell.dart diff --git a/frontend/app_flowy/lib/plugins/board/application/board_bloc.dart b/frontend/app_flowy/lib/plugins/board/application/board_bloc.dart index dcac0a47bb..53038c8d42 100644 --- a/frontend/app_flowy/lib/plugins/board/application/board_bloc.dart +++ b/frontend/app_flowy/lib/plugins/board/application/board_bloc.dart @@ -142,7 +142,7 @@ class BoardBloc extends Bloc { for (final group in groups) { final delegate = GroupControllerDelegateImpl( controller: boardController, - didAddColumnItem: (groupId, row) { + onNewColumnItem: (groupId, row) { add(BoardEvent.didCreateRow(groupId, row)); }, ); @@ -313,11 +313,11 @@ class BoardColumnItem extends AFColumnItem { class GroupControllerDelegateImpl extends GroupControllerDelegate { final AFBoardDataController controller; - final void Function(String, RowPB) didAddColumnItem; + final void Function(String, RowPB) onNewColumnItem; GroupControllerDelegateImpl({ required this.controller, - required this.didAddColumnItem, + required this.onNewColumnItem, }); @override @@ -329,10 +329,8 @@ class GroupControllerDelegateImpl extends GroupControllerDelegate { final item = BoardColumnItem( row: row, fieldId: group.fieldId, - requestFocus: true, ); controller.addColumnItem(group.groupId, item); - didAddColumnItem(group.groupId, row); } } @@ -351,6 +349,17 @@ class GroupControllerDelegateImpl extends GroupControllerDelegate { ), ); } + + @override + void addNewRow(GroupPB group, RowPB row) { + final item = BoardColumnItem( + row: row, + fieldId: group.fieldId, + requestFocus: true, + ); + controller.addColumnItem(group.groupId, item); + onNewColumnItem(group.groupId, row); + } } class BoardEditingRow { diff --git a/frontend/app_flowy/lib/plugins/board/application/group_controller.dart b/frontend/app_flowy/lib/plugins/board/application/group_controller.dart index 812dbc76d3..9407ae360b 100644 --- a/frontend/app_flowy/lib/plugins/board/application/group_controller.dart +++ b/frontend/app_flowy/lib/plugins/board/application/group_controller.dart @@ -9,6 +9,7 @@ abstract class GroupControllerDelegate { void removeRow(GroupPB group, String rowId); void insertRow(GroupPB group, RowPB row, int? index); void updateRow(GroupPB group, RowPB row); + void addNewRow(GroupPB group, RowPB row); } class GroupController { @@ -48,7 +49,11 @@ class GroupController { group.rows.add(insertedRow.row); } - delegate.insertRow(group, insertedRow.row, index); + if (insertedRow.isNew) { + delegate.addNewRow(group, insertedRow.row); + } else { + delegate.insertRow(group, insertedRow.row, index); + } } for (final updatedRow in changeset.updatedRows) { diff --git a/frontend/app_flowy/lib/plugins/board/presentation/board_page.dart b/frontend/app_flowy/lib/plugins/board/presentation/board_page.dart index d0884e4efc..f6bfd609c3 100644 --- a/frontend/app_flowy/lib/plugins/board/presentation/board_page.dart +++ b/frontend/app_flowy/lib/plugins/board/presentation/board_page.dart @@ -196,10 +196,8 @@ class _BoardContentState extends State { ); final cellBuilder = BoardCellBuilder(cardController); - final isEditing = context.read().state.editingRow.fold( - () => false, - (editingRow) => editingRow.row.id == rowPB.id, - ); + + final isEditing = context.read().state.editingRow.isSome(); return AppFlowyColumnItemCard( key: ValueKey(columnItem.id), @@ -212,9 +210,6 @@ class _BoardContentState extends State { isEditing: isEditing, cellBuilder: cellBuilder, dataController: cardController, - onEditEditing: (rowId) { - context.read().add(BoardEvent.endEditRow(rowId)); - }, openCard: (context) => _openCard( gridId, fieldCache, diff --git a/frontend/app_flowy/lib/plugins/board/presentation/card/board_cell.dart b/frontend/app_flowy/lib/plugins/board/presentation/card/board_cell.dart new file mode 100644 index 0000000000..3c0c0298e9 --- /dev/null +++ b/frontend/app_flowy/lib/plugins/board/presentation/card/board_cell.dart @@ -0,0 +1,3 @@ +abstract class FocusableBoardCell { + set becomeFocus(bool isFocus); +} diff --git a/frontend/app_flowy/lib/plugins/board/presentation/card/board_text_cell.dart b/frontend/app_flowy/lib/plugins/board/presentation/card/board_text_cell.dart index ed683005f9..20b1a07085 100644 --- a/frontend/app_flowy/lib/plugins/board/presentation/card/board_text_cell.dart +++ b/frontend/app_flowy/lib/plugins/board/presentation/card/board_text_cell.dart @@ -1,16 +1,19 @@ import 'package:app_flowy/plugins/board/application/card/board_text_cell_bloc.dart'; import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_service.dart'; import 'package:app_flowy/plugins/grid/presentation/widgets/cell/cell_builder.dart'; -import 'package:flowy_infra_ui/style_widget/text.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; class BoardTextCell extends StatefulWidget { final String groupId; + final bool isFocus; + final GridCellControllerBuilder cellControllerBuilder; + const BoardTextCell({ required this.groupId, required this.cellControllerBuilder, + this.isFocus = false, Key? key, }) : super(key: key); @@ -30,6 +33,10 @@ class _BoardTextCellState extends State { _cellBloc = BoardTextCellBloc(cellController: cellController) ..add(const BoardTextCellEvent.initial()); _controller = TextEditingController(text: _cellBloc.state.content); + + if (widget.isFocus) { + focusNode.requestFocus(); + } super.initState(); } diff --git a/frontend/app_flowy/lib/plugins/board/presentation/card/card.dart b/frontend/app_flowy/lib/plugins/board/presentation/card/card.dart index 9f919f2dd1..08331f6021 100644 --- a/frontend/app_flowy/lib/plugins/board/presentation/card/card.dart +++ b/frontend/app_flowy/lib/plugins/board/presentation/card/card.dart @@ -10,8 +10,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'card_cell_builder.dart'; import 'card_container.dart'; -typedef OnEndEditing = void Function(String rowId); - class BoardCard extends StatefulWidget { final String gridId; final String groupId; @@ -19,7 +17,6 @@ class BoardCard extends StatefulWidget { final bool isEditing; final CardDataController dataController; final BoardCellBuilder cellBuilder; - final OnEndEditing onEditEditing; final void Function(BuildContext) openCard; const BoardCard({ @@ -29,7 +26,6 @@ class BoardCard extends StatefulWidget { required this.isEditing, required this.dataController, required this.cellBuilder, - required this.onEditEditing, required this.openCard, Key? key, }) : super(key: key); @@ -87,18 +83,27 @@ class _BoardCardState extends State { final List children = []; cells.asMap().forEach( (int index, GridCellIdentifier cellId) { - final child = widget.cellBuilder.buildCell(widget.groupId, cellId); + Widget child = widget.cellBuilder.buildCell( + widget.groupId, + cellId, + widget.isEditing, + ); + if (index != 0) { - children.add(Padding( + child = Padding( + key: cellId.key(), padding: const EdgeInsets.only(left: 4, right: 4, top: 8), child: child, - )); + ); } else { - children.add(Padding( + child = Padding( + key: UniqueKey(), padding: const EdgeInsets.only(left: 4, right: 4), child: child, - )); + ); } + + children.add(child); }, ); return children; diff --git a/frontend/app_flowy/lib/plugins/board/presentation/card/card_cell_builder.dart b/frontend/app_flowy/lib/plugins/board/presentation/card/card_cell_builder.dart index 83dbf584e8..b292457193 100644 --- a/frontend/app_flowy/lib/plugins/board/presentation/card/card_cell_builder.dart +++ b/frontend/app_flowy/lib/plugins/board/presentation/card/card_cell_builder.dart @@ -19,7 +19,11 @@ class BoardCellBuilder { BoardCellBuilder(this.delegate); - Widget buildCell(String groupId, GridCellIdentifier cellId) { + Widget buildCell( + String groupId, + GridCellIdentifier cellId, + bool isEditing, + ) { final cellControllerBuilder = GridCellControllerBuilder( delegate: delegate, cellId: cellId, @@ -62,6 +66,7 @@ class BoardCellBuilder { return BoardTextCell( groupId: groupId, cellControllerBuilder: cellControllerBuilder, + isFocus: isEditing, key: key, ); case FieldType.URL: diff --git a/frontend/app_flowy/packages/appflowy_board/CHANGELOG.md b/frontend/app_flowy/packages/appflowy_board/CHANGELOG.md index c4c6495533..d8eceeefee 100644 --- a/frontend/app_flowy/packages/appflowy_board/CHANGELOG.md +++ b/frontend/app_flowy/packages/appflowy_board/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.0.6 +* Support scroll to bottom +* Fix some bugs + # 0.0.5 * Optimize insert card animation * Enable insert card at the end of the column diff --git a/frontend/app_flowy/packages/appflowy_board/lib/src/widgets/reorder_flex/reorder_flex.dart b/frontend/app_flowy/packages/appflowy_board/lib/src/widgets/reorder_flex/reorder_flex.dart index 63bd9638b4..90556440b4 100644 --- a/frontend/app_flowy/packages/appflowy_board/lib/src/widgets/reorder_flex/reorder_flex.dart +++ b/frontend/app_flowy/packages/appflowy_board/lib/src/widgets/reorder_flex/reorder_flex.dart @@ -381,7 +381,6 @@ class ReorderFlexState extends State dragState.currentIndex, ); } - dragState.endDragging(); widget.onDragEnded?.call(); }); diff --git a/frontend/app_flowy/packages/appflowy_board/lib/src/widgets/reorder_phantom/phantom_controller.dart b/frontend/app_flowy/packages/appflowy_board/lib/src/widgets/reorder_phantom/phantom_controller.dart index a3e0f5fb6e..0f63266e51 100644 --- a/frontend/app_flowy/packages/appflowy_board/lib/src/widgets/reorder_phantom/phantom_controller.dart +++ b/frontend/app_flowy/packages/appflowy_board/lib/src/widgets/reorder_phantom/phantom_controller.dart @@ -2,7 +2,6 @@ import 'package:appflowy_board/appflowy_board.dart'; import 'package:flutter/widgets.dart'; import '../../utils/log.dart'; -import '../board_column/board_column_data.dart'; import '../reorder_flex/drag_state.dart'; import '../reorder_flex/drag_target.dart'; import '../reorder_flex/drag_target_interceptor.dart'; diff --git a/frontend/app_flowy/packages/appflowy_board/pubspec.yaml b/frontend/app_flowy/packages/appflowy_board/pubspec.yaml index 6bb2feabfe..a9adf5007a 100644 --- a/frontend/app_flowy/packages/appflowy_board/pubspec.yaml +++ b/frontend/app_flowy/packages/appflowy_board/pubspec.yaml @@ -1,6 +1,6 @@ name: appflowy_board description: AppFlowy board implementation. -version: 0.0.5 +version: 0.0.6 homepage: https://github.com/AppFlowy-IO/AppFlowy repository: https://github.com/AppFlowy-IO/AppFlowy/tree/main/frontend/app_flowy/packages/appflowy_board diff --git a/frontend/rust-lib/flowy-grid/src/entities/block_entities.rs b/frontend/rust-lib/flowy-grid/src/entities/block_entities.rs index e691ed1830..6e271a0fb2 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/block_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/block_entities.rs @@ -120,17 +120,28 @@ pub struct InsertedRowPB { #[pb(index = 2, one_of)] pub index: Option, + + #[pb(index = 3)] + pub is_new: bool, } impl InsertedRowPB { pub fn new(row: RowPB) -> Self { - Self { row, index: None } + Self { + row, + index: None, + is_new: false, + } } } impl std::convert::From for InsertedRowPB { fn from(row: RowPB) -> Self { - Self { row, index: None } + Self { + row, + index: None, + is_new: false, + } } } diff --git a/frontend/rust-lib/flowy-grid/src/services/block_manager.rs b/frontend/rust-lib/flowy-grid/src/services/block_manager.rs index 1bc9b9dc42..9619bf52ab 100644 --- a/frontend/rust-lib/flowy-grid/src/services/block_manager.rs +++ b/frontend/rust-lib/flowy-grid/src/services/block_manager.rs @@ -164,6 +164,7 @@ impl GridBlockManager { let insert_row = InsertedRowPB { index: Some(to as i32), row: make_row_from_row_rev(row_rev), + is_new: false, }; let notified_changeset = GridBlockChangesetPB { diff --git a/frontend/rust-lib/flowy-grid/src/services/grid_view_editor.rs b/frontend/rust-lib/flowy-grid/src/services/grid_view_editor.rs index 8b89aa72ae..013f59cd42 100644 --- a/frontend/rust-lib/flowy-grid/src/services/grid_view_editor.rs +++ b/frontend/rust-lib/flowy-grid/src/services/grid_view_editor.rs @@ -98,6 +98,7 @@ impl GridViewRevisionEditor { let inserted_row = InsertedRowPB { row: row_pb.clone(), index: None, + is_new: true, }; let changeset = GroupChangesetPB::insert(group_id.clone(), vec![inserted_row]); self.notify_did_update_group(changeset).await;