Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

chore: fix row rebuild refresh issue

appflowyac766c035938
diff --git a/frontend/app_flowy/lib/startup/tasks/app_widget.dart b/frontend/app_flowy/lib/startup/tasks/app_widget.dart
index 3dba94ce0a..1747cfd8ec 100644
--- a/frontend/app_flowy/lib/startup/tasks/app_widget.dart
+++ b/frontend/app_flowy/lib/startup/tasks/app_widget.dart
@@ -113,7 +113,7 @@ class ApplicationBlocObserver extends BlocObserver {
// ignore: unnecessary_overrides
void onTransition(Bloc bloc, Transition transition) {
// Log.debug("[current]: ${transition.currentState} \n\n[next]: ${transition.nextState}");
- Log.debug("${transition.nextState}");
+ // Log.debug("${transition.nextState}");
super.onTransition(bloc, transition);
}
@@ -123,9 +123,9 @@ class ApplicationBlocObserver extends BlocObserver {
super.onError(bloc, error, stackTrace);
}
- @override
- void onEvent(Bloc bloc, Object? event) {
- // Log.debug("$event");
- super.onEvent(bloc, event);
- }
+ // @override
+ // void onEvent(Bloc bloc, Object? event) {
+ // Log.debug("$event");
+ // super.onEvent(bloc, event);
+ // }
}
diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/grid_listenr.dart b/frontend/app_flowy/lib/workspace/application/grid/field/grid_listenr.dart
index d823207f83..c257fe3c0d 100644
--- a/frontend/app_flowy/lib/workspace/application/grid/field/grid_listenr.dart
+++ b/frontend/app_flowy/lib/workspace/application/grid/field/grid_listenr.dart
@@ -24,7 +24,7 @@ class GridFieldsListener {
void _handler(GridNotification ty, Either<Uint8List, FlowyError> result) {
switch (ty) {
- case GridNotification.DidUpdateGrid:
+ case GridNotification.DidUpdateGridField:
result.fold(
(payload) => updateFieldsNotifier.value = left(GridFieldChangeset.fromBuffer(payload)),
(error) => updateFieldsNotifier.value = right(error),
diff --git a/frontend/app_flowy/lib/workspace/application/grid/grid_header_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/grid_header_bloc.dart
index c7ce6c21f1..13f65ff4d6 100644
--- a/frontend/app_flowy/lib/workspace/application/grid/grid_header_bloc.dart
+++ b/frontend/app_flowy/lib/workspace/application/grid/grid_header_bloc.dart
@@ -2,20 +2,18 @@ import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'dart:async';
-import 'field/field_service.dart';
import 'grid_service.dart';
part 'grid_header_bloc.freezed.dart';
class GridHeaderBloc extends Bloc<GridHeaderEvent, GridHeaderState> {
- final FieldService _fieldService;
+ // final FieldService _fieldService;
final GridFieldCache fieldCache;
GridHeaderBloc({
required String gridId,
required this.fieldCache,
- }) : _fieldService = FieldService(gridId: gridId),
- super(GridHeaderState.initial(fieldCache.clonedFields)) {
+ }) : super(GridHeaderState.initial(fieldCache.clonedFields)) {
on<GridHeaderEvent>(
(event, emit) async {
await event.map(
@@ -31,7 +29,7 @@ class GridHeaderBloc extends Bloc<GridHeaderEvent, GridHeaderState> {
}
Future<void> _startListening() async {
- fieldCache.listenOnFieldChanged((fields) {
+ fieldCache.addListener(() {}, onChanged: (fields) {
if (!isClosed) {
add(GridHeaderEvent.didReceiveFieldUpdate(fields));
}
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 fc853ef8b7..b79c2e5e59 100644
--- a/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart
+++ b/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart
@@ -74,6 +74,15 @@ class GridFieldCache {
_fieldNotifier.addListener(() => onFieldChanged(clonedFields));
}
+ void addListener(VoidCallback listener, {void Function(List<Field>)? onChanged}) {
+ _fieldNotifier.addListener(() {
+ if (onChanged != null) {
+ onChanged(clonedFields);
+ }
+ listener();
+ });
+ }
+
void _removeFields(List<FieldOrder> deletedFields) {
if (deletedFields.isEmpty) {
return;
@@ -130,7 +139,7 @@ class GridRowCache {
GridRowCache({required this.gridId});
- List<RowData> get rows => _rows;
+ List<RowData> get rows => [..._rows];
void updateWithBlock(List<GridBlockOrder> blocks, UnmodifiableListView<Field> fields) {
_fields = fields;
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 d6bc43e50e..dbbe9b054d 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
@@ -34,12 +34,12 @@ class RowBloc extends Bloc<RowEvent, RowState> {
createRow: (_CreateRow value) {
_rowService.createRow();
},
- didReceiveFieldUpdate: (_DidReceiveFieldUpdate value) async {
- await _handleFieldUpdate(emit, value);
- },
didUpdateRow: (_DidUpdateRow value) async {
_handleRowUpdate(value, emit);
},
+ fieldsDidUpdate: (_FieldsDidUpdate value) async {
+ await _handleFieldUpdate(emit);
+ },
);
},
);
@@ -53,15 +53,15 @@ class RowBloc extends Bloc<RowEvent, RowState> {
));
}
- Future<void> _handleFieldUpdate(Emitter<RowState> emit, _DidReceiveFieldUpdate value) async {
+ Future<void> _handleFieldUpdate(Emitter<RowState> emit) async {
final optionRow = await state.row;
final CellDataMap cellDataMap = optionRow.fold(
() => CellDataMap.identity(),
- (row) => _makeCellDatas(row, value.fields),
+ (row) => _makeCellDatas(row, _fieldCache.unmodifiableFields),
);
emit(state.copyWith(
- rowData: state.rowData.copyWith(fields: value.fields),
+ rowData: state.rowData.copyWith(fields: _fieldCache.unmodifiableFields),
cellDataMap: Some(cellDataMap),
));
}
@@ -80,9 +80,9 @@ class RowBloc extends Bloc<RowEvent, RowState> {
);
});
- _fieldCache.listenOnFieldChanged((fields) {
+ _fieldCache.addListener(() {
if (!isClosed) {
- // add(RowEvent.didReceiveFieldUpdate(fields));
+ add(const RowEvent.fieldsDidUpdate());
}
});
@@ -118,7 +118,7 @@ class RowBloc extends Bloc<RowEvent, RowState> {
class RowEvent with _$RowEvent {
const factory RowEvent.initial() = _InitialRow;
const factory RowEvent.createRow() = _CreateRow;
- const factory RowEvent.didReceiveFieldUpdate(List<Field> fields) = _DidReceiveFieldUpdate;
+ const factory RowEvent.fieldsDidUpdate() = _FieldsDidUpdate;
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 5a772693c7..a3f8a3e064 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
@@ -40,7 +40,7 @@ class _GridPageState extends State<GridPage> {
return state.loadingState.map(
loading: (_) => const Center(child: CircularProgressIndicator.adaptive()),
finish: (result) => result.successOrFail.fold(
- (_) => FlowyGrid(),
+ (_) => const FlowyGrid(),
(err) => FlowyErrorPage(err.toString()),
),
);
@@ -65,9 +65,15 @@ class _GridPageState extends State<GridPage> {
}
}
-class FlowyGrid extends StatelessWidget {
+class FlowyGrid extends StatefulWidget {
+ const FlowyGrid({Key? key}) : super(key: key);
+
+ @override
+ State<FlowyGrid> createState() => _FlowyGridState();
+}
+
+class _FlowyGridState extends State<FlowyGrid> {
final _scrollController = GridScrollController();
- FlowyGrid({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
@@ -155,9 +161,15 @@ class _GridHeader extends StatelessWidget {
}
}
-class _GridRows extends StatelessWidget {
+class _GridRows extends StatefulWidget {
+ const _GridRows({Key? key}) : super(key: key);
+
+ @override
+ State<_GridRows> createState() => _GridRowsState();
+}
+
+class _GridRowsState extends State<_GridRows> {
final _key = GlobalKey<SliverAnimatedListState>();
- _GridRows({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
diff --git a/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid/dart_notification.pbenum.dart b/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid/dart_notification.pbenum.dart
index d39002e540..7b43def65e 100644
--- a/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid/dart_notification.pbenum.dart
+++ b/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid/dart_notification.pbenum.dart
@@ -15,7 +15,7 @@ class GridNotification extends $pb.ProtobufEnum {
static const GridNotification DidUpdateGridBlock = GridNotification._(20, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DidUpdateGridBlock');
static const GridNotification DidUpdateRow = GridNotification._(30, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DidUpdateRow');
static const GridNotification DidUpdateCell = GridNotification._(31, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DidUpdateCell');
- static const GridNotification DidUpdateGrid = GridNotification._(40, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DidUpdateGrid');
+ static const GridNotification DidUpdateGridField = GridNotification._(40, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DidUpdateGridField');
static const GridNotification DidUpdateField = GridNotification._(41, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DidUpdateField');
static const $core.List<GridNotification> values = <GridNotification> [
@@ -24,7 +24,7 @@ class GridNotification extends $pb.ProtobufEnum {
DidUpdateGridBlock,
DidUpdateRow,
DidUpdateCell,
- DidUpdateGrid,
+ DidUpdateGridField,
DidUpdateField,
];
diff --git a/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid/dart_notification.pbjson.dart b/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid/dart_notification.pbjson.dart
index 787a77ffa1..8c262092db 100644
--- a/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid/dart_notification.pbjson.dart
+++ b/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid/dart_notification.pbjson.dart
@@ -17,10 +17,10 @@ const GridNotification$json = const {
const {'1': 'DidUpdateGridBlock', '2': 20},
const {'1': 'DidUpdateRow', '2': 30},
const {'1': 'DidUpdateCell', '2': 31},
- const {'1': 'DidUpdateGrid', '2': 40},
+ const {'1': 'DidUpdateGridField', '2': 40},
const {'1': 'DidUpdateField', '2': 41},
],
};
/// Descriptor for `GridNotification`. Decode as a `google.protobuf.EnumDescriptorProto`.
-final $typed_data.Uint8List gridNotificationDescriptor = $convert.base64Decode('ChBHcmlkTm90aWZpY2F0aW9uEgsKB1Vua25vd24QABISCg5EaWRDcmVhdGVCbG9jaxALEhYKEkRpZFVwZGF0ZUdyaWRCbG9jaxAUEhAKDERpZFVwZGF0ZVJvdxAeEhEKDURpZFVwZGF0ZUNlbGwQHxIRCg1EaWRVcGRhdGVHcmlkECgSEgoORGlkVXBkYXRlRmllbGQQKQ==');
+final $typed_data.Uint8List gridNotificationDescriptor = $convert.base64Decode('ChBHcmlkTm90aWZpY2F0aW9uEgsKB1Vua25vd24QABISCg5EaWRDcmVhdGVCbG9jaxALEhYKEkRpZFVwZGF0ZUdyaWRCbG9jaxAUEhAKDERpZFVwZGF0ZVJvdxAeEhEKDURpZFVwZGF0ZUNlbGwQHxIWChJEaWRVcGRhdGVHcmlkRmllbGQQKBISCg5EaWRVcGRhdGVGaWVsZBAp');
diff --git a/frontend/rust-lib/flowy-grid/src/dart_notification.rs b/frontend/rust-lib/flowy-grid/src/dart_notification.rs
index a2a1de0a9f..156ba9058a 100644
--- a/frontend/rust-lib/flowy-grid/src/dart_notification.rs
+++ b/frontend/rust-lib/flowy-grid/src/dart_notification.rs
@@ -9,7 +9,7 @@ pub enum GridNotification {
DidUpdateGridBlock = 20,
DidUpdateRow = 30,
DidUpdateCell = 31,
- DidUpdateGrid = 40,
+ DidUpdateGridField = 40,
DidUpdateField = 41,
}
diff --git a/frontend/rust-lib/flowy-grid/src/protobuf/model/dart_notification.rs b/frontend/rust-lib/flowy-grid/src/protobuf/model/dart_notification.rs
index 326ae3ef4e..338737c643 100644
--- a/frontend/rust-lib/flowy-grid/src/protobuf/model/dart_notification.rs
+++ b/frontend/rust-lib/flowy-grid/src/protobuf/model/dart_notification.rs
@@ -30,7 +30,7 @@ pub enum GridNotification {
DidUpdateGridBlock = 20,
DidUpdateRow = 30,
DidUpdateCell = 31,
- DidUpdateGrid = 40,
+ DidUpdateGridField = 40,
DidUpdateField = 41,
}
@@ -46,7 +46,7 @@ impl ::protobuf::ProtobufEnum for GridNotification {
20 => ::std::option::Option::Some(GridNotification::DidUpdateGridBlock),
30 => ::std::option::Option::Some(GridNotification::DidUpdateRow),
31 => ::std::option::Option::Some(GridNotification::DidUpdateCell),
- 40 => ::std::option::Option::Some(GridNotification::DidUpdateGrid),
+ 40 => ::std::option::Option::Some(GridNotification::DidUpdateGridField),
41 => ::std::option::Option::Some(GridNotification::DidUpdateField),
_ => ::std::option::Option::None
}
@@ -59,7 +59,7 @@ impl ::protobuf::ProtobufEnum for GridNotification {
GridNotification::DidUpdateGridBlock,
GridNotification::DidUpdateRow,
GridNotification::DidUpdateCell,
- GridNotification::DidUpdateGrid,
+ GridNotification::DidUpdateGridField,
GridNotification::DidUpdateField,
];
values
@@ -89,11 +89,11 @@ impl ::protobuf::reflect::ProtobufValue for GridNotification {
}
static file_descriptor_proto_data: &'static [u8] = b"\
- \n\x17dart_notification.proto*\x97\x01\n\x10GridNotification\x12\x0b\n\
+ \n\x17dart_notification.proto*\x9c\x01\n\x10GridNotification\x12\x0b\n\
\x07Unknown\x10\0\x12\x12\n\x0eDidCreateBlock\x10\x0b\x12\x16\n\x12DidUp\
dateGridBlock\x10\x14\x12\x10\n\x0cDidUpdateRow\x10\x1e\x12\x11\n\rDidUp\
- dateCell\x10\x1f\x12\x11\n\rDidUpdateGrid\x10(\x12\x12\n\x0eDidUpdateFie\
- ld\x10)b\x06proto3\
+ dateCell\x10\x1f\x12\x16\n\x12DidUpdateGridField\x10(\x12\x12\n\x0eDidUp\
+ dateField\x10)b\x06proto3\
";
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;
diff --git a/frontend/rust-lib/flowy-grid/src/protobuf/proto/dart_notification.proto b/frontend/rust-lib/flowy-grid/src/protobuf/proto/dart_notification.proto
index 20cf529f3e..a4e5188346 100644
--- a/frontend/rust-lib/flowy-grid/src/protobuf/proto/dart_notification.proto
+++ b/frontend/rust-lib/flowy-grid/src/protobuf/proto/dart_notification.proto
@@ -6,6 +6,6 @@ enum GridNotification {
DidUpdateGridBlock = 20;
DidUpdateRow = 30;
DidUpdateCell = 31;
- DidUpdateGrid = 40;
+ DidUpdateGridField = 40;
DidUpdateField = 41;
}
diff --git a/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs b/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs
index 5cd4ebca87..357c38ba0e 100644
--- a/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs
@@ -473,7 +473,7 @@ impl ClientGridEditor {
}
async fn notify_did_update_grid(&self, changeset: GridFieldChangeset) -> FlowyResult<()> {
- send_dart_notification(&self.grid_id, GridNotification::DidUpdateGrid)
+ send_dart_notification(&self.grid_id, GridNotification::DidUpdateGridField)
.payload(changeset)
.send();
Ok(())