wip: refactor

This commit is contained in:
2025-01-08 17:30:06 +07:00
parent 2d254c3a28
commit 80506b72d9
6 changed files with 145 additions and 105 deletions

View File

@@ -191,7 +191,7 @@ impl ContactList {
}
}
pub fn _selected(&self) -> Vec<PublicKey> {
pub fn selected(&self) -> Vec<PublicKey> {
self.selected.clone().into_iter().collect()
}

View File

@@ -165,13 +165,14 @@ pub struct Inbox {
impl Inbox {
pub fn new(cx: &mut ViewContext<'_, Self>) -> Self {
let items = cx.new_model(|_| None);
let events = cx.global::<ChatRegistry>().rooms();
cx.observe_global::<ChatRegistry>(|this, cx| {
if cx.global::<ChatRegistry>().is_initialized {
this.load(cx)
}
})
.detach();
if let Some(events) = events.upgrade() {
cx.observe(&events, |this, model, cx| {
this.load(model, cx);
})
.detach();
}
Self {
items,
@@ -181,9 +182,8 @@ impl Inbox {
}
}
pub fn load(&mut self, cx: &mut ViewContext<Self>) {
// Get all room's events
let events: Vec<Event> = cx.global::<ChatRegistry>().rooms.read(cx).clone();
pub fn load(&mut self, model: Model<Vec<Event>>, cx: &mut ViewContext<Self>) {
let events = model.read(cx).clone();
cx.spawn(|view, mut async_cx| async move {
let client = get_client();

View File

@@ -36,7 +36,7 @@ impl Sidebar {
let inbox = cx.new_view(Inbox::new);
Self {
name: "Left Dock".into(),
name: "Sidebar".into(),
closeable: true,
zoomable: true,
focus_handle: cx.focus_handle(),
@@ -57,9 +57,9 @@ impl Sidebar {
.rounded(ButtonRounded::Large)
.w_full()
.on_click({
let _contact_list = contact_list.clone();
move |_, _cx| {
// TODO: open room
let contact_list = contact_list.clone();
move |_, cx| {
let _selected = contact_list.model.read(cx).selected();
}
}),
),