From d3363aba0fa53ae072d5b941e1fba6640daf7641 Mon Sep 17 00:00:00 2001 From: "Nathan.fooo" <86001920+appflowy@users.noreply.github.com> Date: Sat, 22 Apr 2023 11:57:35 +0800 Subject: [PATCH] Fix/0.1.3 (#2319) * fix: duplicate document * fix: number cell data parser --- .../application/cell/cell_controller.dart | 3 +-- .../cell/cell_controller_builder.dart | 2 +- .../application/cell/cell_data_loader.dart | 14 ++++++++++++- .../cells/number_cell/number_cell_bloc.dart | 21 ++++++++++--------- .../flowy-document/src/editor/editor.rs | 3 ++- 5 files changed, 28 insertions(+), 15 deletions(-) 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 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 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 { (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 { } } +class NumberCellDataParser implements CellDataParser { + @override + String? parserData(List data) { + return utf8.decode(data); + } +} + class DateCellDataParser implements CellDataParser { @override DateCellDataPB? parserData(List 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 { final NumberCellController cellController; void Function()? _onCellChangedFn; @@ -22,17 +22,18 @@ class NumberCellBloc extends Bloc { 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 { 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) }