AppFlowy/frontend/rust-lib/flowy-grid/src/event_handler.rs

63 lines
2.2 KiB
Rust
Raw Normal View History

2022-03-04 14:09:16 +00:00
use crate::manager::GridManager;
2022-03-02 14:43:04 +00:00
use flowy_error::FlowyError;
2022-03-09 08:11:24 +00:00
use flowy_grid_data_model::entities::{
Cell, Grid, GridId, QueryFieldPayload, QueryRowPayload, RepeatedField, RepeatedRow,
};
2022-03-05 02:59:44 +00:00
use lib_dispatch::prelude::{data_result, AppData, Data, DataResult};
2022-03-02 14:43:04 +00:00
use std::sync::Arc;
2022-03-06 03:28:24 +00:00
#[tracing::instrument(level = "debug", skip(data, manager), err)]
2022-03-06 13:22:42 +00:00
pub(crate) async fn get_grid_data_handler(
2022-03-02 14:43:04 +00:00
data: Data<GridId>,
2022-03-05 02:59:44 +00:00
manager: AppData<Arc<GridManager>>,
2022-03-02 14:43:04 +00:00
) -> DataResult<Grid, FlowyError> {
2022-03-05 02:59:44 +00:00
let grid_id: GridId = data.into_inner();
let editor = manager.open_grid(grid_id).await?;
let grid = editor.grid_data().await;
data_result(grid)
2022-03-03 14:17:07 +00:00
}
2022-03-06 03:28:24 +00:00
#[tracing::instrument(level = "debug", skip(data, manager), err)]
2022-03-03 14:17:07 +00:00
pub(crate) async fn get_rows_handler(
2022-03-05 09:52:25 +00:00
data: Data<QueryRowPayload>,
2022-03-05 02:59:44 +00:00
manager: AppData<Arc<GridManager>>,
2022-03-04 00:22:49 +00:00
) -> DataResult<RepeatedRow, FlowyError> {
2022-03-05 09:52:25 +00:00
let payload: QueryRowPayload = data.into_inner();
let editor = manager.get_grid_editor(&payload.grid_id)?;
2022-03-14 09:24:25 +00:00
let repeated_row: RepeatedRow = editor.get_rows(Some(payload.row_orders)).await?.into();
2022-03-05 02:59:44 +00:00
data_result(repeated_row)
2022-03-03 14:17:07 +00:00
}
2022-03-06 03:28:24 +00:00
#[tracing::instrument(level = "debug", skip(data, manager), err)]
2022-03-03 14:17:07 +00:00
pub(crate) async fn get_fields_handler(
2022-03-05 09:52:25 +00:00
data: Data<QueryFieldPayload>,
2022-03-05 02:59:44 +00:00
manager: AppData<Arc<GridManager>>,
2022-03-04 00:22:49 +00:00
) -> DataResult<RepeatedField, FlowyError> {
2022-03-05 09:52:25 +00:00
let payload: QueryFieldPayload = data.into_inner();
let editor = manager.get_grid_editor(&payload.grid_id)?;
2022-03-13 03:06:28 +00:00
let repeated_field: RepeatedField = editor.get_fields(Some(payload.field_orders)).await?.into();
2022-03-05 02:59:44 +00:00
data_result(repeated_field)
2022-03-03 14:17:07 +00:00
}
2022-03-06 03:28:24 +00:00
#[tracing::instrument(level = "debug", skip(data, manager), err)]
2022-03-03 14:17:07 +00:00
pub(crate) async fn create_row_handler(
data: Data<GridId>,
2022-03-05 02:59:44 +00:00
manager: AppData<Arc<GridManager>>,
2022-03-04 00:22:49 +00:00
) -> Result<(), FlowyError> {
2022-03-03 14:17:07 +00:00
let id: GridId = data.into_inner();
2022-03-05 02:59:44 +00:00
let editor = manager.get_grid_editor(id.as_ref())?;
2022-03-12 01:30:13 +00:00
let _ = editor.create_row().await?;
2022-03-04 00:22:49 +00:00
Ok(())
2022-03-02 14:43:04 +00:00
}
2022-03-09 08:11:24 +00:00
2022-03-13 15:16:52 +00:00
#[tracing::instrument(level = "debug", skip_all, err)]
2022-03-09 08:11:24 +00:00
pub(crate) async fn update_cell_handler(
data: Data<Cell>,
2022-03-13 15:16:52 +00:00
_manager: AppData<Arc<GridManager>>,
2022-03-09 08:11:24 +00:00
) -> Result<(), FlowyError> {
2022-03-12 01:30:13 +00:00
let _cell: Cell = data.into_inner();
2022-03-10 04:01:31 +00:00
// let editor = manager.get_grid_editor(id.as_ref())?;
// let _ = editor.create_empty_row().await?;
2022-03-09 08:11:24 +00:00
Ok(())
}