Implement channel switching

This commit is contained in:
Antonio Scandurra 2021-09-02 10:16:20 +02:00
parent 836b6dfbaf
commit 1d697df1bc
2 changed files with 16 additions and 0 deletions

View file

@ -75,6 +75,10 @@ impl Select {
self.is_open = false; self.is_open = false;
cx.notify(); cx.notify();
} }
pub fn selected_index(&self) -> usize {
self.selected_item_ix
}
} }
impl Entity for Select { impl Entity for Select {

View file

@ -99,6 +99,18 @@ impl ChatPanel {
this.init_active_channel(cx); this.init_active_channel(cx);
}) })
.detach(); .detach();
cx.observe(&this.channel_select, |this, channel_select, cx| {
let selected_ix = channel_select.read(cx).selected_index();
let selected_channel = this.channel_list.update(cx, |channel_list, cx| {
let available_channels = channel_list.available_channels()?;
let channel_id = available_channels.get(selected_ix)?.id;
channel_list.get_channel(channel_id, cx)
});
if let Some(selected_channel) = selected_channel {
this.set_active_channel(selected_channel, cx);
}
})
.detach();
this this
} }