mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: remove grid block from dart side
This commit is contained in:
@ -79,7 +79,7 @@ class GridBloc extends Bloc<GridEvent, GridState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _loadGrid(Emitter<GridState> emit) async {
|
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(
|
return Future(
|
||||||
() => result.fold(
|
() => result.fold(
|
||||||
(grid) async => await _loadFields(grid, emit),
|
(grid) async => await _loadFields(grid, emit),
|
||||||
|
@ -5,7 +5,7 @@ import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart';
|
|||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
|
|
||||||
class GridService {
|
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();
|
await FolderEventSetLatestView(ViewId(value: gridId)).send();
|
||||||
|
|
||||||
final payload = GridId(value: gridId);
|
final payload = GridId(value: gridId);
|
||||||
@ -18,14 +18,6 @@ class GridService {
|
|||||||
return GridEventCreateRow(payload).send();
|
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}) {
|
Future<Either<RepeatedField, FlowyError>> getFields({required String gridId, required List<FieldOrder> fieldOrders}) {
|
||||||
final payload = QueryFieldPayload.create()
|
final payload = QueryFieldPayload.create()
|
||||||
..gridId = gridId
|
..gridId = gridId
|
||||||
|
@ -155,24 +155,37 @@ class _FlowyGridState extends State<FlowyGrid> {
|
|||||||
return rowChanged;
|
return rowChanged;
|
||||||
},
|
},
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return SliverAnimatedList(
|
return SliverList(
|
||||||
key: _key,
|
delegate: SliverChildBuilderDelegate(
|
||||||
initialItemCount: context.read<GridBloc>().state.rows.length,
|
(context, index) {
|
||||||
itemBuilder: (BuildContext context, int index, Animation<double> animation) {
|
|
||||||
final blockRow = context.read<GridBloc>().state.rows[index];
|
final blockRow = context.read<GridBloc>().state.rows[index];
|
||||||
final fields = context.read<GridBloc>().state.fields;
|
final fields = context.read<GridBloc>().state.fields;
|
||||||
final rowData = RowData.fromBlockRow(blockRow, 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) {
|
// Widget _renderRow(RowData rowData, Animation<double> animation) {
|
||||||
return SizeTransition(
|
// return SizeTransition(
|
||||||
sizeFactor: animation,
|
// sizeFactor: animation,
|
||||||
child: GridRowWidget(data: rowData, key: ValueKey(rowData.rowId)),
|
// child: GridRowWidget(data: rowData, key: ValueKey(rowData.rowId)),
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ pub async fn make_grid_view_data(
|
|||||||
let grid_meta = GridMeta {
|
let grid_meta = GridMeta {
|
||||||
grid_id: view_id.to_string(),
|
grid_id: view_id.to_string(),
|
||||||
fields: build_context.field_metas,
|
fields: build_context.field_metas,
|
||||||
block_metas: vec![build_context.block_metas],
|
blocks: vec![build_context.block_metas],
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create grid
|
// Create grid
|
||||||
@ -190,7 +190,7 @@ pub async fn make_grid_view_data(
|
|||||||
let _ = grid_manager.create_grid(view_id, repeated_revision).await?;
|
let _ = grid_manager.create_grid(view_id, repeated_revision).await?;
|
||||||
|
|
||||||
// Indexing the block's rows
|
// 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
|
let _ = grid_manager
|
||||||
.block_index_persistence
|
.block_index_persistence
|
||||||
.insert_or_update(&row.block_id, &row.id);
|
.insert_or_update(&row.block_id, &row.id);
|
||||||
|
@ -18,7 +18,7 @@ pub struct GridMeta {
|
|||||||
pub fields: Vec<FieldMeta>,
|
pub fields: Vec<FieldMeta>,
|
||||||
|
|
||||||
#[pb(index = 3)]
|
#[pb(index = 3)]
|
||||||
pub block_metas: Vec<GridBlockMeta>,
|
pub blocks: Vec<GridBlockMeta>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, ProtoBuf)]
|
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, ProtoBuf)]
|
||||||
@ -74,7 +74,7 @@ pub struct GridBlockMetaData {
|
|||||||
pub block_id: String,
|
pub block_id: String,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub row_metas: Vec<RowMeta>,
|
pub rows: Vec<RowMeta>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, ProtoBuf, Eq, PartialEq)]
|
#[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,
|
row_id: changeset.row_id,
|
||||||
height: None,
|
height: None,
|
||||||
visibility: 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 = GridBlockMeta::new();
|
||||||
let grid_block_meta_data = GridBlockMetaData {
|
let grid_block_meta_data = GridBlockMetaData {
|
||||||
block_id: grid_block.block_id.clone(),
|
block_id: grid_block.block_id.clone(),
|
||||||
row_metas: vec![],
|
rows: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
@ -7,7 +7,7 @@ fn grid_serde_test() {
|
|||||||
let grid = GridMeta {
|
let grid = GridMeta {
|
||||||
grid_id,
|
grid_id,
|
||||||
fields,
|
fields,
|
||||||
block_metas: vec![],
|
blocks: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
let grid_1_json = serde_json::to_string(&grid).unwrap();
|
let grid_1_json = serde_json::to_string(&grid).unwrap();
|
||||||
@ -24,7 +24,7 @@ fn grid_default_serde_test() {
|
|||||||
let grid = GridMeta {
|
let grid = GridMeta {
|
||||||
grid_id,
|
grid_id,
|
||||||
fields: vec![],
|
fields: vec![],
|
||||||
block_metas: vec![],
|
blocks: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
let json = serde_json::to_string(&grid).unwrap();
|
let json = serde_json::to_string(&grid).unwrap();
|
||||||
|
@ -30,11 +30,7 @@ impl GridBlockMetaPad {
|
|||||||
CollaborateError::internal().context(msg)
|
CollaborateError::internal().context(msg)
|
||||||
})?;
|
})?;
|
||||||
let block_id = meta_data.block_id;
|
let block_id = meta_data.block_id;
|
||||||
let rows = meta_data
|
let rows = meta_data.rows.into_iter().map(Arc::new).collect::<Vec<Arc<RowMeta>>>();
|
||||||
.row_metas
|
|
||||||
.into_iter()
|
|
||||||
.map(Arc::new)
|
|
||||||
.collect::<Vec<Arc<RowMeta>>>();
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
block_id,
|
block_id,
|
||||||
row_metas: rows,
|
row_metas: rows,
|
||||||
@ -215,13 +211,13 @@ impl std::default::Default for GridBlockMetaPad {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let block_meta_data = GridBlockMetaData {
|
let block_meta_data = GridBlockMetaData {
|
||||||
block_id: uuid(),
|
block_id: uuid(),
|
||||||
row_metas: vec![],
|
rows: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
let delta = make_block_meta_delta(&block_meta_data);
|
let delta = make_block_meta_delta(&block_meta_data);
|
||||||
GridBlockMetaPad {
|
GridBlockMetaPad {
|
||||||
block_id: block_meta_data.block_id,
|
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,
|
delta,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ impl GridBuilder {
|
|||||||
|
|
||||||
pub fn add_empty_row(mut self) -> Self {
|
pub fn add_empty_row(mut self) -> Self {
|
||||||
let row = RowMeta::new(&self.build_context.block_metas.block_id);
|
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.build_context.block_metas.row_count += 1;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ mod tests {
|
|||||||
let grid_meta = GridMeta {
|
let grid_meta = GridMeta {
|
||||||
grid_id,
|
grid_id,
|
||||||
fields: build_context.field_metas,
|
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);
|
let grid_meta_delta = make_grid_delta(&grid_meta);
|
||||||
|
@ -235,12 +235,12 @@ impl GridMetaPad {
|
|||||||
|
|
||||||
pub fn create_block_meta(&mut self, block: GridBlockMeta) -> CollaborateResult<Option<GridChangeset>> {
|
pub fn create_block_meta(&mut self, block: GridBlockMeta) -> CollaborateResult<Option<GridChangeset>> {
|
||||||
self.modify_grid(|grid_meta| {
|
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");
|
tracing::warn!("Duplicate grid block");
|
||||||
Ok(None)
|
Ok(None)
|
||||||
} else {
|
} else {
|
||||||
match grid_meta.block_metas.last() {
|
match grid_meta.blocks.last() {
|
||||||
None => grid_meta.block_metas.push(block),
|
None => grid_meta.blocks.push(block),
|
||||||
Some(last_block) => {
|
Some(last_block) => {
|
||||||
if last_block.start_row_index > block.start_row_index
|
if last_block.start_row_index > block.start_row_index
|
||||||
&& last_block.len() > 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();
|
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))
|
return Err(CollaborateError::internal().context(msg))
|
||||||
}
|
}
|
||||||
grid_meta.block_metas.push(block);
|
grid_meta.blocks.push(block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Some(()))
|
Ok(Some(()))
|
||||||
@ -257,7 +257,7 @@ impl GridMetaPad {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_block_metas(&self) -> Vec<GridBlockMeta> {
|
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>> {
|
pub fn update_block_meta(&mut self, changeset: GridBlockMetaChangeset) -> CollaborateResult<Option<GridChangeset>> {
|
||||||
@ -320,19 +320,15 @@ impl GridMetaPad {
|
|||||||
where
|
where
|
||||||
F: FnOnce(&mut GridBlockMeta) -> CollaborateResult<Option<()>>,
|
F: FnOnce(&mut GridBlockMeta) -> CollaborateResult<Option<()>>,
|
||||||
{
|
{
|
||||||
self.modify_grid(|grid_meta| {
|
self.modify_grid(
|
||||||
match grid_meta
|
|grid_meta| match grid_meta.blocks.iter().position(|block| block.block_id == block_id) {
|
||||||
.block_metas
|
|
||||||
.iter()
|
|
||||||
.position(|block| block.block_id == block_id)
|
|
||||||
{
|
|
||||||
None => {
|
None => {
|
||||||
tracing::warn!("[GridMetaPad]: Can't find any block with id: {}", block_id);
|
tracing::warn!("[GridMetaPad]: Can't find any block with id: {}", block_id);
|
||||||
Ok(None)
|
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>>
|
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 {
|
let grid = GridMeta {
|
||||||
grid_id: uuid(),
|
grid_id: uuid(),
|
||||||
fields: vec![],
|
fields: vec![],
|
||||||
block_metas: vec![],
|
blocks: vec![],
|
||||||
};
|
};
|
||||||
let delta = make_grid_delta(&grid);
|
let delta = make_grid_delta(&grid);
|
||||||
GridMetaPad {
|
GridMetaPad {
|
||||||
|
Reference in New Issue
Block a user