mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: close grid handler
This commit is contained in:
parent
5db5fd118e
commit
43095cb0dd
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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(),
|
||||
],
|
||||
),
|
||||
|
@ -151,7 +151,7 @@ impl ViewController {
|
||||
}
|
||||
}
|
||||
let processor = self.get_data_processor_from_view_id(¶ms.value).await?;
|
||||
let _ = processor.close_container(¶ms.value).await?;
|
||||
let _ = processor.delete_container(¶ms.value).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
|
@ -118,6 +118,7 @@ impl TextBlockManager {
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(self, pool), err)]
|
||||
async fn make_text_block_editor(
|
||||
&self,
|
||||
block_id: &str,
|
||||
|
@ -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() }))
|
||||
}
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user