From 800fb822115273021036e7eba38fa2873dc4deef Mon Sep 17 00:00:00 2001 From: appflowy Date: Fri, 12 Aug 2022 20:10:56 +0800 Subject: [PATCH] chore: card ui --- .../plugins/board/application/board_bloc.dart | 34 ++++-- .../application/board_data_controller.dart | 46 +++++++- .../card/board_date_cell_bloc.dart | 0 .../board/application/card/card_bloc.dart | 111 ++++++++++++++++++ .../card/card_data_controller.dart | 49 ++++++++ .../app_flowy/lib/plugins/board/board.dart | 2 +- .../board/presentation/board_page.dart | 26 +++- .../card/board_checkbox_cell.dart | 21 ++++ .../presentation/card/board_date_cell.dart | 21 ++++ .../presentation/card/board_number_cell.dart | 21 ++++ .../presentation/card/board_url_cell.dart | 21 ++++ .../plugins/board/presentation/card/card.dart | 60 +++++++++- .../presentation/card/card_cell_builder.dart | 69 +++++++++++ .../application/grid_data_controller.dart | 2 +- .../row/row_action_sheet_bloc.dart | 4 +- .../grid/application/row/row_bloc.dart | 16 +-- .../application/row/row_data_controller.dart | 6 +- .../grid/application/row/row_service.dart | 4 +- .../presentation/widgets/row/grid_row.dart | 2 +- .../presentation/home/menu/menu_user.dart | 2 +- .../flowy-folder/tests/workspace/script.rs | 10 +- 21 files changed, 480 insertions(+), 47 deletions(-) create mode 100644 frontend/app_flowy/lib/plugins/board/application/card/board_date_cell_bloc.dart create mode 100644 frontend/app_flowy/lib/plugins/board/application/card/card_bloc.dart create mode 100644 frontend/app_flowy/lib/plugins/board/application/card/card_data_controller.dart create mode 100644 frontend/app_flowy/lib/plugins/board/presentation/card/board_checkbox_cell.dart create mode 100644 frontend/app_flowy/lib/plugins/board/presentation/card/board_date_cell.dart create mode 100644 frontend/app_flowy/lib/plugins/board/presentation/card/board_number_cell.dart create mode 100644 frontend/app_flowy/lib/plugins/board/presentation/card/board_url_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 df79e3154c..37487a4eec 100644 --- a/frontend/app_flowy/lib/plugins/board/application/board_bloc.dart +++ b/frontend/app_flowy/lib/plugins/board/application/board_bloc.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'package:app_flowy/plugins/grid/application/block/block_cache.dart'; +import 'package:app_flowy/plugins/grid/application/field/field_cache.dart'; import 'package:app_flowy/plugins/grid/application/row/row_cache.dart'; import 'package:appflowy_board/appflowy_board.dart'; import 'package:dartz/dartz.dart'; @@ -20,6 +21,9 @@ class BoardBloc extends Bloc { final BoardDataController _dataController; late final AFBoardDataController boardDataController; + GridFieldCache get fieldCache => _dataController.fieldCache; + String get gridId => _dataController.gridId; + BoardBloc({required ViewPB view}) : _dataController = BoardDataController(view: view), super(BoardState.initial(view.id)) { @@ -57,6 +61,9 @@ class BoardBloc extends Bloc { didReceiveGroups: (List groups) { emit(state.copyWith(groups: groups)); }, + didReceiveRows: (List rowInfos) { + emit(state.copyWith(rowInfos: rowInfos)); + }, ); }, ); @@ -68,7 +75,7 @@ class BoardBloc extends Bloc { return super.close(); } - GridRowCache? getRowCache(String blockId, String rowId) { + GridRowCache? getRowCache(String blockId) { final GridBlockCache? blockCache = _dataController.blocks[blockId]; return blockCache?.rowCache; } @@ -92,6 +99,9 @@ class BoardBloc extends Bloc { boardDataController.addColumns(columns); }, + onRowsChanged: (List rowInfos, RowChangeReason reason) { + add(BoardEvent.didReceiveRows(rowInfos)); + }, onError: (err) { Log.error(err); }, @@ -100,15 +110,15 @@ class BoardBloc extends Bloc { List _buildRows(List rows) { return rows.map((row) { - final rowInfo = RowInfo( - gridId: _dataController.gridId, - blockId: row.blockId, - id: row.id, - fields: _dataController.fieldCache.unmodifiableFields, - height: row.height.toDouble(), - rawRow: row, - ); - return BoardColumnItem(row: rowInfo); + // final rowInfo = RowInfo( + // gridId: _dataController.gridId, + // blockId: row.blockId, + // id: row.id, + // fields: _dataController.fieldCache.unmodifiableFields, + // height: row.height.toDouble(), + // rawRow: row, + // ); + return BoardColumnItem(row: row); }).toList(); } @@ -131,6 +141,8 @@ class BoardEvent with _$BoardEvent { const factory BoardEvent.createRow() = _CreateRow; const factory BoardEvent.didReceiveGroups(List groups) = _DidReceiveGroup; + const factory BoardEvent.didReceiveRows(List rowInfos) = + _DidReceiveRows; const factory BoardEvent.didReceiveGridUpdate( GridPB grid, ) = _DidReceiveGridUpdate; @@ -186,7 +198,7 @@ class GridFieldEquatable extends Equatable { } class BoardColumnItem extends AFColumnItem { - final RowInfo row; + final RowPB row; BoardColumnItem({required this.row}); diff --git a/frontend/app_flowy/lib/plugins/board/application/board_data_controller.dart b/frontend/app_flowy/lib/plugins/board/application/board_data_controller.dart index c8e20b6172..4a0333f30b 100644 --- a/frontend/app_flowy/lib/plugins/board/application/board_data_controller.dart +++ b/frontend/app_flowy/lib/plugins/board/application/board_data_controller.dart @@ -3,6 +3,8 @@ import 'dart:collection'; import 'package:app_flowy/plugins/grid/application/block/block_cache.dart'; import 'package:app_flowy/plugins/grid/application/field/field_cache.dart'; import 'package:app_flowy/plugins/grid/application/grid_service.dart'; +import 'package:app_flowy/plugins/grid/application/row/row_cache.dart'; +import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'dart:async'; @@ -12,6 +14,10 @@ import 'package:flowy_sdk/protobuf/flowy-grid/protobuf.dart'; typedef OnFieldsChanged = void Function(UnmodifiableListView); typedef OnGridChanged = void Function(GridPB); typedef OnGroupChanged = void Function(List); +typedef OnRowsChanged = void Function( + List rowInfos, + RowChangeReason, +); typedef OnError = void Function(FlowyError); class BoardDataController { @@ -21,17 +27,25 @@ class BoardDataController { // key: the block id final LinkedHashMap _blocks; - UnmodifiableMapView get blocks => - UnmodifiableMapView(_blocks); + LinkedHashMap get blocks => _blocks; OnFieldsChanged? _onFieldsChanged; OnGridChanged? _onGridChanged; OnGroupChanged? _onGroupChanged; + OnRowsChanged? _onRowsChanged; OnError? _onError; + List get rowInfos { + final List rows = []; + for (var block in _blocks.values) { + rows.addAll(block.rows); + } + return rows; + } + BoardDataController({required ViewPB view}) : gridId = view.id, - _blocks = LinkedHashMap.identity(), + _blocks = LinkedHashMap.new(), _gridFFIService = GridService(gridId: view.id), fieldCache = GridFieldCache(gridId: view.id); @@ -39,11 +53,13 @@ class BoardDataController { OnGridChanged? onGridChanged, OnFieldsChanged? onFieldsChanged, OnGroupChanged? onGroupChanged, + OnRowsChanged? onRowsChanged, OnError? onError, }) { _onGridChanged = onGridChanged; _onFieldsChanged = onFieldsChanged; _onGroupChanged = onGroupChanged; + _onRowsChanged = onRowsChanged; _onError = onError; fieldCache.addListener(onFields: (fields) { @@ -57,6 +73,7 @@ class BoardDataController { () => result.fold( (grid) async { _onGridChanged?.call(grid); + _initialBlocks(grid.blocks); return await _loadFields(grid).then((result) { return result.fold( (l) { @@ -85,6 +102,29 @@ class BoardDataController { } } + void _initialBlocks(List blocks) { + for (final block in blocks) { + if (_blocks[block.id] != null) { + Log.warn("Initial duplicate block's cache: ${block.id}"); + return; + } + + final cache = GridBlockCache( + gridId: gridId, + block: block, + fieldCache: fieldCache, + ); + + cache.addListener( + onChangeReason: (reason) { + _onRowsChanged?.call(rowInfos, reason); + }, + ); + + _blocks[block.id] = cache; + } + } + Future> _loadFields(GridPB grid) async { final result = await _gridFFIService.getFields(fieldIds: grid.fields); return Future( diff --git a/frontend/app_flowy/lib/plugins/board/application/card/board_date_cell_bloc.dart b/frontend/app_flowy/lib/plugins/board/application/card/board_date_cell_bloc.dart new file mode 100644 index 0000000000..e69de29bb2 diff --git a/frontend/app_flowy/lib/plugins/board/application/card/card_bloc.dart b/frontend/app_flowy/lib/plugins/board/application/card/card_bloc.dart new file mode 100644 index 0000000000..9ba66c2aab --- /dev/null +++ b/frontend/app_flowy/lib/plugins/board/application/card/card_bloc.dart @@ -0,0 +1,111 @@ +import 'dart:collection'; +import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_service.dart'; +import 'package:app_flowy/plugins/grid/application/row/row_cache.dart'; +import 'package:app_flowy/plugins/grid/application/row/row_service.dart'; +import 'package:equatable/equatable.dart'; +import 'package:flowy_sdk/protobuf/flowy-grid/block_entities.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'dart:async'; + +import 'card_data_controller.dart'; + +part 'card_bloc.freezed.dart'; + +class BoardCardBloc extends Bloc { + final RowFFIService _rowService; + final CardDataController _dataController; + + BoardCardBloc({ + required String gridId, + required CardDataController dataController, + }) : _rowService = RowFFIService( + gridId: gridId, + blockId: dataController.rowPB.blockId, + rowId: dataController.rowPB.id, + ), + _dataController = dataController, + super(BoardCardState.initial( + dataController.rowPB, dataController.loadData())) { + on( + (event, emit) async { + await event.map( + initial: (_InitialRow value) async { + await _startListening(); + }, + createRow: (_CreateRow value) { + _rowService.createRow(); + }, + didReceiveCells: (_DidReceiveCells value) async { + final cells = value.gridCellMap.values + .map((e) => GridCellEquatable(e.field)) + .toList(); + emit(state.copyWith( + gridCellMap: value.gridCellMap, + cells: UnmodifiableListView(cells), + changeReason: value.reason, + )); + }, + ); + }, + ); + } + + @override + Future close() async { + _dataController.dispose(); + return super.close(); + } + + Future _startListening() async { + _dataController.addListener( + onRowChanged: (cells, reason) { + if (!isClosed) { + add(BoardCardEvent.didReceiveCells(cells, reason)); + } + }, + ); + } +} + +@freezed +class BoardCardEvent with _$BoardCardEvent { + const factory BoardCardEvent.initial() = _InitialRow; + const factory BoardCardEvent.createRow() = _CreateRow; + const factory BoardCardEvent.didReceiveCells( + GridCellMap gridCellMap, RowChangeReason reason) = _DidReceiveCells; +} + +@freezed +class BoardCardState with _$BoardCardState { + const factory BoardCardState({ + required RowPB rowPB, + required GridCellMap gridCellMap, + required UnmodifiableListView cells, + RowChangeReason? changeReason, + }) = _BoardCardState; + + factory BoardCardState.initial(RowPB rowPB, GridCellMap cellDataMap) => + BoardCardState( + rowPB: rowPB, + gridCellMap: cellDataMap, + cells: UnmodifiableListView( + cellDataMap.values.map((e) => GridCellEquatable(e.field)).toList(), + ), + ); +} + +class GridCellEquatable extends Equatable { + final FieldPB _field; + + const GridCellEquatable(FieldPB field) : _field = field; + + @override + List get props => [ + _field.id, + _field.fieldType, + _field.visibility, + _field.width, + ]; +} diff --git a/frontend/app_flowy/lib/plugins/board/application/card/card_data_controller.dart b/frontend/app_flowy/lib/plugins/board/application/card/card_data_controller.dart new file mode 100644 index 0000000000..d9ac41f10b --- /dev/null +++ b/frontend/app_flowy/lib/plugins/board/application/card/card_data_controller.dart @@ -0,0 +1,49 @@ +import 'package:app_flowy/plugins/board/presentation/card/card_cell_builder.dart'; +import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_service.dart'; +import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_field_notifier.dart'; +import 'package:app_flowy/plugins/grid/application/field/field_cache.dart'; +import 'package:app_flowy/plugins/grid/application/row/row_cache.dart'; +import 'package:flowy_sdk/protobuf/flowy-grid/block_entities.pb.dart'; +import 'package:flutter/foundation.dart'; + +typedef OnCardChanged = void Function(GridCellMap, RowChangeReason); + +class CardDataController extends BoardCellBuilderDelegate { + final RowPB rowPB; + final GridFieldCache _fieldCache; + final GridRowCache _rowCache; + final List _onCardChangedListeners = []; + + CardDataController({ + required this.rowPB, + required GridFieldCache fieldCache, + required GridRowCache rowCache, + }) : _fieldCache = fieldCache, + _rowCache = rowCache; + + GridCellMap loadData() { + return _rowCache.loadGridCells(rowPB.id); + } + + void addListener({OnCardChanged? onRowChanged}) { + _onCardChangedListeners.add(_rowCache.addListener( + rowId: rowPB.id, + onCellUpdated: onRowChanged, + )); + } + + void dispose() { + for (final fn in _onCardChangedListeners) { + _rowCache.removeRowListener(fn); + } + } + + @override + GridCellFieldNotifier buildFieldNotifier() { + return GridCellFieldNotifier( + notifier: GridCellFieldNotifierImpl(_fieldCache)); + } + + @override + GridCellCache get cellCache => _rowCache.cellCache; +} diff --git a/frontend/app_flowy/lib/plugins/board/board.dart b/frontend/app_flowy/lib/plugins/board/board.dart index 2954a7cbf9..36d181ae3e 100644 --- a/frontend/app_flowy/lib/plugins/board/board.dart +++ b/frontend/app_flowy/lib/plugins/board/board.dart @@ -31,7 +31,7 @@ class BoardPluginBuilder implements PluginBuilder { class BoardPluginConfig implements PluginConfig { @override - bool get creatable => false; + bool get creatable => true; } class BoardPlugin extends Plugin { 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 f8367c1392..1d5114ef05 100644 --- a/frontend/app_flowy/lib/plugins/board/presentation/board_page.dart +++ b/frontend/app_flowy/lib/plugins/board/presentation/board_page.dart @@ -1,5 +1,6 @@ // ignore_for_file: unused_field +import 'package:app_flowy/plugins/board/application/card/card_data_controller.dart'; import 'package:appflowy_board/appflowy_board.dart'; import 'package:flowy_infra_ui/widget/error_page.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; @@ -7,6 +8,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import '../application/board_bloc.dart'; import 'card/card.dart'; +import 'card/card_cell_builder.dart'; class BoardPage extends StatelessWidget { final ViewPB view; @@ -51,6 +53,7 @@ class BoardContent extends StatelessWidget { child: Padding( padding: const EdgeInsets.symmetric(vertical: 30, horizontal: 20), child: AFBoard( + key: UniqueKey(), dataController: context.read().boardDataController, headerBuilder: _buildHeader, footBuilder: _buildFooter, @@ -87,10 +90,29 @@ class BoardContent extends StatelessWidget { } Widget _buildCard(BuildContext context, AFColumnItem item) { - final rowInfo = (item as BoardColumnItem).row; + final rowPB = (item as BoardColumnItem).row; + final rowCache = context.read().getRowCache(rowPB.blockId); + + /// Return placeholder widget if the rowCache is null. + if (rowCache == null) return SizedBox(key: ObjectKey(item)); + + final fieldCache = context.read().fieldCache; + final gridId = context.read().gridId; + final cardController = CardDataController( + fieldCache: fieldCache, + rowCache: rowCache, + rowPB: rowPB, + ); + + final cellBuilder = BoardCellBuilder(cardController); + return AppFlowyColumnItemCard( key: ObjectKey(item), - child: BoardCard(rowInfo: rowInfo), + child: BoardCard( + cellBuilder: cellBuilder, + dataController: cardController, + gridId: gridId, + ), ); } } diff --git a/frontend/app_flowy/lib/plugins/board/presentation/card/board_checkbox_cell.dart b/frontend/app_flowy/lib/plugins/board/presentation/card/board_checkbox_cell.dart new file mode 100644 index 0000000000..57920aa631 --- /dev/null +++ b/frontend/app_flowy/lib/plugins/board/presentation/card/board_checkbox_cell.dart @@ -0,0 +1,21 @@ +import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_service.dart'; +import 'package:flutter/material.dart'; + +class BoardCheckboxCell extends StatefulWidget { + final GridCellControllerBuilder cellControllerBuilder; + + const BoardCheckboxCell({ + required this.cellControllerBuilder, + Key? key, + }) : super(key: key); + + @override + State createState() => _BoardCheckboxCellState(); +} + +class _BoardCheckboxCellState extends State { + @override + Widget build(BuildContext context) { + return Container(); + } +} diff --git a/frontend/app_flowy/lib/plugins/board/presentation/card/board_date_cell.dart b/frontend/app_flowy/lib/plugins/board/presentation/card/board_date_cell.dart new file mode 100644 index 0000000000..8270c7978b --- /dev/null +++ b/frontend/app_flowy/lib/plugins/board/presentation/card/board_date_cell.dart @@ -0,0 +1,21 @@ +import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_service.dart'; +import 'package:flutter/material.dart'; + +class BoardDateCell extends StatefulWidget { + final GridCellControllerBuilder cellControllerBuilder; + + const BoardDateCell({ + required this.cellControllerBuilder, + Key? key, + }) : super(key: key); + + @override + State createState() => _BoardDateCellState(); +} + +class _BoardDateCellState extends State { + @override + Widget build(BuildContext context) { + return Container(); + } +} diff --git a/frontend/app_flowy/lib/plugins/board/presentation/card/board_number_cell.dart b/frontend/app_flowy/lib/plugins/board/presentation/card/board_number_cell.dart new file mode 100644 index 0000000000..80797bc821 --- /dev/null +++ b/frontend/app_flowy/lib/plugins/board/presentation/card/board_number_cell.dart @@ -0,0 +1,21 @@ +import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_service.dart'; +import 'package:flutter/material.dart'; + +class BoardNumberCell extends StatefulWidget { + final GridCellControllerBuilder cellControllerBuilder; + + const BoardNumberCell({ + required this.cellControllerBuilder, + Key? key, + }) : super(key: key); + + @override + State createState() => _BoardNumberCellState(); +} + +class _BoardNumberCellState extends State { + @override + Widget build(BuildContext context) { + return Container(); + } +} diff --git a/frontend/app_flowy/lib/plugins/board/presentation/card/board_url_cell.dart b/frontend/app_flowy/lib/plugins/board/presentation/card/board_url_cell.dart new file mode 100644 index 0000000000..f7f084d6cd --- /dev/null +++ b/frontend/app_flowy/lib/plugins/board/presentation/card/board_url_cell.dart @@ -0,0 +1,21 @@ +import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_service.dart'; +import 'package:flutter/material.dart'; + +class BoardUrlCell extends StatefulWidget { + final GridCellControllerBuilder cellControllerBuilder; + + const BoardUrlCell({ + required this.cellControllerBuilder, + Key? key, + }) : super(key: key); + + @override + State createState() => _BoardUrlCellState(); +} + +class _BoardUrlCellState extends State { + @override + Widget build(BuildContext context) { + return Container(); + } +} 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 020cc49db3..6c66ec968a 100644 --- a/frontend/app_flowy/lib/plugins/board/presentation/card/card.dart +++ b/frontend/app_flowy/lib/plugins/board/presentation/card/card.dart @@ -1,13 +1,63 @@ -import 'package:app_flowy/plugins/grid/application/row/row_cache.dart'; +import 'package:app_flowy/plugins/board/application/card/card_bloc.dart'; +import 'package:app_flowy/plugins/board/application/card/card_data_controller.dart'; +import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_service.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; -class BoardCard extends StatelessWidget { - final RowInfo rowInfo; +import 'card_cell_builder.dart'; - const BoardCard({required this.rowInfo, Key? key}) : super(key: key); +class BoardCard extends StatefulWidget { + final String gridId; + final CardDataController dataController; + final BoardCellBuilder cellBuilder; + + const BoardCard({ + required this.gridId, + required this.dataController, + required this.cellBuilder, + Key? key, + }) : super(key: key); + + @override + State createState() => _BoardCardState(); +} + +class _BoardCardState extends State { + late BoardCardBloc _cardBloc; + + @override + void initState() { + _cardBloc = BoardCardBloc( + gridId: widget.gridId, + dataController: widget.dataController, + ); + super.initState(); + } @override Widget build(BuildContext context) { - return const SizedBox(height: 20, child: Text('1234')); + return BlocProvider.value( + value: _cardBloc, + child: BlocBuilder( + builder: (context, state) { + return SizedBox( + height: 100, + child: Column( + children: _makeCells(context, state.gridCellMap), + ), + ); + }, + ), + ); + } + + List _makeCells(BuildContext context, GridCellMap cellMap) { + return cellMap.values.map( + (cellId) { + final child = widget.cellBuilder.buildCell(cellId); + + return SizedBox(height: 39, child: child); + }, + ).toList(); } } 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 e69de29bb2..10ae0db680 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 @@ -0,0 +1,69 @@ +import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_service.dart'; +import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart'; +import 'package:flutter/material.dart'; + +import 'board_checkbox_cell.dart'; +import 'board_date_cell.dart'; +import 'board_number_cell.dart'; +import 'board_select_option_cell.dart'; +import 'board_text_cell.dart'; +import 'board_url_cell.dart'; + +abstract class BoardCellBuilderDelegate + extends GridCellControllerBuilderDelegate { + GridCellCache get cellCache; +} + +class BoardCellBuilder { + final BoardCellBuilderDelegate delegate; + + BoardCellBuilder(this.delegate); + + Widget buildCell(GridCellIdentifier cellId) { + final cellControllerBuilder = GridCellControllerBuilder( + delegate: delegate, + cellId: cellId, + cellCache: delegate.cellCache, + ); + + final key = cellId.key(); + switch (cellId.fieldType) { + case FieldType.Checkbox: + return BoardCheckboxCell( + cellControllerBuilder: cellControllerBuilder, + key: key, + ); + case FieldType.DateTime: + return BoardDateCell( + cellControllerBuilder: cellControllerBuilder, + key: key, + ); + case FieldType.SingleSelect: + return BoardSelectOptionCell( + cellControllerBuilder: cellControllerBuilder, + key: key, + ); + case FieldType.MultiSelect: + return BoardSelectOptionCell( + cellControllerBuilder: cellControllerBuilder, + key: key, + ); + case FieldType.Number: + return BoardNumberCell( + cellControllerBuilder: cellControllerBuilder, + key: key, + ); + case FieldType.RichText: + return BoardTextCell( + cellControllerBuilder: cellControllerBuilder, + key: key, + ); + case FieldType.URL: + return BoardUrlCell( + cellControllerBuilder: cellControllerBuilder, + key: key, + ); + } + throw UnimplementedError; + } +} diff --git a/frontend/app_flowy/lib/plugins/grid/application/grid_data_controller.dart b/frontend/app_flowy/lib/plugins/grid/application/grid_data_controller.dart index 32488599ea..aae6dc684e 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/grid_data_controller.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/grid_data_controller.dart @@ -46,7 +46,7 @@ class GridDataController { GridDataController({required ViewPB view}) : gridId = view.id, - _blocks = LinkedHashMap.identity(), + _blocks = LinkedHashMap.new(), _gridFFIService = GridService(gridId: view.id), fieldCache = GridFieldCache(gridId: view.id); diff --git a/frontend/app_flowy/lib/plugins/grid/application/row/row_action_sheet_bloc.dart b/frontend/app_flowy/lib/plugins/grid/application/row/row_action_sheet_bloc.dart index 0b4499682f..7e3e9a21bd 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/row/row_action_sheet_bloc.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/row/row_action_sheet_bloc.dart @@ -12,10 +12,10 @@ part 'row_action_sheet_bloc.freezed.dart'; class RowActionSheetBloc extends Bloc { - final RowService _rowService; + final RowFFIService _rowService; RowActionSheetBloc({required RowInfo rowData}) - : _rowService = RowService( + : _rowService = RowFFIService( gridId: rowData.gridId, blockId: rowData.blockId, rowId: rowData.id, diff --git a/frontend/app_flowy/lib/plugins/grid/application/row/row_bloc.dart b/frontend/app_flowy/lib/plugins/grid/application/row/row_bloc.dart index e6a68cd080..372287fd1f 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/row/row_bloc.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/row/row_bloc.dart @@ -12,13 +12,13 @@ import 'row_service.dart'; part 'row_bloc.freezed.dart'; class RowBloc extends Bloc { - final RowService _rowService; + final RowFFIService _rowService; final GridRowDataController _dataController; RowBloc({ required RowInfo rowInfo, required GridRowDataController dataController, - }) : _rowService = RowService( + }) : _rowService = RowFFIService( gridId: rowInfo.gridId, blockId: rowInfo.blockId, rowId: rowInfo.id, @@ -35,13 +35,12 @@ class RowBloc extends Bloc { _rowService.createRow(); }, didReceiveCells: (_DidReceiveCells value) async { - final fields = value.gridCellMap.values + final cells = value.gridCellMap.values .map((e) => GridCellEquatable(e.field)) .toList(); - final snapshots = UnmodifiableListView(fields); emit(state.copyWith( gridCellMap: value.gridCellMap, - snapshots: snapshots, + cells: UnmodifiableListView(cells), changeReason: value.reason, )); }, @@ -80,7 +79,7 @@ class RowState with _$RowState { const factory RowState({ required RowInfo rowInfo, required GridCellMap gridCellMap, - required UnmodifiableListView snapshots, + required UnmodifiableListView cells, RowChangeReason? changeReason, }) = _RowState; @@ -88,8 +87,9 @@ class RowState with _$RowState { RowState( rowInfo: rowInfo, gridCellMap: cellDataMap, - snapshots: UnmodifiableListView( - cellDataMap.values.map((e) => GridCellEquatable(e.field)).toList()), + cells: UnmodifiableListView( + cellDataMap.values.map((e) => GridCellEquatable(e.field)).toList(), + ), ); } diff --git a/frontend/app_flowy/lib/plugins/grid/application/row/row_data_controller.dart b/frontend/app_flowy/lib/plugins/grid/application/row/row_data_controller.dart index 31a54aa29b..78783fc894 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/row/row_data_controller.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/row/row_data_controller.dart @@ -13,10 +13,6 @@ class GridRowDataController extends GridCellBuilderDelegate { final GridFieldCache _fieldCache; final GridRowCache _rowCache; - GridFieldCache get fieldCache => _fieldCache; - - GridRowCache get rowCache => _rowCache; - GridRowDataController({ required this.rowInfo, required GridFieldCache fieldCache, @@ -49,5 +45,5 @@ class GridRowDataController extends GridCellBuilderDelegate { } @override - GridCellCache get cellCache => rowCache.cellCache; + GridCellCache get cellCache => _rowCache.cellCache; } diff --git a/frontend/app_flowy/lib/plugins/grid/application/row/row_service.dart b/frontend/app_flowy/lib/plugins/grid/application/row/row_service.dart index 94e047c1f7..0f056a4006 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/row/row_service.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/row/row_service.dart @@ -5,12 +5,12 @@ import 'package:flowy_sdk/protobuf/flowy-grid/block_entities.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/grid_entities.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/row_entities.pb.dart'; -class RowService { +class RowFFIService { final String gridId; final String blockId; final String rowId; - RowService( + RowFFIService( {required this.gridId, required this.blockId, required this.rowId}); Future> createRow() { diff --git a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/row/grid_row.dart b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/row/grid_row.dart index 6c995d57eb..3864c1a6a0 100755 --- a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/row/grid_row.dart +++ b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/row/grid_row.dart @@ -164,7 +164,7 @@ class RowContent extends StatelessWidget { Widget build(BuildContext context) { return BlocBuilder( buildWhen: (previous, current) => - !listEquals(previous.snapshots, current.snapshots), + !listEquals(previous.cells, current.cells), builder: (context, state) { return IntrinsicHeight( child: Row( diff --git a/frontend/app_flowy/lib/workspace/presentation/home/menu/menu_user.dart b/frontend/app_flowy/lib/workspace/presentation/home/menu/menu_user.dart index 3d9d76fe29..dc1e0de3d7 100644 --- a/frontend/app_flowy/lib/workspace/presentation/home/menu/menu_user.dart +++ b/frontend/app_flowy/lib/workspace/presentation/home/menu/menu_user.dart @@ -53,7 +53,7 @@ class MenuUser extends StatelessWidget { borderRadius: Corners.s5Border, child: CircleAvatar( backgroundColor: Colors.transparent, - child: svgWidget('emoji/$iconUrl'), + child: Container(), )), ); } diff --git a/frontend/rust-lib/flowy-folder/tests/workspace/script.rs b/frontend/rust-lib/flowy-folder/tests/workspace/script.rs index 5fb0be874c..528ffbcafb 100644 --- a/frontend/rust-lib/flowy-folder/tests/workspace/script.rs +++ b/frontend/rust-lib/flowy-folder/tests/workspace/script.rs @@ -150,7 +150,7 @@ impl FolderTest { // assert_eq!(json, expected_json); // } FolderScript::AssertWorkspace(workspace) => { - assert_eq!(self.workspace, workspace); + assert_eq!(self.workspace, workspace, "Workspace not equal"); } FolderScript::ReadWorkspace(workspace_id) => { let workspace = read_workspace(sdk, workspace_id).await.pop().unwrap(); @@ -166,7 +166,7 @@ impl FolderTest { // assert_eq!(json, expected_json); // } FolderScript::AssertApp(app) => { - assert_eq!(self.app, app); + assert_eq!(self.app, app, "App not equal"); } FolderScript::ReadApp(app_id) => { let app = read_app(sdk, &app_id).await; @@ -184,7 +184,7 @@ impl FolderTest { self.view = view; } FolderScript::AssertView(view) => { - assert_eq!(self.view, view); + assert_eq!(self.view, view, "View not equal"); } FolderScript::ReadView(view_id) => { let view = read_view(sdk, &view_id).await; @@ -215,7 +215,7 @@ impl FolderTest { } FolderScript::AssertRevisionState { rev_id, state } => { let record = cache.get(rev_id).await.unwrap(); - assert_eq!(record.state, state); + assert_eq!(record.state, state, "Revision state is not match"); if let RevisionState::Ack = state { // There is a defer action that writes the revisions to disk, so we wait here. // Make sure everything is written. @@ -235,7 +235,7 @@ impl FolderTest { .unwrap_or_else(|| panic!("Expected Next revision is {}, but receive None", rev_id.unwrap())); let mut notify = rev_manager.ack_notify(); let _ = notify.recv().await; - assert_eq!(next_revision.rev_id, rev_id.unwrap()); + assert_eq!(next_revision.rev_id, rev_id.unwrap(), "Revision id not match"); } } }