From 271e865d40899c1c9f3787af8e8e9398e9bad734 Mon Sep 17 00:00:00 2001 From: Adrien Date: Sun, 9 Jun 2024 12:31:18 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20Open/close=20ChatPanel=20on=20cl?= =?UTF-8?q?ick=20(Conversations=20layout/big=20breakpoint)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/layouts/conversations.rs | 71 ++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/src/ui/layouts/conversations.rs b/src/ui/layouts/conversations.rs index 0c6fbf3..8bb742e 100644 --- a/src/ui/layouts/conversations.rs +++ b/src/ui/layouts/conversations.rs @@ -2,7 +2,7 @@ use std::rc::Rc; use dioxus::prelude::*; use futures::join; -use tracing::{error, warn}; +use tracing::warn; use crate::ui::{ components::{ @@ -151,37 +151,52 @@ fn LayoutBig() -> Element { let mut first_div = use_signal(|| None::>); let mut last_div = use_signal(|| None::>); - let conversation_panels_nb = 3; - let conversation_panels = (0..conversation_panels_nb + 1).map(|i| { - if i == 0 { - rsx! { - div { - class: ClassName::CONVERSATIONS_VIEW_BIG_CONVERSATION_PANELS_PANEL, - onmounted: move |cx| async move { - let data = cx.data(); - let _ = data.as_ref().scroll_to(ScrollBehavior::Smooth).await; - first_div.set(Some(data)); - }, - ChatPanel { name: format!("CHAT #{i}") }, + let displayed_room_ids = STORE.read().displayed_room_ids(); + + let mut conversation_panels = Vec::new(); + let mut displayed_room_ids_it = displayed_room_ids.iter().peekable(); + let mut is_first = true; + while let Some(room_id) = displayed_room_ids_it.next() { + if let Some(room) = STORE.read().rooms().get(room_id) { + let room = room.signal(); + let room_name_repr = format!("CHAT {}", room.name().unwrap_or(room.id().to_string())); + let panel = if is_first { + is_first = false; + rsx! { + div { + class: ClassName::CONVERSATIONS_VIEW_BIG_CONVERSATION_PANELS_PANEL, + onmounted: move |cx| async move { + let data = cx.data(); + let _ = data.as_ref().scroll_to(ScrollBehavior::Smooth).await; + first_div.set(Some(data)); + }, + ChatPanel { name: room_name_repr }, + } } - } - } else if i == conversation_panels_nb { - rsx! { - div { - class: ClassName::CONVERSATIONS_VIEW_BIG_CONVERSATION_PANELS_PANEL, - onmounted: move |cx: Event| last_div.set(Some(cx.data())), - ChatPanel { name: format!("CHAT #{i}") }, + } else if displayed_room_ids_it.peek().is_none() { + rsx! { + div { + class: ClassName::CONVERSATIONS_VIEW_BIG_CONVERSATION_PANELS_PANEL, + onmounted: move |cx: Event| last_div.set(Some(cx.data())), + ChatPanel { name: room_name_repr }, + } } + } else { + rsx! { + div { + class: ClassName::CONVERSATIONS_VIEW_BIG_CONVERSATION_PANELS_PANEL, + ChatPanel { name: room_name_repr }, + } + } + }; + + if let Some(panel) = panel { + conversation_panels.push(panel); } } else { - rsx! { - div { - class: ClassName::CONVERSATIONS_VIEW_BIG_CONVERSATION_PANELS_PANEL, - ChatPanel { name: format!("CHAT #{i}") }, - } - } + warn!("No {} room found", room_id); } - }); + } rsx! { style { {STYLE_SHEET} }, @@ -219,7 +234,7 @@ fn LayoutBig() -> Element { class: ClassName::CONVERSATIONS_VIEW_HEAD, } - {conversation_panels} + {conversation_panels.iter()} div { class: ClassName::CONVERSATIONS_VIEW_TAIL,