chore: become editing when creating a new card

This commit is contained in:
appflowy 2022-08-29 16:32:20 +08:00
parent 4e8308b834
commit af3bfebb64
14 changed files with 73 additions and 29 deletions

View File

@ -142,7 +142,7 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
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 {

View File

@ -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) {

View File

@ -196,10 +196,8 @@ class _BoardContentState extends State<BoardContent> {
);
final cellBuilder = BoardCellBuilder(cardController);
final isEditing = context.read<BoardBloc>().state.editingRow.fold(
() => false,
(editingRow) => editingRow.row.id == rowPB.id,
);
final isEditing = context.read<BoardBloc>().state.editingRow.isSome();
return AppFlowyColumnItemCard(
key: ValueKey(columnItem.id),
@ -212,9 +210,6 @@ class _BoardContentState extends State<BoardContent> {
isEditing: isEditing,
cellBuilder: cellBuilder,
dataController: cardController,
onEditEditing: (rowId) {
context.read<BoardBloc>().add(BoardEvent.endEditRow(rowId));
},
openCard: (context) => _openCard(
gridId,
fieldCache,

View File

@ -0,0 +1,3 @@
abstract class FocusableBoardCell {
set becomeFocus(bool isFocus);
}

View File

@ -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<BoardTextCell> {
_cellBloc = BoardTextCellBloc(cellController: cellController)
..add(const BoardTextCellEvent.initial());
_controller = TextEditingController(text: _cellBloc.state.content);
if (widget.isFocus) {
focusNode.requestFocus();
}
super.initState();
}

View File

@ -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<BoardCard> {
final List<Widget> 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;

View File

@ -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:

View File

@ -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

View File

@ -381,7 +381,6 @@ class ReorderFlexState extends State<ReorderFlex>
dragState.currentIndex,
);
}
dragState.endDragging();
widget.onDragEnded?.call();
});

View File

@ -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';

View File

@ -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

View File

@ -120,17 +120,28 @@ pub struct InsertedRowPB {
#[pb(index = 2, one_of)]
pub index: Option<i32>,
#[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<RowPB> for InsertedRowPB {
fn from(row: RowPB) -> Self {
Self { row, index: None }
Self {
row,
index: None,
is_new: false,
}
}
}

View File

@ -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 {

View File

@ -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;