refactor group meta toggle into separate show/hide actions
This commit is contained in:
@@ -204,15 +204,27 @@ impl Workspace {
|
||||
});
|
||||
});
|
||||
|
||||
// Listen app-wide, so a group panel can toggle the sidebar without holding it.
|
||||
// Listen app-wide, so a group panel can show or hide the sidebar without holding it.
|
||||
let workspace = cx.entity().downgrade();
|
||||
|
||||
App::on_action(cx, move |action: &nip29_ui::ToggleGroupMeta, cx| {
|
||||
App::on_action(cx, {
|
||||
let workspace = workspace.clone();
|
||||
|
||||
move |action: &nip29_ui::ShowGroupMeta, cx| {
|
||||
let Some(workspace) = workspace.upgrade() else {
|
||||
return;
|
||||
};
|
||||
|
||||
workspace.update(cx, |this, cx| this.show_group_meta(action, cx));
|
||||
}
|
||||
});
|
||||
|
||||
App::on_action(cx, move |action: &nip29_ui::HideGroupMeta, cx| {
|
||||
let Some(workspace) = workspace.upgrade() else {
|
||||
return;
|
||||
};
|
||||
|
||||
workspace.update(cx, |this, cx| this.toggle_group_meta(action, cx));
|
||||
workspace.update(cx, |this, cx| this.hide_group_meta(action, cx));
|
||||
});
|
||||
|
||||
Self {
|
||||
@@ -397,8 +409,8 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
/// Show or hide the sidebar's information for the group a panel belongs to.
|
||||
fn toggle_group_meta(&mut self, action: &nip29_ui::ToggleGroupMeta, cx: &mut Context<Self>) {
|
||||
/// Show the sidebar's information for the group a panel belongs to.
|
||||
fn show_group_meta(&mut self, action: &nip29_ui::ShowGroupMeta, cx: &mut Context<Self>) {
|
||||
let Ok(id) = GroupId::new(action.group.clone()) else {
|
||||
return;
|
||||
};
|
||||
@@ -406,7 +418,20 @@ impl Workspace {
|
||||
let key = GroupKey::new(action.relay.clone(), id);
|
||||
|
||||
self.sidebar.update(cx, |sidebar, cx| {
|
||||
sidebar.toggle_group(&key, cx);
|
||||
sidebar.show_group_meta(&key, cx);
|
||||
});
|
||||
}
|
||||
|
||||
/// Hide the sidebar's information for the group a panel belongs to.
|
||||
fn hide_group_meta(&mut self, action: &nip29_ui::HideGroupMeta, cx: &mut Context<Self>) {
|
||||
let Ok(id) = GroupId::new(action.group.clone()) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let key = GroupKey::new(action.relay.clone(), id);
|
||||
|
||||
self.sidebar.update(cx, |sidebar, cx| {
|
||||
sidebar.hide_group_meta(&key, cx);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -190,28 +190,28 @@ impl Sidebar {
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Show or hide the group view depending on which group is being viewed.
|
||||
pub(crate) fn toggle_group(&mut self, key: &GroupKey, cx: &mut Context<Self>) {
|
||||
/// Show the group view without toggling it closed.
|
||||
pub(crate) fn show_group_meta(&mut self, key: &GroupKey, cx: &mut Context<Self>) {
|
||||
let groups = GroupsRegistry::global(cx);
|
||||
|
||||
let Some(entity) = groups.read(cx).group(key, cx) else {
|
||||
let Some(group) = groups.read(cx).group(key, cx) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let open = self
|
||||
self.show_group(&group, cx);
|
||||
}
|
||||
|
||||
/// Hide the group view if the sidebar is showing the given group.
|
||||
pub(crate) fn hide_group_meta(&mut self, key: &GroupKey, cx: &mut Context<Self>) {
|
||||
let showing = self
|
||||
.group
|
||||
.as_ref()
|
||||
.and_then(|group| group.upgrade())
|
||||
.is_some_and(|current| current.entity_id() == entity.entity_id());
|
||||
.is_some_and(|group| group.read(cx).key() == key);
|
||||
|
||||
if open {
|
||||
self.group_open = !self.group_open;
|
||||
} else {
|
||||
self.group = Some(entity.downgrade());
|
||||
self.group_open = true;
|
||||
if showing {
|
||||
self.hide_group(cx);
|
||||
}
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Leave the group view, returning the sidebar to its tab list.
|
||||
|
||||
Reference in New Issue
Block a user