mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
Fix/0.1.3 (#2319)
* fix: duplicate document * fix: number cell data parser
This commit is contained in:
parent
d804e3ed6d
commit
d3363aba0f
@ -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;
|
||||
});
|
||||
});
|
||||
|
@ -55,7 +55,7 @@ class CellControllerBuilder {
|
||||
case FieldType.Number:
|
||||
final cellDataLoader = CellDataLoader(
|
||||
cellId: _cellId,
|
||||
parser: StringCellDataParser(),
|
||||
parser: NumberCellDataParser(),
|
||||
reloadOnFieldChanged: true,
|
||||
);
|
||||
return NumberCellController(
|
||||
|
@ -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) {
|
||||
|
@ -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(),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user