chore: close grid handler

This commit is contained in:
appflowy 2022-04-10 16:29:45 +08:00
parent 5db5fd118e
commit 43095cb0dd
10 changed files with 38 additions and 23 deletions

View File

@ -65,7 +65,7 @@ class DocumentBloc extends Bloc<DocumentEvent, DocumentState> {
await _subscription?.cancel();
}
service.closeDocument(docId: view.id);
await service.closeDocument(docId: view.id);
return super.close();
}

View File

@ -13,16 +13,15 @@ import 'grid_service.dart';
part 'grid_bloc.freezed.dart';
class GridBloc extends Bloc<GridEvent, GridState> {
final View view;
final GridService _gridService;
final GridListener _gridListener;
final GridFieldsListener _fieldListener;
GridBloc({required this.view})
GridBloc({required View view})
: _fieldListener = GridFieldsListener(gridId: view.id),
_gridService = GridService(),
_gridService = GridService(gridId: view.id),
_gridListener = GridListener(gridId: view.id),
super(GridState.initial()) {
super(GridState.initial(view.id)) {
on<GridEvent>(
(event, emit) async {
await event.map(
@ -31,7 +30,7 @@ class GridBloc extends Bloc<GridEvent, GridState> {
_startListening();
},
createRow: (_CreateRow value) {
_gridService.createRow(gridId: view.id);
_gridService.createRow();
},
updateDesc: (_Desc value) {},
didReceiveRowUpdate: (_DidReceiveRowUpdate value) {
@ -47,6 +46,7 @@ class GridBloc extends Bloc<GridEvent, GridState> {
@override
Future<void> close() async {
await _gridService.closeGrid();
await _fieldListener.stop();
await _gridListener.stop();
return super.close();
@ -86,7 +86,7 @@ class GridBloc extends Bloc<GridEvent, GridState> {
}
Future<void> _loadGrid(Emitter<GridState> emit) async {
final result = await _gridService.loadGrid(gridId: view.id);
final result = await _gridService.loadGrid();
return Future(
() => result.fold(
(grid) async => await _loadFields(grid, emit),
@ -96,7 +96,7 @@ class GridBloc extends Bloc<GridEvent, GridState> {
}
Future<void> _loadFields(Grid grid, Emitter<GridState> emit) async {
final result = await _gridService.getFields(gridId: grid.id, fieldOrders: grid.fieldOrders);
final result = await _gridService.getFields(fieldOrders: grid.fieldOrders);
return Future(
() => result.fold(
(fields) {
@ -162,17 +162,19 @@ class GridEvent with _$GridEvent {
@freezed
class GridState with _$GridState {
const factory GridState({
required String gridId,
required GridLoadingState loadingState,
required List<Field> fields,
required List<RowOrder> rows,
required Option<Grid> grid,
}) = _GridState;
factory GridState.initial() => GridState(
factory GridState.initial(String gridId) => GridState(
loadingState: const _Loading(),
fields: [],
rows: [],
grid: none(),
gridId: gridId,
);
}

View File

@ -1,27 +1,37 @@
import 'package:dartz/dartz.dart';
import 'package:flowy_sdk/dispatch/dispatch.dart';
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart';
import 'package:dartz/dartz.dart';
class GridService {
Future<Either<Grid, FlowyError>> loadGrid({required String gridId}) async {
final String gridId;
GridService({
required this.gridId,
});
Future<Either<Grid, FlowyError>> loadGrid() async {
await FolderEventSetLatestView(ViewId(value: gridId)).send();
final payload = GridId(value: gridId);
return GridEventGetGridData(payload).send();
}
Future<Either<Row, FlowyError>> createRow({required String gridId, Option<String>? startRowId}) {
Future<Either<Row, FlowyError>> createRow({Option<String>? startRowId}) {
CreateRowPayload payload = CreateRowPayload.create()..gridId = gridId;
startRowId?.fold(() => null, (id) => payload.startRowId = id);
return GridEventCreateRow(payload).send();
}
Future<Either<RepeatedField, FlowyError>> getFields({required String gridId, required List<FieldOrder> fieldOrders}) {
Future<Either<RepeatedField, FlowyError>> getFields({required List<FieldOrder> fieldOrders}) {
final payload = QueryFieldPayload.create()
..gridId = gridId
..fieldOrders = RepeatedFieldOrder(items: fieldOrders);
return GridEventGetFields(payload).send();
}
Future<Either<Unit, FlowyError>> closeGrid() {
final request = ViewId(value: gridId);
return FolderEventCloseView(request).send();
}
}

View File

@ -83,8 +83,6 @@ class _FlowyGridState extends State<FlowyGrid> {
@override
Widget build(BuildContext context) {
final gridId = context.read<GridBloc>().view.id;
return BlocBuilder<GridBloc, GridState>(
buildWhen: (previous, current) => previous.fields != current.fields,
builder: (context, state) {
@ -103,9 +101,9 @@ class _FlowyGridState extends State<FlowyGrid> {
physics: StyledScrollPhysics(),
controller: _scrollController.verticalController,
slivers: [
_renderToolbar(gridId),
GridHeader(gridId: gridId, fields: List.from(state.fields)),
_renderRows(gridId: gridId, context: context),
_renderToolbar(state.gridId),
GridHeader(gridId: state.gridId, fields: List.from(state.fields)),
_renderRows(gridId: state.gridId, context: context),
const GridFooter(),
],
),

View File

@ -151,7 +151,7 @@ impl ViewController {
}
}
let processor = self.get_data_processor_from_view_id(&params.value).await?;
let _ = processor.close_container(&params.value).await?;
let _ = processor.delete_container(&params.value).await?;
Ok(())
}

View File

@ -73,7 +73,7 @@ impl GridManager {
self.get_or_create_grid_editor(grid_id).await
}
#[tracing::instrument(level = "trace", skip_all, fields(grid_id), err)]
#[tracing::instrument(level = "debug", skip_all, fields(grid_id), err)]
pub fn close_grid<T: AsRef<str>>(&self, grid_id: T) -> FlowyResult<()> {
let grid_id = grid_id.as_ref();
tracing::Span::current().record("grid_id", &grid_id);

View File

@ -67,7 +67,7 @@ fn crate_log_filter(level: String) -> String {
filters.push(format!("flowy_sdk={}", level));
filters.push(format!("flowy_folder={}", level));
filters.push(format!("flowy_user={}", level));
filters.push(format!("flowy_block={}", level));
filters.push(format!("flowy_text_block={}", level));
filters.push(format!("flowy_grid={}", level));
filters.push(format!("flowy_collaboration={}", "debug"));
filters.push(format!("dart_notify={}", level));

View File

@ -118,6 +118,7 @@ impl TextBlockManager {
}
}
#[tracing::instrument(level = "trace", skip(self, pool), err)]
async fn make_text_block_editor(
&self,
block_id: &str,

View File

@ -163,7 +163,11 @@ impl GridBlockMetaPad {
match cal_diff::<PlainTextAttributes>(old, new) {
None => Ok(None),
Some(delta) => {
tracing::debug!("[GridBlockMeta] Composing change {}", delta.to_delta_str());
tracing::debug!("[GridBlockMeta] Composing delta {}", delta.to_delta_str());
tracing::debug!(
"[GridBlockMeta] Composing str {}",
delta.to_str().unwrap_or("".to_string())
);
self.delta = self.delta.compose(&delta)?;
Ok(Some(GridBlockMetaChange { delta, md5: self.md5() }))
}

View File

@ -163,7 +163,6 @@ impl ServerDocumentManager {
}
}
#[tracing::instrument(level = "debug", skip(self, repeated_revision), err)]
async fn create_document(
&self,
doc_id: &str,
@ -182,6 +181,7 @@ impl ServerDocumentManager {
}
}
#[tracing::instrument(level = "debug", skip(self, doc), err)]
async fn create_document_handler(&self, doc: TextBlockInfo) -> Result<Arc<OpenDocumentHandler>, CollaborateError> {
let persistence = self.persistence.clone();
let handle = spawn_blocking(|| OpenDocumentHandler::new(doc, persistence))