refactor group meta toggle into separate show/hide actions
This commit is contained in:
+31
-27
@@ -33,10 +33,18 @@ mod invite;
|
||||
mod message;
|
||||
mod metadata;
|
||||
|
||||
/// Ask the shell to show or hide the sidebar's information for a group.
|
||||
/// Ask the shell to show the sidebar's information for a group.
|
||||
#[derive(Action, Clone, PartialEq, Eq, Deserialize)]
|
||||
#[action(namespace = nip29_ui, no_json)]
|
||||
pub struct ToggleGroupMeta {
|
||||
pub struct ShowGroupMeta {
|
||||
pub relay: RelayUrl,
|
||||
pub group: String,
|
||||
}
|
||||
|
||||
/// Ask the shell to hide the sidebar's information for a group.
|
||||
#[derive(Action, Clone, PartialEq, Eq, Deserialize)]
|
||||
#[action(namespace = nip29_ui, no_json)]
|
||||
pub struct HideGroupMeta {
|
||||
pub relay: RelayUrl,
|
||||
pub group: String,
|
||||
}
|
||||
@@ -870,15 +878,6 @@ impl GroupPanel {
|
||||
supports_text && writable
|
||||
});
|
||||
|
||||
let meta = self.group.upgrade().map(|group| {
|
||||
let group = group.read(cx);
|
||||
|
||||
(
|
||||
group.key().relay().clone(),
|
||||
group.key().id().as_str().to_owned(),
|
||||
)
|
||||
});
|
||||
|
||||
v_flex()
|
||||
.flex_shrink_0()
|
||||
.w_full()
|
||||
@@ -889,22 +888,6 @@ impl GroupPanel {
|
||||
h_flex()
|
||||
.gap_1()
|
||||
.items_end()
|
||||
.child(
|
||||
Button::new("info")
|
||||
.icon(IconName::Group)
|
||||
.tooltip("Toggle group information in the sidebar")
|
||||
.ghost()
|
||||
.large()
|
||||
.on_click(move |_event, window, cx| {
|
||||
let Some((relay, group)) = meta.clone() else {
|
||||
return;
|
||||
};
|
||||
window.dispatch_action(
|
||||
Box::new(ToggleGroupMeta { relay, group }),
|
||||
cx,
|
||||
);
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
Button::new("upload")
|
||||
.icon(IconName::Upload)
|
||||
@@ -1000,6 +983,27 @@ impl Panel for GroupPanel {
|
||||
fn toolbar_buttons(&self, _window: &Window, _cx: &App) -> Vec<Button> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
fn set_active(&self, active: bool, window: &mut Window, cx: &mut App) {
|
||||
let Some(group) = self.group.upgrade() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let (relay, id) = {
|
||||
let group = group.read(cx);
|
||||
|
||||
(
|
||||
group.key().relay().clone(),
|
||||
group.key().id().as_str().to_owned(),
|
||||
)
|
||||
};
|
||||
|
||||
if active {
|
||||
window.dispatch_action(Box::new(ShowGroupMeta { relay, group: id }), cx);
|
||||
} else {
|
||||
window.dispatch_action(Box::new(HideGroupMeta { relay, group: id }), cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl EventEmitter<PanelEvent> for GroupPanel {}
|
||||
|
||||
Reference in New Issue
Block a user