Skip to content

Commit a0753ce

Browse files
authored
Merge pull request #867 from AppFlowy-IO/feat/move_card
feat: move card from one column to another
2 parents 9d747f3 + da485c6 commit a0753ce

File tree

70 files changed

+1141
-504
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1141
-504
lines changed

frontend/.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"program": "./lib/main.dart",
3030
"type": "dart",
3131
"env": {
32-
"RUST_LOG": "debug"
32+
"RUST_LOG": "trace"
3333
},
3434
"cwd": "${workspaceRoot}/app_flowy"
3535
},

frontend/app_flowy/lib/plugins/blank/blank.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class BlankPluginBuilder extends PluginBuilder {
1616
String get menuName => "Blank";
1717

1818
@override
19-
PluginType get pluginType => DefaultPlugin.blank.type();
19+
PluginType get pluginType => PluginType.blank;
2020
}
2121

2222
class BlankPluginConfig implements PluginConfig {

frontend/app_flowy/lib/plugins/board/application/board_bloc.dart

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:async';
22
import 'package:app_flowy/plugins/grid/application/block/block_cache.dart';
33
import 'package:app_flowy/plugins/grid/application/field/field_cache.dart';
44
import 'package:app_flowy/plugins/grid/application/row/row_cache.dart';
5+
import 'package:app_flowy/plugins/grid/application/row/row_service.dart';
56
import 'package:appflowy_board/appflowy_board.dart';
67
import 'package:dartz/dartz.dart';
78
import 'package:equatable/equatable.dart';
@@ -21,13 +22,15 @@ part 'board_bloc.freezed.dart';
2122
class BoardBloc extends Bloc<BoardEvent, BoardState> {
2223
final BoardDataController _dataController;
2324
late final AFBoardDataController afBoardDataController;
24-
List<GroupController> groupControllers = [];
25+
final MoveRowFFIService _rowService;
26+
Map<String, GroupController> groupControllers = {};
2527

2628
GridFieldCache get fieldCache => _dataController.fieldCache;
2729
String get gridId => _dataController.gridId;
2830

2931
BoardBloc({required ViewPB view})
30-
: _dataController = BoardDataController(view: view),
32+
: _rowService = MoveRowFFIService(gridId: view.id),
33+
_dataController = BoardDataController(view: view),
3134
super(BoardState.initial(view.id)) {
3235
afBoardDataController = AFBoardDataController(
3336
onMoveColumn: (
@@ -38,13 +41,21 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
3841
columnId,
3942
fromIndex,
4043
toIndex,
41-
) {},
44+
) {
45+
final fromRow = groupControllers[columnId]?.rowAtIndex(fromIndex);
46+
final toRow = groupControllers[columnId]?.rowAtIndex(toIndex);
47+
_moveRow(fromRow, toRow);
48+
},
4249
onMoveColumnItemToColumn: (
4350
fromColumnId,
4451
fromIndex,
4552
toColumnId,
4653
toIndex,
47-
) {},
54+
) {
55+
final fromRow = groupControllers[fromColumnId]?.rowAtIndex(fromIndex);
56+
final toRow = groupControllers[toColumnId]?.rowAtIndex(toIndex);
57+
_moveRow(fromRow, toRow);
58+
},
4859
);
4960

5061
on<BoardEvent>(
@@ -76,15 +87,31 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
7687
didReceiveRows: (List<RowInfo> rowInfos) {
7788
emit(state.copyWith(rowInfos: rowInfos));
7889
},
90+
didReceiveError: (FlowyError error) {
91+
emit(state.copyWith(noneOrError: some(error)));
92+
},
7993
);
8094
},
8195
);
8296
}
8397

