feat: support moving group

This commit is contained in:
appflowy
2022-09-30 20:44:41 +08:00
parent 6c3978c3ba
commit 5763e289ef
14 changed files with 171 additions and 117 deletions

View File

@ -98,6 +98,7 @@ pub struct MoveGroupPayloadPB {
pub to_group_id: String,
}
#[derive(debug, Debug)]
pub struct MoveGroupParams {
pub view_id: String,
pub from_group_id: String,

View File

@ -173,6 +173,7 @@ impl GridViewRevisionEditor {
Ok(groups.into_iter().map(GroupPB::from).collect())
}
#[tracing::instrument(level = "trace", err)]
pub(crate) async fn move_group(&self, params: MoveGroupParams) -> FlowyResult<()> {
let _ = self
.group_controller
@ -180,7 +181,7 @@ impl GridViewRevisionEditor {
.await
.move_group(&params.from_group_id, &params.to_group_id)?;
match self.group_controller.read().await.get_group(&params.from_group_id) {
None => {}
None => tracing::warn!("Can not find the group with id: {}", params.from_group_id),
Some((index, group)) => {
let inserted_group = InsertedGroupPB {
group: GroupPB::from(group),

View File

@ -135,6 +135,7 @@ where
self.mut_configuration(|configuration| {
let from_index = configuration.groups.iter().position(|group| group.id == from_id);
let to_index = configuration.groups.iter().position(|group| group.id == to_id);
tracing::trace!("Swap group index:{:?} with index:{:?}", from_index, to_index);
if let (Some(from), Some(to)) = (from_index, to_index) {
configuration.groups.swap(from, to);
}