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.

Fix/0.1.3 (#2319)

Nathan.foood3363aba0fa5
diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/application/cell/cell_controller.dart b/frontend/appflowy_flutter/lib/plugins/database_view/application/cell/cell_controller.dart
index 25799ddaa2..804d0b8b81 100644
--- a/frontend/appflowy_flutter/lib/plugins/database_view/application/cell/cell_controller.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database_view/application/cell/cell_controller.dart
@@ -173,8 +173,8 @@ class CellController<T, D> extends Equatable {
void _loadData() {
_saveDataOperation?.cancel();
-
_loadDataOperation?.cancel();
+
_loadDataOperation = Timer(const Duration(milliseconds: 10), () {
_cellDataLoader.loadData().then((data) {
if (data != null) {
@@ -182,7 +182,6 @@ class CellController<T, D> extends Equatable {
} else {
_cellCache.remove(_cacheKey);
}
-
_cellDataNotifier?.value = data;
});
});
diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/application/cell/cell_controller_builder.dart b/frontend/appflowy_flutter/lib/plugins/database_view/application/cell/cell_controller_builder.dart
index 42c29dc3e4..cebc3caf10 100644
--- a/frontend/appflowy_flutter/lib/plugins/database_view/application/cell/cell_controller_builder.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database_view/application/cell/cell_controller_builder.dart
@@ -55,7 +55,7 @@ class CellControllerBuilder {
case FieldType.Number:
final cellDataLoader = CellDataLoader(
cellId: _cellId,
- parser: StringCellDataParser(),
+ parser: NumberCellDataParser(),
reloadOnFieldChanged: true,
);
return NumberCellController(
diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/application/cell/cell_data_loader.dart b/frontend/appflowy_flutter/lib/plugins/database_view/application/cell/cell_data_loader.dart
index f6c67e219e..13154029e2 100644
--- a/frontend/appflowy_flutter/lib/plugins/database_view/application/cell/cell_data_loader.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database_view/application/cell/cell_data_loader.dart
@@ -27,7 +27,12 @@ class CellDataLoader<T> {
(result) => result.fold(
(CellPB cell) {
try {
- return parser.parserData(cell.data);
+ // Return null the data of the cell is empty.
+ if (cell.data.isEmpty) {
+ return null;
+ } else {
+ return parser.parserData(cell.data);
+ }
} catch (e, s) {
Log.error('$parser parser cellData failed, $e');
Log.error('Stack trace \n $s');
@@ -51,6 +56,13 @@ class StringCellDataParser implements CellDataParser<String> {
}
}
+class NumberCellDataParser implements CellDataParser<String> {
+ @override
+ String? parserData(List<int> data) {
+ return utf8.decode(data);
+ }
+}
+
class DateCellDataParser implements CellDataParser<DateCellDataPB> {
@override
DateCellDataPB? parserData(List<int> data) {
diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/number_cell/number_cell_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/number_cell/number_cell_bloc.dart
index aab00be5c4..da152a3e5d 100644
--- a/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/number_cell/number_cell_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/number_cell/number_cell_bloc.dart
@@ -1,11 +1,11 @@
import 'package:appflowy/plugins/database_view/application/cell/cell_controller_builder.dart';
-import 'package:appflowy_backend/log.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'dart:async';
part 'number_cell_bloc.freezed.dart';
+//
class NumberCellBloc extends Bloc<NumberCellEvent, NumberCellState> {
final NumberCellController cellController;
void Function()? _onCellChangedFn;
@@ -22,17 +22,18 @@ class NumberCellBloc extends Bloc<NumberCellEvent, NumberCellState> {
didReceiveCellUpdate: (cellContent) {
emit(state.copyWith(cellContent: cellContent ?? ""));
},
- updateCell: (text) {
+ updateCell: (text) async {
if (state.cellContent != text) {
emit(state.copyWith(cellContent: text));
- cellController.saveCellData(
- text,
- onFinish: (result) {
- result.fold(
- () {},
- (err) => Log.error(err),
- );
- },
+ await cellController.saveCellData(text);
+
+ // If the input content is "abc" that can't parsered as number then the data stored in the backend will be an empty string.
+ // So for every cell data that will be formatted in the backend.
+ // It needs to get the formatted data after saving.
+ add(
+ NumberCellEvent.didReceiveCellUpdate(
+ cellController.getCellData(),
+ ),
);
}
},
diff --git a/frontend/rust-lib/flowy-document/src/editor/editor.rs b/frontend/rust-lib/flowy-document/src/editor/editor.rs
index 5c7566efe4..f0bb08785a 100644
--- a/frontend/rust-lib/flowy-document/src/editor/editor.rs
+++ b/frontend/rust-lib/flowy-document/src/editor/editor.rs
@@ -66,7 +66,8 @@ impl AppFlowyDocumentEditor {
pub async fn duplicate_document(&self) -> FlowyResult<String> {
let transaction = self.document_transaction().await?;
- let json = transaction.to_json()?;
+ let document = Document::from_transaction(transaction)?;
+ let json = serde_json::to_string(&document)?;
Ok(json)
}