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: remove row listener from rowbloc

appflowy0a19364ea7b6
diff --git a/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart
index 4d54081980..f38e874453 100644
--- a/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart
+++ b/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart
@@ -46,7 +46,6 @@ class GridBloc extends Bloc<GridEvent, GridState> {
await _gridService.closeGrid();
await fieldCache.dispose();
await rowCache.dispose();
- fieldCache.dispose();
return super.close();
}
diff --git a/frontend/app_flowy/lib/workspace/application/grid/grid_listener.dart b/frontend/app_flowy/lib/workspace/application/grid/grid_listener.dart
index fcff6fa15f..e6c7dc9de7 100644
--- a/frontend/app_flowy/lib/workspace/application/grid/grid_listener.dart
+++ b/frontend/app_flowy/lib/workspace/application/grid/grid_listener.dart
@@ -23,7 +23,7 @@ class GridRowListener {
void _handler(GridNotification ty, Either<Uint8List, FlowyError> result) {
switch (ty) {
- case GridNotification.DidUpdateGridBlock:
+ case GridNotification.DidUpdateGridRow:
result.fold(
(payload) => rowsUpdateNotifier.value = left([GridRowsChangeset.fromBuffer(payload)]),
(error) => rowsUpdateNotifier.value = right(error),
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 69731a0329..1f026a0af6 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
@@ -1,12 +1,9 @@
import 'dart:collection';
-
import 'package:app_flowy/workspace/application/grid/grid_service.dart';
-import 'package:flowy_sdk/log.dart';
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 'row_listener.dart';
import 'row_service.dart';
import 'package:dartz/dartz.dart';
@@ -16,7 +13,7 @@ typedef CellDataMap = LinkedHashMap<String, GridCellIdentifier>;
class RowBloc extends Bloc<RowEvent, RowState> {
final RowService _rowService;
- final RowListener _rowlistener;
+
final GridFieldCache _fieldCache;
final GridRowCache _rowCache;
@@ -25,7 +22,6 @@ class RowBloc extends Bloc<RowEvent, RowState> {
required GridFieldCache fieldCache,
required GridRowCache rowCache,
}) : _rowService = RowService(gridId: rowData.gridId, rowId: rowData.rowId),
- _rowlistener = RowListener(rowId: rowData.rowId),
_fieldCache = fieldCache,
_rowCache = rowCache,
super(RowState.initial(rowData)) {
@@ -76,27 +72,20 @@ class RowBloc extends Bloc<RowEvent, RowState> {
@override
Future<void> close() async {
- await _rowlistener.stop();
return super.close();
}
Future<void> _startListening() async {
- _rowlistener.updateRowNotifier?.addPublishListener(
- (result) {
- result.fold(
- (row) => add(RowEvent.didUpdateRow(row)),
- (err) => Log.error(err),
- );
- },
- listenWhen: () => !isClosed,
- );
-
_fieldCache.addListener(
listener: () => add(const RowEvent.fieldsDidUpdate()),
listenWhen: () => !isClosed,
);
- _rowlistener.start();
+ _rowCache.addRowListener(
+ rowId: state.rowData.rowId,
+ onUpdated: (row) => add(RowEvent.didUpdateRow(row)),
+ listenWhen: () => !isClosed,
+ );
}
Future<void> _loadRow(Emitter<RowState> emit) async {
diff --git a/frontend/app_flowy/lib/workspace/application/grid/row/row_service.dart b/frontend/app_flowy/lib/workspace/application/grid/row/row_service.dart
index c35466f5c3..bed21d1691 100644
--- a/frontend/app_flowy/lib/workspace/application/grid/row/row_service.dart
+++ b/frontend/app_flowy/lib/workspace/application/grid/row/row_service.dart
@@ -1,6 +1,5 @@
import 'dart:collection';
-import 'package:app_flowy/workspace/application/grid/grid_listener.dart';
import 'package:dartz/dartz.dart';
import 'package:flowy_sdk/dispatch/dispatch.dart';
import 'package:flowy_sdk/log.dart';
@@ -10,6 +9,8 @@ import 'package:flowy_sdk/protobuf/flowy-grid/row_entities.pb.dart';
import 'package:flutter/foundation.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
+import 'package:app_flowy/workspace/application/grid/grid_listener.dart';
+
part 'row_service.freezed.dart';
class RowService {
@@ -86,7 +87,6 @@ class GridRowCache {
late GridRowListener _rowsListener;
final RowsNotifier _rowNotifier = RowsNotifier();
final HashMap<String, Row> _rowDataMap = HashMap();
-
UnmodifiableListView<Field> _fields = UnmodifiableListView([]);
GridRowCache({required this.gridId}) {
@@ -113,8 +113,11 @@ class GridRowCache {
_rowNotifier.dispose();
}
- void addListener({void Function(List<GridRow>, GridRowChangeReason)? onChanged, bool Function()? listenWhen}) {
- _rowNotifier.addListener(() {
+ void addListener({
+ void Function(List<GridRow>, GridRowChangeReason)? onChanged,
+ bool Function()? listenWhen,
+ }) {
+ listener() {
if (listenWhen != null && listenWhen() == false) {
return;
}
@@ -122,6 +125,32 @@ class GridRowCache {
if (onChanged != null) {
onChanged(clonedRows, _rowNotifier._changeReason);
}
+ }
+
+ _rowNotifier.addListener(listener);
+ }
+
+ void addRowListener({
+ required String rowId,
+ void Function(Row)? onUpdated,
+ bool Function()? listenWhen,
+ }) {
+ _rowNotifier.addListener(() {
+ if (onUpdated == null) {
+ return;
+ }
+
+ if (listenWhen != null && listenWhen() == false) {
+ return;
+ }
+
+ _rowNotifier._changeReason.whenOrNull(update: (indexs) {
+ final updatedIndex = indexs.firstWhereOrNull((updatedIndex) => updatedIndex.rowId == rowId);
+ final row = _rowDataMap[rowId];
+ if (updatedIndex != null && row != null) {
+ onUpdated(row);
+ }
+ });
});
}
@@ -166,14 +195,14 @@ class GridRowCache {
}
final List<GridRow> newRows = [];
- final DeletedIndex deletedIndex = [];
+ final DeletedIndexs deletedIndex = [];
final Map<String, RowOrder> deletedRowMap = {for (var rowOrder in deletedRows) rowOrder.rowId: rowOrder};
- _rowNotifier.rows.asMap().forEach((index, value) {
- if (deletedRowMap[value.rowId] == null) {
- newRows.add(value);
+ _rowNotifier.rows.asMap().forEach((index, row) {
+ if (deletedRowMap[row.rowId] == null) {
+ newRows.add(row);
} else {
- deletedIndex.add(Tuple2(index, value));
+ deletedIndex.add(DeletedIndex(index: index, row: row));
}
});
@@ -189,7 +218,12 @@ class GridRowCache {
final List<GridRow> newRows = _rowNotifier.rows;
for (final createdRow in createdRows) {
final gridRow = GridRow.fromBlockRow(gridId, createdRow.rowOrder, _fields);
- insertIndexs.add(Tuple2(createdRow.index, gridRow.rowId));
+ insertIndexs.add(
+ InsertedIndex(
+ index: createdRow.index,
+ rowId: gridRow.rowId,
+ ),
+ );
newRows.insert(createdRow.index, gridRow);
}
_rowNotifier.updateRows(newRows, GridRowChangeReason.insert(insertIndexs));
@@ -200,14 +234,15 @@ class GridRowCache {
return;
}
- final List<int> updatedIndexs = [];
+ final UpdatedIndexs updatedIndexs = [];
final List<GridRow> newRows = _rowNotifier.rows;
for (final rowOrder in updatedRows) {
final index = newRows.indexWhere((row) => row.rowId == rowOrder.rowId);
if (index != -1) {
newRows.removeAt(index);
newRows.insert(index, GridRow.fromBlockRow(gridId, rowOrder, _fields));
- updatedIndexs.add(index);
+ _rowDataMap.remove(rowOrder.rowId);
+ updatedIndexs.add(UpdatedIndex(index: index, rowId: rowOrder.rowId));
}
}
@@ -246,13 +281,41 @@ class GridRow with _$GridRow {
}
}
-typedef InsertedIndexs = List<Tuple2<int, String>>;
-typedef DeletedIndex = List<Tuple2<int, GridRow>>;
+typedef InsertedIndexs = List<InsertedIndex>;
+typedef DeletedIndexs = List<DeletedIndex>;
+typedef UpdatedIndexs = List<UpdatedIndex>;
+
+class InsertedIndex {
+ int index;
+ String rowId;
+ InsertedIndex({
+ required this.index,
+ required this.rowId,
+ });
+}
+
+class DeletedIndex {
+ int index;
+ GridRow row;
+ DeletedIndex({
+ required this.index,
+ required this.row,
+ });
+}
+
+class UpdatedIndex {
+ int index;
+ String rowId;
+ UpdatedIndex({
+ required this.index,
+ required this.rowId,
+ });
+}
@freezed
class GridRowChangeReason with _$GridRowChangeReason {
const factory GridRowChangeReason.insert(InsertedIndexs items) = _Insert;
- const factory GridRowChangeReason.delete(DeletedIndex items) = _Delete;
- const factory GridRowChangeReason.update(List<int> indexs) = _Update;
+ const factory GridRowChangeReason.delete(DeletedIndexs items) = _Delete;
+ const factory GridRowChangeReason.update(UpdatedIndexs indexs) = _Update;
const factory GridRowChangeReason.initial() = InitialListState;
}
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 1a5f64c03a..c4b937300e 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
@@ -191,22 +191,20 @@ class _GridRowsState extends State<_GridRows> {
return BlocConsumer<GridBloc, GridState>(
listenWhen: (previous, current) => previous.listState != current.listState,
listener: (context, state) {
- state.listState.map(
+ state.listState.mapOrNull(
insert: (value) {
for (final item in value.items) {
- _key.currentState?.insertItem(item.value1);
+ _key.currentState?.insertItem(item.index);
}
},
delete: (value) {
for (final item in value.items) {
_key.currentState?.removeItem(
- item.value1,
- (context, animation) => _renderRow(context, item.value2, animation),
+ item.index,
+ (context, animation) => _renderRow(context, item.row, animation),
);
}
},
- initial: (_) {},
- update: (_) {},
);
},
buildWhen: (previous, current) => false,
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 7b43def65e..7a89d33361 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
@@ -12,19 +12,19 @@ import 'package:protobuf/protobuf.dart' as $pb;
class GridNotification extends $pb.ProtobufEnum {
static const GridNotification Unknown = GridNotification._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Unknown');
static const GridNotification DidCreateBlock = GridNotification._(11, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DidCreateBlock');
- static const GridNotification DidUpdateGridBlock = GridNotification._(20, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DidUpdateGridBlock');
+ static const GridNotification DidUpdateGridRow = GridNotification._(20, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DidUpdateGridRow');
+ static const GridNotification DidUpdateGridField = GridNotification._(21, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DidUpdateGridField');
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 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 GridNotification DidUpdateCell = GridNotification._(40, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DidUpdateCell');
+ static const GridNotification DidUpdateField = GridNotification._(50, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DidUpdateField');
static const $core.List<GridNotification> values = <GridNotification> [
Unknown,
DidCreateBlock,
- DidUpdateGridBlock,
+ DidUpdateGridRow,
+ DidUpdateGridField,
DidUpdateRow,
DidUpdateCell,
- 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 8c262092db..96a087ca40 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
@@ -14,13 +14,13 @@ const GridNotification$json = const {
'2': const [
const {'1': 'Unknown', '2': 0},
const {'1': 'DidCreateBlock', '2': 11},
- const {'1': 'DidUpdateGridBlock', '2': 20},
+ const {'1': 'DidUpdateGridRow', '2': 20},
+ const {'1': 'DidUpdateGridField', '2': 21},
const {'1': 'DidUpdateRow', '2': 30},
- const {'1': 'DidUpdateCell', '2': 31},
- const {'1': 'DidUpdateGridField', '2': 40},
- const {'1': 'DidUpdateField', '2': 41},
+ const {'1': 'DidUpdateCell', '2': 40},
+ const {'1': 'DidUpdateField', '2': 50},
],
};
/// Descriptor for `GridNotification`. Decode as a `google.protobuf.EnumDescriptorProto`.
-final $typed_data.Uint8List gridNotificationDescriptor = $convert.base64Decode('ChBHcmlkTm90aWZpY2F0aW9uEgsKB1Vua25vd24QABISCg5EaWRDcmVhdGVCbG9jaxALEhYKEkRpZFVwZGF0ZUdyaWRCbG9jaxAUEhAKDERpZFVwZGF0ZVJvdxAeEhEKDURpZFVwZGF0ZUNlbGwQHxIWChJEaWRVcGRhdGVHcmlkRmllbGQQKBISCg5EaWRVcGRhdGVGaWVsZBAp');
+final $typed_data.Uint8List gridNotificationDescriptor = $convert.base64Decode('ChBHcmlkTm90aWZpY2F0aW9uEgsKB1Vua25vd24QABISCg5EaWRDcmVhdGVCbG9jaxALEhQKEERpZFVwZGF0ZUdyaWRSb3cQFBIWChJEaWRVcGRhdGVHcmlkRmllbGQQFRIQCgxEaWRVcGRhdGVSb3cQHhIRCg1EaWRVcGRhdGVDZWxsECgSEgoORGlkVXBkYXRlRmllbGQQMg==');
diff --git a/frontend/rust-lib/flowy-grid/src/dart_notification.rs b/frontend/rust-lib/flowy-grid/src/dart_notification.rs
index 156ba9058a..92749da519 100644
--- a/frontend/rust-lib/flowy-grid/src/dart_notification.rs
+++ b/frontend/rust-lib/flowy-grid/src/dart_notification.rs
@@ -6,11 +6,11 @@ const OBSERVABLE_CATEGORY: &str = "Grid";
pub enum GridNotification {
Unknown = 0,
DidCreateBlock = 11,
- DidUpdateGridBlock = 20,
+ DidUpdateGridRow = 20,
+ DidUpdateGridField = 21,
DidUpdateRow = 30,
- DidUpdateCell = 31,
- DidUpdateGridField = 40,
- DidUpdateField = 41,
+ DidUpdateCell = 40,
+ DidUpdateField = 50,
}
impl std::default::Default for GridNotification {
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 338737c643..ff60cbf9e7 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
@@ -27,11 +27,11 @@
pub enum GridNotification {
Unknown = 0,
DidCreateBlock = 11,
- DidUpdateGridBlock = 20,
+ DidUpdateGridRow = 20,
+ DidUpdateGridField = 21,
DidUpdateRow = 30,
- DidUpdateCell = 31,
- DidUpdateGridField = 40,
- DidUpdateField = 41,
+ DidUpdateCell = 40,
+ DidUpdateField = 50,
}
impl ::protobuf::ProtobufEnum for GridNotification {
@@ -43,11 +43,11 @@ impl ::protobuf::ProtobufEnum for GridNotification {
match value {
0 => ::std::option::Option::Some(GridNotification::Unknown),
11 => ::std::option::Option::Some(GridNotification::DidCreateBlock),
- 20 => ::std::option::Option::Some(GridNotification::DidUpdateGridBlock),
+ 20 => ::std::option::Option::Some(GridNotification::DidUpdateGridRow),
+ 21 => ::std::option::Option::Some(GridNotification::DidUpdateGridField),
30 => ::std::option::Option::Some(GridNotification::DidUpdateRow),
- 31 => ::std::option::Option::Some(GridNotification::DidUpdateCell),
- 40 => ::std::option::Option::Some(GridNotification::DidUpdateGridField),
- 41 => ::std::option::Option::Some(GridNotification::DidUpdateField),
+ 40 => ::std::option::Option::Some(GridNotification::DidUpdateCell),
+ 50 => ::std::option::Option::Some(GridNotification::DidUpdateField),
_ => ::std::option::Option::None
}
}
@@ -56,10 +56,10 @@ impl ::protobuf::ProtobufEnum for GridNotification {
static values: &'static [GridNotification] = &[
GridNotification::Unknown,
GridNotification::DidCreateBlock,
- GridNotification::DidUpdateGridBlock,
+ GridNotification::DidUpdateGridRow,
+ GridNotification::DidUpdateGridField,
GridNotification::DidUpdateRow,
GridNotification::DidUpdateCell,
- 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*\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\x16\n\x12DidUpdateGridField\x10(\x12\x12\n\x0eDidUp\
- dateField\x10)b\x06proto3\
+ \n\x17dart_notification.proto*\x9a\x01\n\x10GridNotification\x12\x0b\n\
+ \x07Unknown\x10\0\x12\x12\n\x0eDidCreateBlock\x10\x0b\x12\x14\n\x10DidUp\
+ dateGridRow\x10\x14\x12\x16\n\x12DidUpdateGridField\x10\x15\x12\x10\n\
+ \x0cDidUpdateRow\x10\x1e\x12\x11\n\rDidUpdateCell\x10(\x12\x12\n\x0eDidU\
+ pdateField\x102b\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 a4e5188346..9a2899833f 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
@@ -3,9 +3,9 @@ syntax = "proto3";
enum GridNotification {
Unknown = 0;
DidCreateBlock = 11;
- DidUpdateGridBlock = 20;
+ DidUpdateGridRow = 20;
+ DidUpdateGridField = 21;
DidUpdateRow = 30;
- DidUpdateCell = 31;
- DidUpdateGridField = 40;
- DidUpdateField = 41;
+ DidUpdateCell = 40;
+ DidUpdateField = 50;
}
diff --git a/frontend/rust-lib/flowy-grid/src/services/block_meta_manager.rs b/frontend/rust-lib/flowy-grid/src/services/block_meta_manager.rs
index 2a8eae4497..58c623adc6 100644
--- a/frontend/rust-lib/flowy-grid/src/services/block_meta_manager.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/block_meta_manager.rs
@@ -2,13 +2,13 @@ use crate::dart_notification::{send_dart_notification, GridNotification};
use crate::manager::GridUser;
use crate::services::block_meta_editor::ClientGridBlockMetaEditor;
use crate::services::persistence::block_index::BlockIndexPersistence;
-use crate::services::row::{group_row_orders, make_rows_from_row_metas, GridBlockSnapshot};
+use crate::services::row::{group_row_orders, GridBlockSnapshot};
use std::borrow::Cow;
use dashmap::DashMap;
use flowy_error::FlowyResult;
use flowy_grid_data_model::entities::{
- CellChangeset, CellMeta, CellNotificationData, FieldMeta, GridBlockMeta, GridBlockMetaChangeset, GridRowsChangeset,
+ CellChangeset, CellMeta, CellNotificationData, GridBlockMeta, GridBlockMetaChangeset, GridRowsChangeset,
IndexRowOrder, RowMeta, RowMetaChangeset, RowOrder,
};
use flowy_revision::disk::SQLiteGridBlockMetaRevisionPersistence;
@@ -76,7 +76,7 @@ impl GridBlockMetaEditorManager {
index_row_order.index = row_index;
let _ = self
- .notify_did_update_rows(GridRowsChangeset::insert(block_id, vec![index_row_order]))
+ .notify_did_update_block(GridRowsChangeset::insert(block_id, vec![index_row_order]))
.await?;
Ok(row_count)
}
@@ -98,7 +98,7 @@ impl GridBlockMetaEditorManager {
changesets.push(GridBlockMetaChangeset::from_row_count(&block_id, row_count));
let _ = self
- .notify_did_update_rows(GridRowsChangeset::insert(&block_id, inserted_row_orders))
+ .notify_did_update_block(GridRowsChangeset::insert(&block_id, inserted_row_orders))
.await?;
}
@@ -108,19 +108,7 @@ impl GridBlockMetaEditorManager {
pub async fn update_row(&self, changeset: RowMetaChangeset) -> FlowyResult<()> {
let editor = self.get_editor_from_row_id(&changeset.row_id).await?;
let _ = editor.update_row(changeset.clone()).await?;
-
- match editor
- .get_row_orders(Some(vec![Cow::Borrowed(&changeset.row_id)]))
- .await?
- .pop()
- {
- None => {}
- Some(row_order) => {
- let block_order_changeset = GridRowsChangeset::update(&editor.block_id, vec![row_order]);
- let _ = self.notify_did_update_rows(block_order_changeset).await?;
- }
- }
-
+ let _ = self.notify_did_update_block_row(&changeset.row_id).await?;
Ok(())
}
@@ -131,7 +119,7 @@ impl GridBlockMetaEditorManager {
let row_orders = editor.get_row_orders(Some(vec![Cow::Borrowed(&row_id)])).await?;
let _ = editor.delete_rows(vec![Cow::Borrowed(&row_id)]).await?;
let _ = self
- .notify_did_update_rows(GridRowsChangeset::delete(&block_id, row_orders))
+ .notify_did_update_block(GridRowsChangeset::delete(&block_id, row_orders))
.await?;
Ok(())
@@ -173,7 +161,7 @@ impl GridBlockMetaEditorManager {
updated_rows: vec![],
};
- let _ = self.notify_did_update_rows(notified_changeset).await?;
+ let _ = self.notify_did_update_block(notified_changeset).await?;
}
}
@@ -181,10 +169,8 @@ impl GridBlockMetaEditorManager {
}
pub async fn update_cell(&self, changeset: CellChangeset) -> FlowyResult<()> {
- let row_id = changeset.row_id.clone();
- let editor = self.get_editor_from_row_id(&row_id).await?;
let row_changeset: RowMetaChangeset = changeset.clone().into();
- let _ = editor.update_row(row_changeset).await?;
+ let _ = self.update_row(row_changeset).await?;
let cell_notification_data = CellNotificationData {
grid_id: changeset.grid_id,
@@ -193,6 +179,7 @@ impl GridBlockMetaEditorManager {
content: changeset.data,
};
self.notify_did_update_cell(cell_notification_data).await?;
+
Ok(())
}
@@ -239,8 +226,22 @@ impl GridBlockMetaEditorManager {
Ok(block_cell_metas)
}
- async fn notify_did_update_rows(&self, changeset: GridRowsChangeset) -> FlowyResult<()> {
- send_dart_notification(&self.grid_id, GridNotification::DidUpdateGridBlock)
+ async fn notify_did_update_block_row(&self, row_id: &str) -> FlowyResult<()> {
+ let editor = self.get_editor_from_row_id(row_id).await?;
+ let row_ids = Some(vec![Cow::Borrowed(&row_id)]);
+ match editor.get_row_orders(row_ids).await?.pop() {
+ None => {}
+ Some(row_order) => {
+ let block_order_changeset = GridRowsChangeset::update(&editor.block_id, vec![row_order]);
+ let _ = self.notify_did_update_block(block_order_changeset).await?;
+ }
+ }
+
+ Ok(())
+ }
+
+ async fn notify_did_update_block(&self, changeset: GridRowsChangeset) -> FlowyResult<()> {
+ send_dart_notification(&self.grid_id, GridNotification::DidUpdateGridRow)
.payload(changeset)
.send();
Ok(())
@@ -253,22 +254,6 @@ impl GridBlockMetaEditorManager {
.send();
Ok(())
}
-
- #[allow(dead_code)]
- async fn notify_did_update_row(&self, row_id: &str, field_metas: &[FieldMeta]) -> FlowyResult<()> {
- match self.get_row_meta(row_id).await? {
- None => {}
- Some(row_meta) => {
- let row_metas = vec![row_meta];
- if let Some(row) = make_rows_from_row_metas(field_metas, &row_metas).pop() {
- send_dart_notification(row_id, GridNotification::DidUpdateRow)
- .payload(row)
- .send();
- }
- }
- }
- Ok(())
- }
}
async fn make_block_meta_editor_map(
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 b34e0fea65..2dd6e57ea5 100644
--- a/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs
+++ b/frontend/rust-lib/flowy-grid/src/services/grid_editor.rs
@@ -77,7 +77,7 @@ impl ClientGridEditor {
Ok(grid.update_field_meta(changeset, deserializer)?)
})
.await?;
- let _ = self.notify_grid_did_update_field(&field_id).await?;
+ let _ = self.notify_did_update_grid_field(&field_id).await?;
} else {
let _ = self
.modify(|grid| {
@@ -87,7 +87,7 @@ impl ClientGridEditor {
Ok(grid.create_field_meta(field_meta, start_field_id)?)
})
.await?;
- let _ = self.notify_grid_did_insert_field(&field_id).await?;
+ let _ = self.notify_did_insert_grid_field(&field_id).await?;
}
Ok(())
@@ -114,14 +114,14 @@ impl ClientGridEditor {
.modify(|grid| Ok(grid.update_field_meta(params, json_deserializer)?))
.await?;
- let _ = self.notify_grid_did_update_field(&field_id).await?;
+ let _ = self.notify_did_update_grid_field(&field_id).await?;
Ok(())
}
pub async fn replace_field(&self, field_meta: FieldMeta) -> FlowyResult<()> {
let field_id = field_meta.id.clone();
let _ = self.modify(|pad| Ok(pad.replace_field_meta(field_meta)?)).await?;
- let _ = self.notify_grid_did_update_field(&field_id).await?;
+ let _ = self.notify_did_update_grid_field(&field_id).await?;
Ok(())
}
@@ -153,7 +153,7 @@ impl ClientGridEditor {
.modify(|grid| Ok(grid.switch_to_field(field_id, field_type.clone(), type_option_json_builder)?))
.await?;
- let _ = self.notify_grid_did_update_field(field_id).await?;
+ let _ = self.notify_did_update_grid_field(field_id).await?;
Ok(())
}
@@ -164,7 +164,7 @@ impl ClientGridEditor {
.modify(|grid| Ok(grid.duplicate_field_meta(field_id, &duplicated_field_id)?))
.await?;
- let _ = self.notify_grid_did_insert_field(field_id).await?;
+ let _ = self.notify_did_insert_grid_field(field_id).await?;
Ok(())
}
@@ -462,7 +462,7 @@ impl ClientGridEditor {
}
#[tracing::instrument(level = "trace", skip_all, err)]
- async fn notify_grid_did_insert_field(&self, field_id: &str) -> FlowyResult<()> {
+ async fn notify_did_insert_grid_field(&self, field_id: &str) -> FlowyResult<()> {
if let Some((index, field_meta)) = self.pad.read().await.get_field_meta(field_id) {
let index_field = IndexField::from_field_meta(field_meta, index);
let notified_changeset = GridFieldChangeset::insert(&self.grid_id, vec![index_field]);
@@ -472,7 +472,7 @@ impl ClientGridEditor {
}
#[tracing::instrument(level = "trace", skip_all, err)]
- async fn notify_grid_did_update_field(&self, field_id: &str) -> FlowyResult<()> {
+ async fn notify_did_update_grid_field(&self, field_id: &str) -> FlowyResult<()> {
let mut field_metas = self.get_field_metas(Some(vec![field_id])).await?;
debug_assert!(field_metas.len() == 1);
diff --git a/shared-lib/flowy-sync/src/client_grid/grid_meta_pad.rs b/shared-lib/flowy-sync/src/client_grid/grid_meta_pad.rs
index f40b93233e..d91265e896 100644
--- a/shared-lib/flowy-sync/src/client_grid/grid_meta_pad.rs
+++ b/shared-lib/flowy-sync/src/client_grid/grid_meta_pad.rs
@@ -208,7 +208,7 @@ impl GridMetaPad {
pub fn move_field(
&mut self,
field_id: &str,
- from_index: usize,
+ _from_index: usize,
to_index: usize,
) -> CollaborateResult<Option<GridChangeset>> {
self.modify_grid(