98+
void _moveRow(RowPB? fromRow, RowPB? toRow) {
99+
if (fromRow != null && toRow != null) {
100+
_rowService
101+
.moveRow(
102+
fromRowId: fromRow.id,
103+
toRowId: toRow.id,
104+
)
105+
.then((result) {
106+
result.fold((l) => null, (r) => add(BoardEvent.didReceiveError(r)));
107+
});
108+
}
109+
}
110+
84111
@override
85112
Future<void> close() async {
86113
await _dataController.dispose();
87-
for (final controller in groupControllers) {
114+
for (final controller in groupControllers.values) {
88115
controller.dispose();
89116
}
90117
return super.close();
@@ -94,11 +121,12 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
94121
for (final group in groups) {
95122
final delegate = GroupControllerDelegateImpl(afBoardDataController);
96123
final controller = GroupController(
124+
gridId: state.gridId,
97125
group: group,
98126
delegate: delegate,
99127
);
100128
controller.startListening();
101-
groupControllers.add(controller);
129+
groupControllers[controller.group.groupId] = (controller);
102130
}
103131
}
104132

@@ -162,6 +190,7 @@ class BoardEvent with _$BoardEvent {
162190
const factory BoardEvent.initial() = InitialGrid;
163191
const factory BoardEvent.createRow(String groupId) = _CreateRow;
164192
const factory BoardEvent.endEditRow(String rowId) = _EndEditRow;
193+
const factory BoardEvent.didReceiveError(FlowyError error) = _DidReceiveError;
165194
const factory BoardEvent.didReceiveRows(List<RowInfo> rowInfos) =
166195
_DidReceiveRows;
167196
const factory BoardEvent.didReceiveGridUpdate(
@@ -177,13 +206,15 @@ class BoardState with _$BoardState {
177206
required Option<RowPB> editingRow,
178207
required List<RowInfo> rowInfos,
179208
required GridLoadingState loadingState,
209+
required Option<FlowyError> noneOrError,
180210
}) = _BoardState;
181211

182212
factory BoardState.initial(String gridId) => BoardState(
183213
rowInfos: [],
184214
grid: none(),
185215
gridId: gridId,
186216
editingRow: none(),
217+
noneOrError: none(),
187218
loadingState: const _Loading(),
188219
);
189220
}

frontend/app_flowy/lib/plugins/board/application/group_controller.dart

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import 'package:flowy_sdk/log.dart';
2+
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
23
import 'package:flowy_sdk/protobuf/flowy-grid/protobuf.dart';
34

45
import 'group_listener.dart';
56

7+
typedef OnGroupError = void Function(FlowyError);
8+
69
abstract class GroupControllerDelegate {
710
void removeRow(String groupId, String rowId);
811
void insertRow(String groupId, RowPB row, int? index);
@@ -14,8 +17,19 @@ class GroupController {
1417
final GroupListener _listener;
1518
final GroupControllerDelegate delegate;
1619

17-
GroupController({required this.group, required this.delegate})
18-
: _listener = GroupListener(group);
20+
GroupController({
21+
required String gridId,
22+
required this.group,
23+
required this.delegate,
24+
}) : _listener = GroupListener(group);
25+
26+
RowPB? rowAtIndex(int index) {
27+
if (index < group.rows.length) {
28+
return group.rows[index];
29+
} else {
30+
return null;
31+
}
32+
}
1933

2034
void startListening() {
2135
_listener.start(onGroupChanged: (result) {

frontend/app_flowy/lib/plugins/board/board.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ class BoardPluginBuilder implements PluginBuilder {
2020
String get menuName => "Board";
2121

2222
@override
23-
PluginType get pluginType => DefaultPlugin.board.type();
23+
PluginType get pluginType => PluginType.board;
2424

2525
@override
2626
ViewDataTypePB get dataType => ViewDataTypePB.Database;
2727

2828
@override
29-
SubViewDataTypePB get subDataType => SubViewDataTypePB.Board;
29+
ViewLayoutTypePB? get subDataType => ViewLayoutTypePB.Board;
3030
}
3131

3232
class BoardPluginConfig implements PluginConfig {

frontend/app_flowy/lib/plugins/doc/document.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ class DocumentPluginBuilder extends PluginBuilder {
4242
String get menuName => LocaleKeys.document_menuName.tr();
4343

4444
@override
45-
PluginType get pluginType => DefaultPlugin.editor.type();
45+
PluginType get pluginType => PluginType.editor;
4646

4747
@override
48-
ViewDataTypePB get dataType => ViewDataTypePB.TextBlock;
48+
ViewDataTypePB get dataType => ViewDataTypePB.Text;
4949
}
5050

5151
class DocumentPlugin implements Plugin {

frontend/app_flowy/lib/plugins/grid/application/cell/select_option_editor_bloc.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class SelectOptionCellEditorBloc
111111
void _loadOptions() {
112112
_delayOperation?.cancel();
113113
_delayOperation = Timer(const Duration(milliseconds: 10), () {
114-
_selectOptionService.getOpitonContext().then((result) {
114+
_selectOptionService.getOptionContext().then((result) {
115115
if (isClosed) {
116116
return;
117117
}

frontend/app_flowy/lib/plugins/grid/application/cell/select_option_service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class SelectOptionService {
5555
return GridEventUpdateSelectOption(payload).send();
5656
}
5757

58-
Future<Either<SelectOptionCellDataPB, FlowyError>> getOpitonContext() {
58+
Future<Either<SelectOptionCellDataPB, FlowyError>> getOptionContext() {
5959
final payload = GridCellIdPB.create()
6060
..gridId = gridId
6161
..fieldId = fieldId

frontend/app_flowy/lib/plugins/grid/application/row/row_service.dart

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
44
import 'package:flowy_sdk/protobuf/flowy-grid/block_entities.pb.dart';
55
import 'package:flowy_sdk/protobuf/flowy-grid/grid_entities.pb.dart';
66
import 'package:flowy_sdk/protobuf/flowy-grid/row_entities.pb.dart';
7-
import 'package:flowy_sdk/protobuf/flowy-grid/setting_entities.pb.dart';
87

98
class RowFFIService {
109
final String gridId;
@@ -23,27 +22,6 @@ class RowFFIService {
2322
return GridEventCreateTableRow(payload).send();
2423
}
2524

26-
Future<Either<Unit, FlowyError>> moveRow({
27-
required String rowId,
28-
required int fromIndex,
29-
required int toIndex,
30-
required GridLayout layout,
31-
String? upperRowId,
32-
}) {
33-
var payload = MoveRowPayloadPB.create()
34-
..viewId = gridId
35-
..rowId = rowId
36-
..layout = layout
37-
..fromIndex = fromIndex
38-
..toIndex = toIndex;
39-
40-
if (upperRowId != null) {
41-
payload.upperRowId = upperRowId;
42-
}
43-
44-
return GridEventMoveRow(payload).send();
45-
}
46-
4725
Future<Either<OptionalRowPB, FlowyError>> getRow(String rowId) {
4826
final payload = RowIdPB.create()
4927
..gridId = gridId
@@ -71,3 +49,23 @@ class RowFFIService {
7149
return GridEventDuplicateRow(payload).send();
7250
}
7351
}
52+
53+
class MoveRowFFIService {
54+
final String gridId;
55+
56+
MoveRowFFIService({
57+
required this.gridId,
58+
});
59+
60+
Future<Either<Unit, FlowyError>> moveRow({
61+
required String fromRowId,
62+
required String toRowId,
63+
}) {
64+
var payload = MoveRowPayloadPB.create()
65+
..viewId = gridId
66+
..fromRowId = fromRowId
67+
..toRowId = toRowId;
68+
69+
return GridEventMoveRow(payload).send();
70+
}
71+
}

frontend/app_flowy/lib/plugins/grid/grid.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ class GridPluginBuilder implements PluginBuilder {
2222
String get menuName => LocaleKeys.grid_menuName.tr();
2323

2424
@override
25-
PluginType get pluginType => DefaultPlugin.grid.type();
25+
PluginType get pluginType => PluginType.grid;
2626

2727
@override
2828
ViewDataTypePB get dataType => ViewDataTypePB.Database;
2929

3030
@override
31-
SubViewDataTypePB? get subDataType => SubViewDataTypePB.Grid;
31+
ViewLayoutTypePB? get subDataType => ViewLayoutTypePB.Grid;
3232
}
3333

3434
class GridPluginConfig implements PluginConfig {

0 commit comments

Comments
 (0)