diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_data_loader.dart b/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_data_loader.dart index b779d227b1..c4b3430199 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_data_loader.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/cell_data_loader.dart @@ -5,14 +5,14 @@ abstract class IGridCellDataConfig { bool get reloadOnFieldChanged; } -abstract class ICellDataParser { +abstract class IGridCellDataParser { T? parserData(List data); } class GridCellDataLoader { final CellService service = CellService(); final GridCellIdentifier cellId; - final ICellDataParser parser; + final IGridCellDataParser parser; final bool reloadOnFieldChanged; GridCellDataLoader({ @@ -40,7 +40,7 @@ class GridCellDataLoader { } } -class StringCellDataParser implements ICellDataParser { +class StringCellDataParser implements IGridCellDataParser { @override String? parserData(List data) { final s = utf8.decode(data); @@ -48,7 +48,7 @@ class StringCellDataParser implements ICellDataParser { } } -class DateCellDataParser implements ICellDataParser { +class DateCellDataParser implements IGridCellDataParser { @override DateCellDataPB? parserData(List data) { if (data.isEmpty) { @@ -58,7 +58,7 @@ class DateCellDataParser implements ICellDataParser { } } -class SelectOptionCellDataParser implements ICellDataParser { +class SelectOptionCellDataParser implements IGridCellDataParser { @override SelectOptionCellDataPB? parserData(List data) { if (data.isEmpty) { @@ -68,7 +68,7 @@ class SelectOptionCellDataParser implements ICellDataParser { +class URLCellDataParser implements IGridCellDataParser { @override URLCellDataPB? parserData(List data) { if (data.isEmpty) { diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/context_builder.dart b/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/context_builder.dart index 8e51e33f29..48e88e56ac 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/context_builder.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/context_builder.dart @@ -52,6 +52,7 @@ class GridCellControllerBuilder { final cellDataLoader = GridCellDataLoader( cellId: _cellId, parser: StringCellDataParser(), + reloadOnFieldChanged: true, ); return GridCellController( cellId: _cellId, @@ -170,16 +171,13 @@ class IGridCellController extends Equatable { } isListening = true; - /// The cell data will be changed by two reasons: - /// 1. User edit the cell - /// 2. User edit the field - /// For example: The number cell reload the cell data that carries the format - /// user input: 12 - /// cell display: $12 _cellDataNotifier = ValueNotifier(_cellsCache.get(_cacheKey)); _cellListener = CellListener(rowId: cellId.rowId, fieldId: cellId.field.id); /// 1.Listen on user edit event and load the new cell data if needed. + /// For example: + /// user input: 12 + /// cell display: $12 _cellListener.start(onCellChanged: (result) { result.fold( (_) => _loadData(), @@ -193,6 +191,9 @@ class IGridCellController extends Equatable { onCellFieldChanged(); } + /// reloadOnFieldChanged should be true if you need to load the data when the corresponding field is changed + /// For example: + /// ¥12 -> $12 if (_cellDataLoader.reloadOnFieldChanged) { _loadData(); }