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() {
|
void _loadData() {
|
||||||
_saveDataOperation?.cancel();
|
_saveDataOperation?.cancel();
|
||||||
|
|
||||||
_loadDataOperation?.cancel();
|
_loadDataOperation?.cancel();
|
||||||
|
|
||||||
_loadDataOperation = Timer(const Duration(milliseconds: 10), () {
|
_loadDataOperation = Timer(const Duration(milliseconds: 10), () {
|
||||||
_cellDataLoader.loadData().then((data) {
|
_cellDataLoader.loadData().then((data) {
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
@ -182,7 +182,6 @@ class CellController<T, D> extends Equatable {
|
|||||||
} else {
|
} else {
|
||||||
_cellCache.remove(_cacheKey);
|
_cellCache.remove(_cacheKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
_cellDataNotifier?.value = data;
|
_cellDataNotifier?.value = data;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -55,7 +55,7 @@ class CellControllerBuilder {
|
|||||||
case FieldType.Number:
|
case FieldType.Number:
|
||||||
final cellDataLoader = CellDataLoader(
|
final cellDataLoader = CellDataLoader(
|
||||||
cellId: _cellId,
|
cellId: _cellId,
|
||||||
parser: StringCellDataParser(),
|
parser: NumberCellDataParser(),
|
||||||
reloadOnFieldChanged: true,
|
reloadOnFieldChanged: true,
|
||||||
);
|
);
|
||||||
return NumberCellController(
|
return NumberCellController(
|
||||||
|
@ -27,7 +27,12 @@ class CellDataLoader<T> {
|
|||||||
(result) => result.fold(
|
(result) => result.fold(
|
||||||
(CellPB cell) {
|
(CellPB cell) {
|
||||||
try {
|
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) {
|
} catch (e, s) {
|
||||||
Log.error('$parser parser cellData failed, $e');
|
Log.error('$parser parser cellData failed, $e');
|
||||||
Log.error('Stack trace \n $s');
|
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> {
|
class DateCellDataParser implements CellDataParser<DateCellDataPB> {
|
||||||
@override
|
@override
|
||||||
DateCellDataPB? parserData(List<int> data) {
|
DateCellDataPB? parserData(List<int> data) {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import 'package:appflowy/plugins/database_view/application/cell/cell_controller_builder.dart';
|
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:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
part 'number_cell_bloc.freezed.dart';
|
part 'number_cell_bloc.freezed.dart';
|
||||||
|
|
||||||
|
//
|
||||||
class NumberCellBloc extends Bloc<NumberCellEvent, NumberCellState> {
|
class NumberCellBloc extends Bloc<NumberCellEvent, NumberCellState> {
|
||||||
final NumberCellController cellController;
|
final NumberCellController cellController;
|
||||||
void Function()? _onCellChangedFn;
|
void Function()? _onCellChangedFn;
|
||||||
@ -22,17 +22,18 @@ class NumberCellBloc extends Bloc<NumberCellEvent, NumberCellState> {
|
|||||||
didReceiveCellUpdate: (cellContent) {
|
didReceiveCellUpdate: (cellContent) {
|
||||||
emit(state.copyWith(cellContent: cellContent ?? ""));
|
emit(state.copyWith(cellContent: cellContent ?? ""));
|
||||||
},
|
},
|
||||||
updateCell: (text) {
|
updateCell: (text) async {
|
||||||
if (state.cellContent != text) {
|
if (state.cellContent != text) {
|
||||||
emit(state.copyWith(cellContent: text));
|
emit(state.copyWith(cellContent: text));
|
||||||
cellController.saveCellData(
|
await cellController.saveCellData(text);
|
||||||
text,
|
|
||||||
onFinish: (result) {
|
// If the input content is "abc" that can't parsered as number then the data stored in the backend will be an empty string.
|
||||||
result.fold(
|
// So for every cell data that will be formatted in the backend.
|
||||||
() {},
|
// It needs to get the formatted data after saving.
|
||||||
(err) => Log.error(err),
|
add(
|
||||||
);
|
NumberCellEvent.didReceiveCellUpdate(
|
||||||
},
|
cellController.getCellData(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -66,7 +66,8 @@ impl AppFlowyDocumentEditor {
|
|||||||
|
|
||||||
pub async fn duplicate_document(&self) -> FlowyResult<String> {
|
pub async fn duplicate_document(&self) -> FlowyResult<String> {
|
||||||
let transaction = self.document_transaction().await?;
|
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)
|
Ok(json)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user