mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: bugs
This commit is contained in:
parent
af5f42d296
commit
6d385877a9
@ -18,7 +18,6 @@ import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/date_type_option.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/number_type_option.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/selection_type_option.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
|
||||
@ -169,13 +168,13 @@ void _resolveGridDeps(GetIt getIt) {
|
||||
),
|
||||
);
|
||||
|
||||
getIt.registerFactoryParam<TextCellBloc, GridCellContext, void>(
|
||||
getIt.registerFactoryParam<TextCellBloc, GridDefaultCellContext, void>(
|
||||
(context, _) => TextCellBloc(
|
||||
cellContext: context,
|
||||
),
|
||||
);
|
||||
|
||||
getIt.registerFactoryParam<SelectionCellBloc, GridCellContext<SelectOptionContext>, void>(
|
||||
getIt.registerFactoryParam<SelectionCellBloc, GridSelectOptionCellContext, void>(
|
||||
(context, _) => SelectionCellBloc(
|
||||
cellContext: context,
|
||||
),
|
||||
|
@ -10,7 +10,6 @@ import 'package:flowy_sdk/protobuf/flowy-grid/cell_entities.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-grid/selection_type_option.pb.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
import 'package:app_flowy/workspace/application/grid/cell/cell_listener.dart';
|
||||
|
||||
part 'cell_service.freezed.dart';
|
||||
@ -21,19 +20,22 @@ typedef GridSelectOptionCellContext = GridCellContext<SelectOptionContext>;
|
||||
class GridCellContext<T> {
|
||||
final GridCell gridCell;
|
||||
final GridCellCache cellCache;
|
||||
late GridCellCacheKey _cacheKey;
|
||||
final GridCellCacheKey _cacheKey;
|
||||
final GridCellDataLoader<T> cellDataLoader;
|
||||
|
||||
final CellListener _cellListener;
|
||||
final CellService _cellService = CellService();
|
||||
final ValueNotifier<dynamic> _cellDataNotifier = ValueNotifier(null);
|
||||
late final ValueNotifier<T?> _cellDataNotifier;
|
||||
Timer? _delayOperation;
|
||||
|
||||
GridCellContext({
|
||||
required this.gridCell,
|
||||
required this.cellCache,
|
||||
required this.cellDataLoader,
|
||||
}) : _cellListener = CellListener(rowId: gridCell.rowId, fieldId: gridCell.field.id) {
|
||||
}) : _cellListener = CellListener(rowId: gridCell.rowId, fieldId: gridCell.field.id),
|
||||
_cacheKey = GridCellCacheKey(objectId: gridCell.rowId, fieldId: gridCell.field.id) {
|
||||
_cellDataNotifier = ValueNotifier(cellCache.get(cacheKey));
|
||||
|
||||
_cellListener.updateCellNotifier?.addPublishListener((result) {
|
||||
result.fold(
|
||||
(notification) => _loadData(),
|
||||
@ -43,15 +45,8 @@ class GridCellContext<T> {
|
||||
|
||||
_cellListener.start();
|
||||
|
||||
_cacheKey = GridCellCacheKey(
|
||||
objectId: "$hashCode",
|
||||
fieldId: gridCell.field.id,
|
||||
);
|
||||
|
||||
if (cellDataLoader.reloadOnFieldChanged) {
|
||||
cellCache.addListener(cacheKey, () {
|
||||
reloadCellData();
|
||||
});
|
||||
cellCache.addListener(cacheKey, () => reloadCellData());
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,7 +77,9 @@ class GridCellContext<T> {
|
||||
}
|
||||
|
||||
void saveCellData(String data) {
|
||||
_cellService.updateCell(gridId: gridId, fieldId: field.id, rowId: rowId, data: data);
|
||||
_cellService.updateCell(gridId: gridId, fieldId: field.id, rowId: rowId, data: data).then((result) {
|
||||
result.fold((l) => null, (err) => Log.error(err));
|
||||
});
|
||||
}
|
||||
|
||||
void reloadCellData() {
|
||||
@ -265,42 +262,6 @@ class CellService {
|
||||
}
|
||||
}
|
||||
|
||||
// class CellCache {
|
||||
// final CellService _cellService;
|
||||
// final HashMap<String, Cell> _cellDataMap = HashMap();
|
||||
|
||||
// CellCache() : _cellService = CellService();
|
||||
|
||||
// Future<Option<Cell>> getCellData(GridCell identifier) async {
|
||||
// final cellId = _cellId(identifier);
|
||||
// final Cell? data = _cellDataMap[cellId];
|
||||
// if (data != null) {
|
||||
// return Future(() => Some(data));
|
||||
// }
|
||||
|
||||
// final result = await _cellService.getCell(
|
||||
// gridId: identifier.gridId,
|
||||
// fieldId: identifier.field.id,
|
||||
// rowId: identifier.rowId,
|
||||
// );
|
||||
|
||||
// return result.fold(
|
||||
// (cell) {
|
||||
// _cellDataMap[_cellId(identifier)] = cell;
|
||||
// return Some(cell);
|
||||
// },
|
||||
// (err) {
|
||||
// Log.error(err);
|
||||
// return none();
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
|
||||
// String _cellId(GridCell identifier) {
|
||||
// return "${identifier.rowId}/${identifier.field.id}";
|
||||
// }
|
||||
// }
|
||||
|
||||
@freezed
|
||||
class GridCell with _$GridCell {
|
||||
const factory GridCell({
|
||||
|
@ -7,7 +7,7 @@ import 'package:app_flowy/workspace/application/grid/cell/cell_service.dart';
|
||||
part 'selection_cell_bloc.freezed.dart';
|
||||
|
||||
class SelectionCellBloc extends Bloc<SelectionCellEvent, SelectionCellState> {
|
||||
final GridCellContext<SelectOptionContext> cellContext;
|
||||
final GridSelectOptionCellContext cellContext;
|
||||
|
||||
SelectionCellBloc({
|
||||
required this.cellContext,
|
||||
@ -63,7 +63,7 @@ class SelectionCellState with _$SelectionCellState {
|
||||
required List<SelectOption> selectedOptions,
|
||||
}) = _SelectionCellState;
|
||||
|
||||
factory SelectionCellState.initial(GridCellContext<SelectOptionContext> context) {
|
||||
factory SelectionCellState.initial(GridSelectOptionCellContext context) {
|
||||
final data = context.getCellData();
|
||||
|
||||
return SelectionCellState(
|
||||
|
@ -10,7 +10,7 @@ part 'selection_editor_bloc.freezed.dart';
|
||||
|
||||
class SelectOptionEditorBloc extends Bloc<SelectOptionEditorEvent, SelectOptionEditorState> {
|
||||
final SelectOptionService _selectOptionService;
|
||||
final GridCellContext<SelectOptionContext> cellContext;
|
||||
final GridSelectOptionCellContext cellContext;
|
||||
|
||||
SelectOptionEditorBloc({
|
||||
required this.cellContext,
|
||||
@ -111,7 +111,7 @@ class SelectOptionEditorState with _$SelectOptionEditorState {
|
||||
required List<SelectOption> selectedOptions,
|
||||
}) = _SelectOptionEditorState;
|
||||
|
||||
factory SelectOptionEditorState.initial(GridCellContext<SelectOptionContext> context) {
|
||||
factory SelectOptionEditorState.initial(GridSelectOptionCellContext context) {
|
||||
final data = context.getCellData();
|
||||
return SelectOptionEditorState(
|
||||
options: data?.options ?? [],
|
||||
|
@ -7,10 +7,10 @@ import 'cell_service.dart';
|
||||
part 'text_cell_bloc.freezed.dart';
|
||||
|
||||
class TextCellBloc extends Bloc<TextCellEvent, TextCellState> {
|
||||
final GridCellContext cellContext;
|
||||
final GridDefaultCellContext cellContext;
|
||||
TextCellBloc({
|
||||
required this.cellContext,
|
||||
}) : super(TextCellState.initial(cellContext.gridCell)) {
|
||||
}) : super(TextCellState.initial(cellContext)) {
|
||||
on<TextCellEvent>(
|
||||
(event, emit) async {
|
||||
await event.map(
|
||||
@ -22,14 +22,10 @@ class TextCellBloc extends Bloc<TextCellEvent, TextCellState> {
|
||||
emit(state.copyWith(content: value.text));
|
||||
},
|
||||
didReceiveCellData: (_DidReceiveCellData value) {
|
||||
emit(state.copyWith(
|
||||
cellData: value.cellData,
|
||||
content: value.cellData.cell?.content ?? "",
|
||||
));
|
||||
emit(state.copyWith(content: value.cellData.cell?.content ?? ""));
|
||||
},
|
||||
didReceiveCellUpdate: (_DidReceiveCellUpdate value) {
|
||||
emit(state.copyWith(
|
||||
cellData: state.cellData.copyWith(cell: value.cell),
|
||||
content: value.cell.content,
|
||||
));
|
||||
},
|
||||
@ -65,11 +61,9 @@ class TextCellEvent with _$TextCellEvent {
|
||||
class TextCellState with _$TextCellState {
|
||||
const factory TextCellState({
|
||||
required String content,
|
||||
required GridCell cellData,
|
||||
}) = _TextCellState;
|
||||
|
||||
factory TextCellState.initial(GridCell cellData) => TextCellState(
|
||||
content: cellData.cell?.content ?? "",
|
||||
cellData: cellData,
|
||||
factory TextCellState.initial(GridDefaultCellContext context) => TextCellState(
|
||||
content: context.getCellData()?.content ?? "",
|
||||
);
|
||||
}
|
||||
|
@ -21,13 +21,13 @@ GridCellWidget buildGridCellWidget(GridCell gridCell, GridCellCache cellCache, {
|
||||
case FieldType.DateTime:
|
||||
return DateCell(cellContext: cellContext, key: key);
|
||||
case FieldType.MultiSelect:
|
||||
return MultiSelectCell(cellContext: cellContext as GridCellContext<SelectOptionContext>, style: style, key: key);
|
||||
return MultiSelectCell(cellContext: cellContext as GridSelectOptionCellContext, style: style, key: key);
|
||||
case FieldType.Number:
|
||||
return NumberCell(cellContext: cellContext, key: key);
|
||||
case FieldType.RichText:
|
||||
return GridTextCell(cellContext: cellContext, style: style, key: key);
|
||||
case FieldType.SingleSelect:
|
||||
return SingleSelectCell(cellContext: cellContext as GridCellContext<SelectOptionContext>, style: style, key: key);
|
||||
return SingleSelectCell(cellContext: cellContext as GridSelectOptionCellContext, style: style, key: key);
|
||||
default:
|
||||
throw UnimplementedError;
|
||||
}
|
||||
@ -46,7 +46,7 @@ GridCellContext makeCellContext(GridCell gridCell, GridCellCache cellCache) {
|
||||
);
|
||||
case FieldType.MultiSelect:
|
||||
case FieldType.SingleSelect:
|
||||
return GridCellContext<SelectOptionContext>(
|
||||
return GridSelectOptionCellContext(
|
||||
gridCell: gridCell,
|
||||
cellCache: cellCache,
|
||||
cellDataLoader: SelectOptionCellDataLoader(gridCell: gridCell),
|
||||
|
@ -19,7 +19,7 @@ class SelectOptionCellStyle extends GridCellStyle {
|
||||
}
|
||||
|
||||
class SingleSelectCell extends GridCellWidget {
|
||||
final GridCellContext<SelectOptionContext> cellContext;
|
||||
final GridSelectOptionCellContext cellContext;
|
||||
late final SelectOptionCellStyle? cellStyle;
|
||||
|
||||
SingleSelectCell({
|
||||
@ -88,7 +88,7 @@ class _SingleSelectCellState extends State<SingleSelectCell> {
|
||||
|
||||
//----------------------------------------------------------------
|
||||
class MultiSelectCell extends GridCellWidget {
|
||||
final GridCellContext<SelectOptionContext> cellContext;
|
||||
final GridSelectOptionCellContext cellContext;
|
||||
late final SelectOptionCellStyle? cellStyle;
|
||||
|
||||
MultiSelectCell({
|
||||
|
@ -25,7 +25,7 @@ import 'text_field.dart';
|
||||
const double _editorPannelWidth = 300;
|
||||
|
||||
class SelectOptionCellEditor extends StatelessWidget with FlowyOverlayDelegate {
|
||||
final GridCellContext<SelectOptionContext> cellContext;
|
||||
final GridSelectOptionCellContext cellContext;
|
||||
final VoidCallback onDismissed;
|
||||
|
||||
const SelectOptionCellEditor({
|
||||
@ -60,7 +60,7 @@ class SelectOptionCellEditor extends StatelessWidget with FlowyOverlayDelegate {
|
||||
|
||||
static void show(
|
||||
BuildContext context,
|
||||
GridCellContext<SelectOptionContext> cellContext,
|
||||
GridSelectOptionCellContext cellContext,
|
||||
VoidCallback onDismissed,
|
||||
) {
|
||||
SelectOptionCellEditor.remove(context);
|
||||
|
Loading…
Reference in New Issue
Block a user