diff --git a/src/base.rs b/src/base.rs index b0f0c1c..e43a935 100644 --- a/src/base.rs +++ b/src/base.rs @@ -160,7 +160,7 @@ pub async fn sync_rooms( receivers: Receivers, rooms_ref: UseAtomRef, ) { - while let Some(_is_logged) = rx.next().await { + if let Some(_is_logged) = rx.next().await { let mut rooms_receiver = receivers.rooms_receiver.borrow_mut(); let mut room_topic_receiver = receivers.room_topic_receiver.borrow_mut(); diff --git a/src/components/chats_window/chats_window.rs b/src/components/chats_window/chats_window.rs deleted file mode 100644 index e9e8ff2..0000000 --- a/src/components/chats_window/chats_window.rs +++ /dev/null @@ -1,202 +0,0 @@ -use dioxus::prelude::*; -use fermi::*; -use tracing::debug; - -use crate::base::{sync_rooms, ROOMS}; -use crate::components::avatar_selector::AvatarSelector; -use crate::components::icons::DownArrowIcon; -use crate::matrix_interface::requester::Receivers; - -use super::edit_section::EditSection; - -turf::style_sheet!("src/components/chats_window/chats_window.scss"); - -pub struct ChatsWindowProps { - pub receivers: Receivers, -} - -pub fn ChatsWindow(cx: Scope) -> Element { - debug!("ChatsWindow rendering"); - - let receivers = &cx.props.receivers; - - use_init_atom_root(cx); - - let rooms_ref = use_atom_ref(cx, &ROOMS); - - let sync_rooms_coro = use_coroutine(cx, |rx| { - to_owned![receivers]; - - sync_rooms(rx, receivers, rooms_ref.clone()) - }); - sync_rooms_coro.send(true); - - let rooms = rooms_ref.read(); - let rendered_room_tabs = rooms.values().map(|room| { - let room = room.borrow(); - let room_name = room.name().unwrap_or(room.id().to_string()); - rsx!( - div { - class: ClassName::TAB, - - button { - img { - src: "./images/status_online.png", - }, - - "{room_name}", - }, - }, - ) - }); - - cx.render(rsx! { - style { STYLE_SHEET }, - - div { - class: ClassName::CHATS_WINDOW, - - div { - class: ClassName::TABS, - - rendered_room_tabs.into_iter(), - }, - - div { - class: ClassName::CHAT, - - div { - class: ClassName::HEADER, - - div { - class: ClassName::INFO, - - p { - class: ClassName::ROOM_NAME, - - "MON POTE", - }, - - p { - class: ClassName::ROOM_TOPIC, - - "LE STATUT A MON POTE", - }, - }, - - div { - class: ClassName::NAVBAR, - - button { - style: "background: url(./images/add_user2.png) center no-repeat", - }, - - button { - style: "background: url(./images/directory.png) center no-repeat", - }, - - button { - style: "background: url(./images/phone.png) center no-repeat", - }, - - button { - style: "background: url(./images/medias.png) center no-repeat", - }, - - button { - style: "background: url(./images/games.png) center no-repeat", - }, - - button { - style: "background: url(./images/ban_user.png) center no-repeat", - }, - - button { - class: ClassName::FLEX_RIGHT_AERO_BUTTON, - style: "background: url(./images/brush.png) center no-repeat", - }, - - button { - class: ClassName::FLEX_LAST_BUTTON, - style: "background: url(./images/settings.png) center no-repeat", - }, - }, - }, - - div { - class: ClassName::CONVERSATION, - - div { - class: ClassName::ROOM_EVENTS, - - ul { - li { - class: ClassName::ROOM_EVENT, - div { - p { - class: ClassName::TITLE, - "MON POTE says:" - }, - p { - class: ClassName::CONTENT, - "Coucou mon pote", - }, - }, - }, - }, - }, - - div { - class: ClassName::OTHER_AVATAR_SELECTOR_CONTAINER, - - div { - - class: ClassName::AVATAR_SELECTOR, - AvatarSelector {}, - }, - div { - class: ClassName::WEBCAM, - img { - src: "images/webcam.svg" - }, - }, - - div { - class: ClassName::ARROW_ICON, - DownArrowIcon {} - }, - }, - - div { - class: ClassName::HOLDER, - "••••••" - }, - - div { - class: ClassName::EDIT_SECTION, - EditSection {}, - }, - - div { - class: ClassName::MY_AVATAR_SELECTOR_CONTAINER, - - div { - class: ClassName::AVATAR_SELECTOR, - AvatarSelector {}, - }, - div { - class: ClassName::WEBCAM, - img { - src: "images/webcam.svg" - }, - }, - div { - class: ClassName::ARROW_ICON, - DownArrowIcon {} - }, - }, - }, - }, - }, - }) -} diff --git a/src/components/chats_window/mod.rs b/src/components/chats_window/mod.rs index 8e7c844..2ee6afd 100644 --- a/src/components/chats_window/mod.rs +++ b/src/components/chats_window/mod.rs @@ -1,3 +1,203 @@ -pub mod chats_window; - mod edit_section; + +use dioxus::prelude::*; +use fermi::*; +use tracing::debug; + +use crate::base::{sync_rooms, ROOMS}; +use crate::components::avatar_selector::AvatarSelector; +use crate::components::icons::DownArrowIcon; +use crate::matrix_interface::requester::Receivers; +use edit_section::EditSection; + +turf::style_sheet!("src/components/chats_window/chats_window.scss"); + +pub struct ChatsWindowProps { + pub receivers: Receivers, +} + +pub fn ChatsWindow(cx: Scope) -> Element { + debug!("ChatsWindow rendering"); + + let receivers = &cx.props.receivers; + + use_init_atom_root(cx); + + let rooms_ref = use_atom_ref(cx, &ROOMS); + + let sync_rooms_coro = use_coroutine(cx, |rx| { + to_owned![receivers]; + + sync_rooms(rx, receivers, rooms_ref.clone()) + }); + sync_rooms_coro.send(true); + + let rooms = rooms_ref.read(); + let rendered_room_tabs = rooms.values().map(|room| { + let room = room.borrow(); + let room_name = room.name().unwrap_or(room.id().to_string()); + rsx!( + div { + class: ClassName::TAB, + + button { + img { + src: "./images/status_online.png", + }, + + "{room_name}", + }, + }, + ) + }); + + cx.render(rsx! { + style { STYLE_SHEET }, + + div { + class: ClassName::CHATS_WINDOW, + + div { + class: ClassName::TABS, + + rendered_room_tabs.into_iter(), + }, + + div { + class: ClassName::CHAT, + + div { + class: ClassName::HEADER, + + div { + class: ClassName::INFO, + + p { + class: ClassName::ROOM_NAME, + + "MON POTE", + }, + + p { + class: ClassName::ROOM_TOPIC, + + "LE STATUT A MON POTE", + }, + }, + + div { + class: ClassName::NAVBAR, + + button { + style: "background: url(./images/add_user2.png) center no-repeat", + }, + + button { + style: "background: url(./images/directory.png) center no-repeat", + }, + + button { + style: "background: url(./images/phone.png) center no-repeat", + }, + + button { + style: "background: url(./images/medias.png) center no-repeat", + }, + + button { + style: "background: url(./images/games.png) center no-repeat", + }, + + button { + style: "background: url(./images/ban_user.png) center no-repeat", + }, + + button { + class: ClassName::FLEX_RIGHT_AERO_BUTTON, + style: "background: url(./images/brush.png) center no-repeat", + }, + + button { + class: ClassName::FLEX_LAST_BUTTON, + style: "background: url(./images/settings.png) center no-repeat", + }, + }, + }, + + div { + class: ClassName::CONVERSATION, + + div { + class: ClassName::ROOM_EVENTS, + + ul { + li { + class: ClassName::ROOM_EVENT, + div { + p { + class: ClassName::TITLE, + "MON POTE says:" + }, + p { + class: ClassName::CONTENT, + "Coucou mon pote", + }, + }, + }, + }, + }, + + div { + class: ClassName::OTHER_AVATAR_SELECTOR_CONTAINER, + + div { + + class: ClassName::AVATAR_SELECTOR, + AvatarSelector {}, + }, + div { + class: ClassName::WEBCAM, + img { + src: "images/webcam.svg" + }, + }, + + div { + class: ClassName::ARROW_ICON, + DownArrowIcon {} + }, + }, + + div { + class: ClassName::HOLDER, + "••••••" + }, + + div { + class: ClassName::EDIT_SECTION, + EditSection {}, + }, + + div { + class: ClassName::MY_AVATAR_SELECTOR_CONTAINER, + + div { + class: ClassName::AVATAR_SELECTOR, + AvatarSelector {}, + }, + div { + class: ClassName::WEBCAM, + img { + src: "images/webcam.svg" + }, + }, + div { + class: ClassName::ARROW_ICON, + DownArrowIcon {} + }, + }, + }, + }, + }, + }) +} diff --git a/src/components/contacts_window/contacts_section.rs b/src/components/contacts_window/contacts_section.rs index d821437..2c4aaa3 100644 --- a/src/components/contacts_window/contacts_section.rs +++ b/src/components/contacts_window/contacts_section.rs @@ -64,7 +64,7 @@ pub fn ContactsSection<'a>( let show = use_state(cx, || false); - let classes = vec![ + let classes = [ ClassName::SECTION, if **show { ClassName::ACTIVE } else { "" }, ] @@ -86,7 +86,7 @@ pub fn ContactsSection<'a>( let formatted = format!( "{room_name} - {}", if is_invited { - format!("Invited - ") + "Invited - ".to_string() } else { "".to_string() } diff --git a/src/components/contacts_window/contacts_window.rs b/src/components/contacts_window/contacts_window.rs deleted file mode 100644 index d16ab12..0000000 --- a/src/components/contacts_window/contacts_window.rs +++ /dev/null @@ -1,94 +0,0 @@ -use dioxus::prelude::*; -use tracing::debug; - -use crate::components::contacts_window::contacts::Contacts; -use crate::components::contacts_window::user_infos::UserInfos; - -turf::style_sheet!("src/components/contacts_window/contacts_window.scss"); - -pub fn ContactsWindow(cx: Scope) -> Element { - debug!("ContactsWindow rendering"); - - cx.render(rsx! { - style { STYLE_SHEET }, - - div { - class: ClassName::CONTACTS_WINDOW, - - div { - class: ClassName::HEADER, - - div { - class: ClassName::TITLE_BAR, - }, - - div { - class: ClassName::USER_INFO, - }, - - UserInfos {}, - }, - - div { - class: ClassName::CONTACTS_NAV, - div { - class: ClassName::INNER, - - button { - class: ClassName::AERO_BUTTON, - style: "background: url(./images/letter.png) center no-repeat", - }, - button { - class: ClassName::AERO_BUTTON, - style: "background: url(./images/directory.png) no-repeat center", - }, - button { - class: ClassName::AERO_BUTTON, - style: "background: url(./images/news.png) no-repeat center", - }, - - button { - class: ClassName::FLEX_RIGHT_AERO_BUTTON, - style: "background: url(./images/brush.png) no-repeat center", - }, - button { - class: ClassName::AERO_BUTTON, - style: "background: url(./images/settings.png) no-repeat center", - }, - - }, - - }, - - div { - class: ClassName::SEARCH, - - div { - class: ClassName::INNER, - - input { - class: ClassName::SEARCH_INPUT, - placeholder: "Find a contact...", - r#type: "text", - }, - - button { - class: ClassName::BUTTON, - style: "background: url(./images/add_user.png) no-repeat center", - }, - - button { - class: ClassName::BUTTON, - style: "background: url(./images/tbc_transfert.png) no-repeat center", - }, - }, - }, - - Contacts {}, - - div { - class: ClassName::FOOTER, - }, - }, - }) -} diff --git a/src/components/contacts_window/mod.rs b/src/components/contacts_window/mod.rs index 6a86f27..d32e0c8 100644 --- a/src/components/contacts_window/mod.rs +++ b/src/components/contacts_window/mod.rs @@ -1,5 +1,98 @@ -pub mod contacts_window; - mod contacts; mod contacts_section; mod user_infos; + +use dioxus::prelude::*; +use tracing::debug; + +use crate::components::contacts_window::contacts::Contacts; +use crate::components::contacts_window::user_infos::UserInfos; + +turf::style_sheet!("src/components/contacts_window/contacts_window.scss"); + +pub fn ContactsWindow(cx: Scope) -> Element { + debug!("ContactsWindow rendering"); + + cx.render(rsx! { + style { STYLE_SHEET }, + + div { + class: ClassName::CONTACTS_WINDOW, + + div { + class: ClassName::HEADER, + + div { + class: ClassName::TITLE_BAR, + }, + + div { + class: ClassName::USER_INFO, + }, + + UserInfos {}, + }, + + div { + class: ClassName::CONTACTS_NAV, + div { + class: ClassName::INNER, + + button { + class: ClassName::AERO_BUTTON, + style: "background: url(./images/letter.png) center no-repeat", + }, + button { + class: ClassName::AERO_BUTTON, + style: "background: url(./images/directory.png) no-repeat center", + }, + button { + class: ClassName::AERO_BUTTON, + style: "background: url(./images/news.png) no-repeat center", + }, + + button { + class: ClassName::FLEX_RIGHT_AERO_BUTTON, + style: "background: url(./images/brush.png) no-repeat center", + }, + button { + class: ClassName::AERO_BUTTON, + style: "background: url(./images/settings.png) no-repeat center", + }, + + }, + + }, + + div { + class: ClassName::SEARCH, + + div { + class: ClassName::INNER, + + input { + class: ClassName::SEARCH_INPUT, + placeholder: "Find a contact...", + r#type: "text", + }, + + button { + class: ClassName::BUTTON, + style: "background: url(./images/add_user.png) no-repeat center", + }, + + button { + class: ClassName::BUTTON, + style: "background: url(./images/tbc_transfert.png) no-repeat center", + }, + }, + }, + + Contacts {}, + + div { + class: ClassName::FOOTER, + }, + }, + }) +} diff --git a/src/components/login.rs b/src/components/login.rs index 777da91..a1a5b4b 100644 --- a/src/components/login.rs +++ b/src/components/login.rs @@ -19,7 +19,7 @@ pub fn Login(cx: Scope) -> Element { let invalid_login = use_state(cx, || false); - let login = use_ref(cx, || Login::new()); + let login = use_ref(cx, Login::new); let password_class = if **invalid_login { ClassName::INVALID_INPUT @@ -127,11 +127,10 @@ struct Login { impl Login { fn new() -> Self { - let login = Self { + Self { homeserver_url: None, email: None, password: None, - }; - login + } } } diff --git a/src/components/main_window.rs b/src/components/main_window.rs index 0514503..d1055dd 100644 --- a/src/components/main_window.rs +++ b/src/components/main_window.rs @@ -3,7 +3,7 @@ use fermi::*; use tracing::debug; use crate::base::SESSION; -use crate::components::contacts_window::contacts_window::ContactsWindow; +use crate::components::contacts_window::ContactsWindow; use crate::components::login::Login; pub fn MainWindow(cx: Scope) -> Element { diff --git a/src/main.rs b/src/main.rs index 2516ad3..7814dc9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ pub mod components; pub mod matrix_interface; use crate::base::{login, sync_rooms, APP_SETTINGS, ROOMS, SESSION}; -use crate::components::chats_window::chats_window::{ChatsWindow, ChatsWindowProps}; +use crate::components::chats_window::{ChatsWindow, ChatsWindowProps}; use crate::components::main_window::MainWindow; mod base; diff --git a/src/matrix_interface/client.rs b/src/matrix_interface/client.rs index c539740..eeea087 100644 --- a/src/matrix_interface/client.rs +++ b/src/matrix_interface/client.rs @@ -291,13 +291,9 @@ impl Client { let joined_matrix_rooms_ref = &matrix_client.joined_rooms(); let invited_matrix_rooms_ref = &matrix_client.invited_rooms(); - for matrix_rooms in vec![joined_matrix_rooms_ref, invited_matrix_rooms_ref] { + for matrix_rooms in [joined_matrix_rooms_ref, invited_matrix_rooms_ref] { for matrix_room in matrix_rooms.iter() { - let topic = match matrix_room.topic() { - None => None, - Some(topic) => Some(RefCell::new(topic)), - }; - + let topic = matrix_room.topic().map(RefCell::new); let room = Room::new( Arc::new(matrix_room.to_owned()), topic, @@ -405,7 +401,7 @@ impl Client { async fn run(&mut self, task: WorkerTask) { match task { WorkerTask::Init(reply) => { - assert_eq!(self.initialized, false); + assert!(!self.initialized); self.init(); reply.send(()); } diff --git a/src/matrix_interface/requester.rs b/src/matrix_interface/requester.rs index adf30d0..d1c6953 100644 --- a/src/matrix_interface/requester.rs +++ b/src/matrix_interface/requester.rs @@ -35,12 +35,12 @@ impl Requester { pub fn init(&self) { let (reply, response) = oneshot(); self.tx.send(WorkerTask::Init(reply)).unwrap(); - return response.recv(); + response.recv() } pub fn login(&self, style: LoginStyle) -> anyhow::Result<()> { let (reply, response) = oneshot(); self.tx.send(WorkerTask::Login(style, reply)).unwrap(); - return response.recv(); + response.recv() } } diff --git a/src/matrix_interface/worker_tasks.rs b/src/matrix_interface/worker_tasks.rs index ff38ae3..82074f8 100644 --- a/src/matrix_interface/worker_tasks.rs +++ b/src/matrix_interface/worker_tasks.rs @@ -24,7 +24,7 @@ pub(super) fn oneshot() -> (ClientReply, ClientResponse) { let reply = ClientReply(tx); let response = ClientResponse(rx); - return (reply, response); + (reply, response) } #[derive(Debug)]