1use super::{
2 channel::{Channel, ChannelList},
3 Settings,
4};
5use gpui::{elements::*, Entity, ModelHandle, RenderContext, View, ViewContext};
6use postage::watch;
7
8pub struct ChatPanel {
9 channel_list: ModelHandle<ChannelList>,
10 active_channel: Option<ModelHandle<Channel>>,
11 // active_channel_subscription: Subscription,
12 messages: ListState,
13}
14
15pub enum Event {}
16
17impl ChatPanel {
18 pub fn new(
19 channel_list: ModelHandle<ChannelList>,
20 settings: watch::Receiver<Settings>,
21 cx: &mut ViewContext<Self>,
22 ) -> Self {
23 let mut this = Self {
24 channel_list,
25 messages: ListState::new(Vec::new()),
26 active_channel: None,
27 };
28 let channel = this.channel_list.update(cx, |list, cx| {
29 if let Some(channel_id) = list
30 .available_channels()
31 .and_then(|channels| channels.first())
32 .map(|details| details.id)
33 {
34 return list.get_channel(channel_id, cx);
35 }
36 None
37 });
38 if let Some(channel) = channel {
39 this.set_active_channel(channel);
40 }
41 this
42 }
43
44 pub fn set_active_channel(&mut self, channel: ModelHandle<Channel>) {
45 //
46 }
47}
48
49impl Entity for ChatPanel {
50 type Event = Event;
51}
52
53impl View for ChatPanel {
54 fn ui_name() -> &'static str {
55 "ChatPanel"
56 }
57
58 fn render(&self, cx: &RenderContext<Self>) -> gpui::ElementBox {
59 List::new(self.messages.clone()).boxed()
60 }
61}