diff --git a/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart b/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart index 42f6fa0694..0f2118fea1 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart @@ -162,7 +162,7 @@ class GridRowCache { } final List newRows = []; - final List> deletedIndex = []; + final DeletedIndex deletedIndex = []; final Map deletedRowMap = {for (var rowOrder in deletedRows) rowOrder.rowId: rowOrder}; _rows.asMap().forEach((index, value) { if (deletedRowMap[value.rowId] == null) { @@ -181,13 +181,13 @@ class GridRowCache { return none(); } - List insertIndexs = []; + InsertedIndexs insertIndexs = []; for (final newRow in createdRows) { if (newRow.hasIndex()) { - insertIndexs.add(newRow.index); + insertIndexs.add(Tuple2(newRow.index, newRow.rowOrder.rowId)); _rows.insert(newRow.index, _toRowData(newRow.rowOrder)); } else { - insertIndexs.add(_rows.length); + insertIndexs.add(Tuple2(newRow.index, newRow.rowOrder.rowId)); _rows.add(_toRowData(newRow.rowOrder)); } } @@ -216,9 +216,12 @@ class GridRowCache { } } +typedef InsertedIndexs = List>; +typedef DeletedIndex = List>; + @freezed class GridListState with _$GridListState { - const factory GridListState.insert(List indexs) = _Insert; - const factory GridListState.delete(List> indexs) = _Delete; + const factory GridListState.insert(InsertedIndexs items) = _Insert; + const factory GridListState.delete(DeletedIndex items) = _Delete; const factory GridListState.initial() = InitialListState; } diff --git a/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart index b16d75dc92..81bb8b190c 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart @@ -35,20 +35,23 @@ class RowBloc extends Bloc { _rowService.createRow(); }, didUpdateRow: (_DidUpdateRow value) async { - _handleRowUpdate(value, emit); + _handleRowUpdate(value.row, emit); }, fieldsDidUpdate: (_FieldsDidUpdate value) async { await _handleFieldUpdate(emit); }, + didLoadRow: (_DidLoadRow value) { + _handleRowUpdate(value.row, emit); + }, ); }, ); } - void _handleRowUpdate(_DidUpdateRow value, Emitter emit) { - final CellDataMap cellDataMap = _makeCellDatas(value.row, state.rowData.fields); + void _handleRowUpdate(Row row, Emitter emit) { + final CellDataMap cellDataMap = _makeCellDatas(row, state.rowData.fields); emit(state.copyWith( - row: Future(() => Some(value.row)), + row: Future(() => Some(row)), cellDataMap: Some(cellDataMap), )); } @@ -75,7 +78,11 @@ class RowBloc extends Bloc { Future _startListening() async { _rowlistener.updateRowNotifier?.addPublishListener((result) { result.fold( - (row) => add(RowEvent.didUpdateRow(row)), + (row) { + if (!isClosed) { + add(RowEvent.didUpdateRow(row)); + } + }, (err) => Log.error(err), ); }); @@ -92,7 +99,11 @@ class RowBloc extends Bloc { Future _loadRow(Emitter emit) async { _rowService.getRow().then((result) { return result.fold( - (row) => add(RowEvent.didUpdateRow(row)), + (row) { + if (!isClosed) { + add(RowEvent.didLoadRow(row)); + } + }, (err) => Log.error(err), ); }); @@ -119,6 +130,7 @@ class RowEvent with _$RowEvent { const factory RowEvent.initial() = _InitialRow; const factory RowEvent.createRow() = _CreateRow; const factory RowEvent.fieldsDidUpdate() = _FieldsDidUpdate; + const factory RowEvent.didLoadRow(Row row) = _DidLoadRow; const factory RowEvent.didUpdateRow(Row row) = _DidUpdateRow; } diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/grid_page.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/grid_page.dart index 1c7707c8eb..74215f4b80 100755 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/grid_page.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/grid_page.dart @@ -6,7 +6,6 @@ import 'package:flowy_infra_ui/style_widget/scrolling/styled_scroll_bar.dart'; import 'package:flowy_infra_ui/style_widget/scrolling/styled_scrollview.dart'; import 'package:flowy_infra_ui/widget/error_page.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart' show Field; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter/material.dart'; import 'package:linked_scroll_controller/linked_scroll_controller.dart'; @@ -193,15 +192,15 @@ class _GridRowsState extends State<_GridRows> { listener: (context, state) { state.listState.map( insert: (value) { - for (final index in value.indexs) { - _key.currentState?.insertItem(index); + for (final item in value.items) { + _key.currentState?.insertItem(item.value1); } }, delete: (value) { - for (final index in value.indexs) { + for (final item in value.items) { _key.currentState?.removeItem( - index.value1, - (context, animation) => _renderRow(context, index.value2, animation), + item.value1, + (context, animation) => _renderRow(context, item.value2, animation), ); } }, @@ -224,6 +223,7 @@ class _GridRowsState extends State<_GridRows> { Widget _renderRow(BuildContext context, RowData rowData, Animation animation) { final fieldCache = context.read().fieldCache; + return SizeTransition( sizeFactor: animation, child: GridRowWidget( diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_container.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_container.dart index 0ff4ae71ab..c9af10c2b8 100755 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_container.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_container.dart @@ -33,7 +33,7 @@ class CellContainer extends StatelessWidget { child: Consumer( builder: (context, state, _) { return Container( - constraints: BoxConstraints(maxWidth: width, maxHeight: 42), + constraints: BoxConstraints(maxWidth: width), decoration: _makeBoxDecoration(context, state), padding: GridSize.cellContentInsets, child: Center(child: child), diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/grid_row.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/grid_row.dart index b63f79f5b0..edac8bc2fe 100755 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/grid_row.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/grid_row.dart @@ -44,8 +44,8 @@ class _GridRowWidgetState extends State { child: BlocBuilder( buildWhen: (p, c) => p.rowData.height != c.rowData.height, builder: (context, state) { - return LimitedBox( - maxHeight: 200, + return SizedBox( + height: 42, child: Row( mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.center,