chore: remove grid block from dart side

This commit is contained in:
appflowy 2022-04-10 07:10:15 +08:00
parent d08f298fb6
commit b92660058c
9 changed files with 51 additions and 54 deletions

View File

@ -79,7 +79,7 @@ class GridBloc extends Bloc<GridEvent, GridState> {
}
Future<void> _loadGrid(Emitter<GridState> emit) async {
final result = await service.openGrid(gridId: view.id);
final result = await service.loadGrid(gridId: view.id);
return Future(
() => result.fold(
(grid) async => await _loadFields(grid, emit),

View File

@ -5,7 +5,7 @@ import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart';
import 'package:dartz/dartz.dart';
class GridService {
Future<Either<Grid, FlowyError>> openGrid({required String gridId}) async {
Future<Either<loadGrid, FlowyError>> loadGrid({required String gridId}) async {
await FolderEventSetLatestView(ViewId(value: gridId)).send();
final payload = GridId(value: gridId);
@ -18,14 +18,6 @@ class GridService {
return GridEventCreateRow(payload).send();
}
Future<Either<RepeatedGridBlock, FlowyError>> getGridBlocks(
{required String gridId, required List<GridBlockOrder> blockOrders}) {
final payload = QueryGridBlocksPayload.create()
..gridId = gridId
..blockOrders.addAll(blockOrders);
return GridEventGetGridBlocks(payload).send();
}
Future<Either<RepeatedField, FlowyError>> getFields({required String gridId, required List<FieldOrder> fieldOrders}) {
final payload = QueryFieldPayload.create()
..gridId = gridId

View File

@ -155,24 +155,37 @@ class _FlowyGridState extends State<FlowyGrid> {
return rowChanged;
},
builder: (context, state) {
return SliverAnimatedList(
key: _key,
initialItemCount: context.read<GridBloc>().state.rows.length,
itemBuilder: (BuildContext context, int index, Animation<double> animation) {
return SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
final blockRow = context.read<GridBloc>().state.rows[index];
final fields = context.read<GridBloc>().state.fields;
final rowData = RowData.fromBlockRow(blockRow, fields);
return _renderRow(rowData, animation);
return GridRowWidget(data: rowData, key: ValueKey(rowData.rowId));
},
);
childCount: context.read<GridBloc>().state.rows.length,
addRepaintBoundaries: true,
addAutomaticKeepAlives: true,
));
// return SliverAnimatedList(
// key: _key,
// initialItemCount: context.read<GridBloc>().state.rows.length,
// itemBuilder: (BuildContext context, int index, Animation<double> animation) {
// final blockRow = context.read<GridBloc>().state.rows[index];
// final fields = context.read<GridBloc>().state.fields;
// final rowData = RowData.fromBlockRow(blockRow, fields);
// return _renderRow(rowData, animation);
// },
// );
},
);
}
Widget _renderRow(RowData rowData, Animation<double> animation) {
return SizeTransition(
sizeFactor: animation,
child: GridRowWidget(data: rowData, key: ValueKey(rowData.rowId)),
);
}
// Widget _renderRow(RowData rowData, Animation<double> animation) {
// return SizeTransition(
// sizeFactor: animation,
// child: GridRowWidget(data: rowData, key: ValueKey(rowData.rowId)),
// );
// }
}

View File

@ -179,7 +179,7 @@ pub async fn make_grid_view_data(
let grid_meta = GridMeta {
grid_id: view_id.to_string(),
fields: build_context.field_metas,
block_metas: vec![build_context.block_metas],
blocks: vec![build_context.block_metas],
};
// Create grid
@ -190,7 +190,7 @@ pub async fn make_grid_view_data(
let _ = grid_manager.create_grid(view_id, repeated_revision).await?;
// Indexing the block's rows
build_context.block_meta_data.row_metas.iter().for_each(|row| {
build_context.block_meta_data.rows.iter().for_each(|row| {
let _ = grid_manager
.block_index_persistence
.insert_or_update(&row.block_id, &row.id);

View File

@ -18,7 +18,7 @@ pub struct GridMeta {
pub fields: Vec<FieldMeta>,
#[pb(index = 3)]
pub block_metas: Vec<GridBlockMeta>,
pub blocks: Vec<GridBlockMeta>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, ProtoBuf)]
@ -74,7 +74,7 @@ pub struct GridBlockMetaData {
pub block_id: String,
#[pb(index = 2)]
pub row_metas: Vec<RowMeta>,
pub rows: Vec<RowMeta>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, ProtoBuf, Eq, PartialEq)]
@ -398,7 +398,7 @@ impl std::convert::From<CellMetaChangeset> for RowMetaChangeset {
row_id: changeset.row_id,
height: None,
visibility: None,
cell_by_field_id: cell_by_field_id,
cell_by_field_id,
}
}
}
@ -420,7 +420,7 @@ impl std::default::Default for BuildGridContext {
let grid_block = GridBlockMeta::new();
let grid_block_meta_data = GridBlockMetaData {
block_id: grid_block.block_id.clone(),
row_metas: vec![],
rows: vec![],
};
Self {

View File

@ -7,7 +7,7 @@ fn grid_serde_test() {
let grid = GridMeta {
grid_id,
fields,
block_metas: vec![],
blocks: vec![],
};
let grid_1_json = serde_json::to_string(&grid).unwrap();
@ -24,7 +24,7 @@ fn grid_default_serde_test() {
let grid = GridMeta {
grid_id,
fields: vec![],
block_metas: vec![],
blocks: vec![],
};
let json = serde_json::to_string(&grid).unwrap();

View File

@ -30,11 +30,7 @@ impl GridBlockMetaPad {
CollaborateError::internal().context(msg)
})?;
let block_id = meta_data.block_id;
let rows = meta_data
.row_metas
.into_iter()
.map(Arc::new)
.collect::<Vec<Arc<RowMeta>>>();
let rows = meta_data.rows.into_iter().map(Arc::new).collect::<Vec<Arc<RowMeta>>>();
Ok(Self {
block_id,
row_metas: rows,
@ -215,13 +211,13 @@ impl std::default::Default for GridBlockMetaPad {
fn default() -> Self {
let block_meta_data = GridBlockMetaData {
block_id: uuid(),
row_metas: vec![],
rows: vec![],
};
let delta = make_block_meta_delta(&block_meta_data);
GridBlockMetaPad {
block_id: block_meta_data.block_id,
row_metas: block_meta_data.row_metas.into_iter().map(Arc::new).collect::<Vec<_>>(),
row_metas: block_meta_data.rows.into_iter().map(Arc::new).collect::<Vec<_>>(),
delta,
}
}

View File

@ -14,7 +14,7 @@ impl GridBuilder {
pub fn add_empty_row(mut self) -> Self {
let row = RowMeta::new(&self.build_context.block_metas.block_id);
self.build_context.block_meta_data.row_metas.push(row);
self.build_context.block_meta_data.rows.push(row);
self.build_context.block_metas.row_count += 1;
self
}
@ -57,7 +57,7 @@ mod tests {
let grid_meta = GridMeta {
grid_id,
fields: build_context.field_metas,
block_metas: vec![build_context.block_metas],
blocks: vec![build_context.block_metas],
};
let grid_meta_delta = make_grid_delta(&grid_meta);

View File

@ -235,12 +235,12 @@ impl GridMetaPad {
pub fn create_block_meta(&mut self, block: GridBlockMeta) -> CollaborateResult<Option<GridChangeset>> {
self.modify_grid(|grid_meta| {
if grid_meta.block_metas.iter().any(|b| b.block_id == block.block_id) {
if grid_meta.blocks.iter().any(|b| b.block_id == block.block_id) {
tracing::warn!("Duplicate grid block");
Ok(None)
} else {
match grid_meta.block_metas.last() {
None => grid_meta.block_metas.push(block),
match grid_meta.blocks.last() {
None => grid_meta.blocks.push(block),
Some(last_block) => {
if last_block.start_row_index > block.start_row_index
&& last_block.len() > block.start_row_index
@ -248,7 +248,7 @@ impl GridMetaPad {
let msg = "GridBlock's start_row_index should be greater than the last_block's start_row_index and its len".to_string();
return Err(CollaborateError::internal().context(msg))
}
grid_meta.block_metas.push(block);
grid_meta.blocks.push(block);
}
}
Ok(Some(()))
@ -257,7 +257,7 @@ impl GridMetaPad {
}
pub fn get_block_metas(&self) -> Vec<GridBlockMeta> {
self.grid_meta.block_metas.clone()
self.grid_meta.blocks.clone()
}
pub fn update_block_meta(&mut self, changeset: GridBlockMetaChangeset) -> CollaborateResult<Option<GridChangeset>> {
@ -320,19 +320,15 @@ impl GridMetaPad {
where
F: FnOnce(&mut GridBlockMeta) -> CollaborateResult<Option<()>>,
{
self.modify_grid(|grid_meta| {
match grid_meta
.block_metas
.iter()
.position(|block| block.block_id == block_id)
{
self.modify_grid(
|grid_meta| match grid_meta.blocks.iter().position(|block| block.block_id == block_id) {
None => {
tracing::warn!("[GridMetaPad]: Can't find any block with id: {}", block_id);
Ok(None)
}
Some(index) => f(&mut grid_meta.block_metas[index]),
}
})
Some(index) => f(&mut grid_meta.blocks[index]),
},
)
}
pub fn modify_field<F>(&mut self, field_id: &str, f: F) -> CollaborateResult<Option<GridChangeset>>
@ -380,7 +376,7 @@ impl std::default::Default for GridMetaPad {
let grid = GridMeta {
grid_id: uuid(),
fields: vec![],
block_metas: vec![],
blocks: vec![],
};
let delta = make_grid_delta(&grid);
GridMetaPad {