mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: fix row rebuild refresh issue
This commit is contained in:
parent
b606c5ba7b
commit
ac766c0359
@ -113,7 +113,7 @@ class ApplicationBlocObserver extends BlocObserver {
|
||||
// ignore: unnecessary_overrides
|
||||
void onTransition(Bloc bloc, Transition transition) {
|
||||
// Log.debug("[current]: ${transition.currentState} \n\n[next]: ${transition.nextState}");
|
||||
Log.debug("${transition.nextState}");
|
||||
// Log.debug("${transition.nextState}");
|
||||
super.onTransition(bloc, transition);
|
||||
}
|
||||
|
||||
@ -123,9 +123,9 @@ class ApplicationBlocObserver extends BlocObserver {
|
||||
super.onError(bloc, error, stackTrace);
|
||||
}
|
||||
|
||||
@override
|
||||
void onEvent(Bloc bloc, Object? event) {
|
||||
// Log.debug("$event");
|
||||
super.onEvent(bloc, event);
|
||||
}
|
||||
// @override
|
||||
// void onEvent(Bloc bloc, Object? event) {
|
||||
// Log.debug("$event");
|
||||
// super.onEvent(bloc, event);
|
||||
// }
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class GridFieldsListener {
|
||||
|
||||
void _handler(GridNotification ty, Either<Uint8List, FlowyError> result) {
|
||||
switch (ty) {
|
||||
case GridNotification.DidUpdateGrid:
|
||||
case GridNotification.DidUpdateGridField:
|
||||
result.fold(
|
||||
(payload) => updateFieldsNotifier.value = left(GridFieldChangeset.fromBuffer(payload)),
|
||||
(error) => updateFieldsNotifier.value = right(error),
|
||||
|
@ -2,20 +2,18 @@ import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'dart:async';
|
||||
import 'field/field_service.dart';
|
||||
import 'grid_service.dart';
|
||||
|
||||
part 'grid_header_bloc.freezed.dart';
|
||||
|
||||
class GridHeaderBloc extends Bloc<GridHeaderEvent, GridHeaderState> {
|
||||
final FieldService _fieldService;
|
||||
// final FieldService _fieldService;
|
||||
final GridFieldCache fieldCache;
|
||||
|
||||
GridHeaderBloc({
|
||||
required String gridId,
|
||||
required this.fieldCache,
|
||||
}) : _fieldService = FieldService(gridId: gridId),
|
||||
super(GridHeaderState.initial(fieldCache.clonedFields)) {
|
||||
}) : super(GridHeaderState.initial(fieldCache.clonedFields)) {
|
||||
on<GridHeaderEvent>(
|
||||
(event, emit) async {
|
||||
await event.map(
|
||||
@ -31,7 +29,7 @@ class GridHeaderBloc extends Bloc<GridHeaderEvent, GridHeaderState> {
|
||||
}
|
||||
|
||||
Future<void> _startListening() async {
|
||||
fieldCache.listenOnFieldChanged((fields) {
|
||||
fieldCache.addListener(() {}, onChanged: (fields) {
|
||||
if (!isClosed) {
|
||||
add(GridHeaderEvent.didReceiveFieldUpdate(fields));
|
||||
}
|
||||
|
@ -74,6 +74,15 @@ class GridFieldCache {
|
||||
_fieldNotifier.addListener(() => onFieldChanged(clonedFields));
|
||||
}
|
||||
|
||||
void addListener(VoidCallback listener, {void Function(List<Field>)? onChanged}) {
|
||||
_fieldNotifier.addListener(() {
|
||||
if (onChanged != null) {
|
||||
onChanged(clonedFields);
|
||||
}
|
||||
listener();
|
||||
});
|
||||
}
|
||||
|
||||
void _removeFields(List<FieldOrder> deletedFields) {
|
||||
if (deletedFields.isEmpty) {
|
||||
return;
|
||||
@ -130,7 +139,7 @@ class GridRowCache {
|
||||
|
||||
GridRowCache({required this.gridId});
|
||||
|
||||
List<RowData> get rows => _rows;
|
||||
List<RowData> get rows => [..._rows];
|
||||
|
||||
void updateWithBlock(List<GridBlockOrder> blocks, UnmodifiableListView<Field> fields) {
|
||||
_fields = fields;
|
||||
|
@ -34,12 +34,12 @@ class RowBloc extends Bloc<RowEvent, RowState> {
|
||||
createRow: (_CreateRow value) {
|
||||
_rowService.createRow();
|
||||
},
|
||||
didReceiveFieldUpdate: (_DidReceiveFieldUpdate value) async {
|
||||
await _handleFieldUpdate(emit, value);
|
||||
},
|
||||
didUpdateRow: (_DidUpdateRow value) async {
|
||||
_handleRowUpdate(value, emit);
|
||||
},
|
||||
fieldsDidUpdate: (_FieldsDidUpdate value) async {
|
||||
await _handleFieldUpdate(emit);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
@ -53,15 +53,15 @@ class RowBloc extends Bloc<RowEvent, RowState> {
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> _handleFieldUpdate(Emitter<RowState> emit, _DidReceiveFieldUpdate value) async {
|
||||
Future<void> _handleFieldUpdate(Emitter<RowState> emit) async {
|
||||
final optionRow = await state.row;
|
||||
final CellDataMap cellDataMap = optionRow.fold(
|
||||
() => CellDataMap.identity(),
|
||||
(row) => _makeCellDatas(row, value.fields),
|
||||
(row) => _makeCellDatas(row, _fieldCache.unmodifiableFields),
|
||||
);
|
||||
|
||||
emit(state.copyWith(
|
||||
rowData: state.rowData.copyWith(fields: value.fields),
|
||||
rowData: state.rowData.copyWith(fields: _fieldCache.unmodifiableFields),
|
||||
cellDataMap: Some(cellDataMap),
|
||||
));
|
||||
}
|
||||
@ -80,9 +80,9 @@ class RowBloc extends Bloc<RowEvent, RowState> {
|
||||
);
|
||||
});
|
||||
|
||||
_fieldCache.listenOnFieldChanged((fields) {
|
||||
_fieldCache.addListener(() {
|
||||
if (!isClosed) {
|
||||
// add(RowEvent.didReceiveFieldUpdate(fields));
|
||||
add(const RowEvent.fieldsDidUpdate());
|
||||
}
|
||||
});
|
||||
|
||||
@ -118,7 +118,7 @@ class RowBloc extends Bloc<RowEvent, RowState> {
|
||||
class RowEvent with _$RowEvent {
|
||||
const factory RowEvent.initial() = _InitialRow;
|
||||
const factory RowEvent.createRow() = _CreateRow;
|
||||
const factory RowEvent.didReceiveFieldUpdate(List<Field> fields) = _DidReceiveFieldUpdate;
|
||||
const factory RowEvent.fieldsDidUpdate() = _FieldsDidUpdate;
|
||||
const factory RowEvent.didUpdateRow(Row row) = _DidUpdateRow;
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ class _GridPageState extends State<GridPage> {
|
||||
return state.loadingState.map(
|
||||
loading: (_) => const Center(child: CircularProgressIndicator.adaptive()),
|
||||
finish: (result) => result.successOrFail.fold(
|
||||
(_) => FlowyGrid(),
|
||||
(_) => const FlowyGrid(),
|
||||
(err) => FlowyErrorPage(err.toString()),
|
||||
),
|
||||
);
|
||||
@ -65,9 +65,15 @@ class _GridPageState extends State<GridPage> {
|
||||
}
|
||||
}
|
||||
|
||||
class FlowyGrid extends StatelessWidget {
|
||||
class FlowyGrid extends StatefulWidget {
|
||||
const FlowyGrid({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<FlowyGrid> createState() => _FlowyGridState();
|
||||
}
|
||||
|
||||
class _FlowyGridState extends State<FlowyGrid> {
|
||||
final _scrollController = GridScrollController();
|
||||
FlowyGrid({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -155,9 +161,15 @@ class _GridHeader extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _GridRows extends StatelessWidget {
|
||||
class _GridRows extends StatefulWidget {
|
||||
const _GridRows({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<_GridRows> createState() => _GridRowsState();
|
||||
}
|
||||
|
||||
class _GridRowsState extends State<_GridRows> {
|
||||
final _key = GlobalKey<SliverAnimatedListState>();
|
||||
_GridRows({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -15,7 +15,7 @@ class GridNotification extends $pb.ProtobufEnum {
|
||||
static const GridNotification DidUpdateGridBlock = GridNotification._(20, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DidUpdateGridBlock');
|
||||
static const GridNotification DidUpdateRow = GridNotification._(30, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DidUpdateRow');
|
||||
static const GridNotification DidUpdateCell = GridNotification._(31, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DidUpdateCell');
|
||||
static const GridNotification DidUpdateGrid = GridNotification._(40, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DidUpdateGrid');
|
||||
static const GridNotification DidUpdateGridField = GridNotification._(40, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DidUpdateGridField');
|
||||
static const GridNotification DidUpdateField = GridNotification._(41, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DidUpdateField');
|
||||
|
||||
static const $core.List<GridNotification> values = <GridNotification> [
|
||||
@ -24,7 +24,7 @@ class GridNotification extends $pb.ProtobufEnum {
|
||||
DidUpdateGridBlock,
|
||||
DidUpdateRow,
|
||||
DidUpdateCell,
|
||||
DidUpdateGrid,
|
||||
DidUpdateGridField,
|
||||
DidUpdateField,
|
||||
];
|
||||
|
||||
|
@ -17,10 +17,10 @@ const GridNotification$json = const {
|
||||
const {'1': 'DidUpdateGridBlock', '2': 20},
|
||||
const {'1': 'DidUpdateRow', '2': 30},
|
||||
const {'1': 'DidUpdateCell', '2': 31},
|
||||
const {'1': 'DidUpdateGrid', '2': 40},
|
||||
const {'1': 'DidUpdateGridField', '2': 40},
|
||||
const {'1': 'DidUpdateField', '2': 41},
|
||||
],
|
||||
};
|
||||
|
||||
/// Descriptor for `GridNotification`. Decode as a `google.protobuf.EnumDescriptorProto`.
|
||||
final $typed_data.Uint8List gridNotificationDescriptor = $convert.base64Decode('ChBHcmlkTm90aWZpY2F0aW9uEgsKB1Vua25vd24QABISCg5EaWRDcmVhdGVCbG9jaxALEhYKEkRpZFVwZGF0ZUdyaWRCbG9jaxAUEhAKDERpZFVwZGF0ZVJvdxAeEhEKDURpZFVwZGF0ZUNlbGwQHxIRCg1EaWRVcGRhdGVHcmlkECgSEgoORGlkVXBkYXRlRmllbGQQKQ==');
|
||||
final $typed_data.Uint8List gridNotificationDescriptor = $convert.base64Decode('ChBHcmlkTm90aWZpY2F0aW9uEgsKB1Vua25vd24QABISCg5EaWRDcmVhdGVCbG9jaxALEhYKEkRpZFVwZGF0ZUdyaWRCbG9jaxAUEhAKDERpZFVwZGF0ZVJvdxAeEhEKDURpZFVwZGF0ZUNlbGwQHxIWChJEaWRVcGRhdGVHcmlkRmllbGQQKBISCg5EaWRVcGRhdGVGaWVsZBAp');
|
||||
|
@ -9,7 +9,7 @@ pub enum GridNotification {
|
||||
DidUpdateGridBlock = 20,
|
||||
DidUpdateRow = 30,
|
||||
DidUpdateCell = 31,
|
||||
DidUpdateGrid = 40,
|
||||
DidUpdateGridField = 40,
|
||||
DidUpdateField = 41,
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ pub enum GridNotification {
|
||||
DidUpdateGridBlock = 20,
|
||||
DidUpdateRow = 30,
|
||||
DidUpdateCell = 31,
|
||||
DidUpdateGrid = 40,
|
||||
DidUpdateGridField = 40,
|
||||
DidUpdateField = 41,
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ impl ::protobuf::ProtobufEnum for GridNotification {
|
||||
20 => ::std::option::Option::Some(GridNotification::DidUpdateGridBlock),
|
||||
30 => ::std::option::Option::Some(GridNotification::DidUpdateRow),
|
||||
31 => ::std::option::Option::Some(GridNotification::DidUpdateCell),
|
||||
40 => ::std::option::Option::Some(GridNotification::DidUpdateGrid),
|
||||
40 => ::std::option::Option::Some(GridNotification::DidUpdateGridField),
|
||||
41 => ::std::option::Option::Some(GridNotification::DidUpdateField),
|
||||
_ => ::std::option::Option::None
|
||||
}
|
||||
@ -59,7 +59,7 @@ impl ::protobuf::ProtobufEnum for GridNotification {
|
||||
GridNotification::DidUpdateGridBlock,
|
||||
GridNotification::DidUpdateRow,
|
||||
GridNotification::DidUpdateCell,
|
||||
GridNotification::DidUpdateGrid,
|
||||
GridNotification::DidUpdateGridField,
|
||||
GridNotification::DidUpdateField,
|
||||
];
|
||||
values
|
||||
@ -89,11 +89,11 @@ impl ::protobuf::reflect::ProtobufValue for GridNotification {
|
||||
}
|
||||
|
||||
static file_descriptor_proto_data: &'static [u8] = b"\
|
||||
\n\x17dart_notification.proto*\x97\x01\n\x10GridNotification\x12\x0b\n\
|
||||
\n\x17dart_notification.proto*\x9c\x01\n\x10GridNotification\x12\x0b\n\
|
||||
\x07Unknown\x10\0\x12\x12\n\x0eDidCreateBlock\x10\x0b\x12\x16\n\x12DidUp\
|
||||
dateGridBlock\x10\x14\x12\x10\n\x0cDidUpdateRow\x10\x1e\x12\x11\n\rDidUp\
|
||||
dateCell\x10\x1f\x12\x11\n\rDidUpdateGrid\x10(\x12\x12\n\x0eDidUpdateFie\
|
||||
ld\x10)b\x06proto3\
|
||||
dateCell\x10\x1f\x12\x16\n\x12DidUpdateGridField\x10(\x12\x12\n\x0eDidUp\
|
||||
dateField\x10)b\x06proto3\
|
||||
";
|
||||
|
||||
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;
|
||||
|
@ -6,6 +6,6 @@ enum GridNotification {
|
||||
DidUpdateGridBlock = 20;
|
||||
DidUpdateRow = 30;
|
||||
DidUpdateCell = 31;
|
||||
DidUpdateGrid = 40;
|
||||
DidUpdateGridField = 40;
|
||||
DidUpdateField = 41;
|
||||
}
|
||||
|
@ -473,7 +473,7 @@ impl ClientGridEditor {
|
||||
}
|
||||
|
||||
async fn notify_did_update_grid(&self, changeset: GridFieldChangeset) -> FlowyResult<()> {
|
||||
send_dart_notification(&self.grid_id, GridNotification::DidUpdateGrid)
|
||||
send_dart_notification(&self.grid_id, GridNotification::DidUpdateGridField)
|
||||
.payload(changeset)
|
||||
.send();
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user