🚧 Add an interface to the ChatsWindows to drive its behavior

For now, only the ChatsWindow tabs are toggled on clicks on room names (from ContactsSection).
This commit is contained in:
2023-12-30 23:31:51 +01:00
parent 2fed770f62
commit 116bbcb247
9 changed files with 208 additions and 92 deletions

View File

@@ -1,13 +1,12 @@
use std::cell::RefCell;
use dioxus::prelude::*;
use dioxus_free_icons::icons::io_icons::IoChevronDown;
use dioxus_free_icons::Icon;
use fermi::prelude::*;
use matrix_sdk::RoomState;
use matrix_sdk::{ruma::OwnedRoomId, RoomState};
use tracing::{debug, warn};
use crate::base::{ByIdRooms, Room, ROOMS};
use crate::base::{ByIdRooms, Room, CHATS_WIN_INTERFACE, ROOMS};
use crate::components::chats_window::interface::Interface as ChatsWindowInterface;
turf::style_sheet!("src/components/contacts_window/contacts_section.scss");
@@ -24,7 +23,7 @@ fn ContactsArrow(cx: Scope) -> Element {
static NO_NAME_REPR: &str = "No name";
static NO_SUBJECT_REPR: &str = "No subject";
pub fn filter_people_conversations(rooms_atom: UseAtomRef<ByIdRooms>) -> Vec<RefCell<Room>> {
pub(super) fn filter_people_conversations(rooms_atom: UseAtomRef<ByIdRooms>) -> Vec<RefCell<Room>> {
let rooms = rooms_atom.read();
let mut filtered_rooms = Vec::<RefCell<Room>>::with_capacity(rooms.len());
@@ -37,7 +36,7 @@ pub fn filter_people_conversations(rooms_atom: UseAtomRef<ByIdRooms>) -> Vec<Ref
filtered_rooms
}
pub fn filter_room_conversations(rooms_atom: UseAtomRef<ByIdRooms>) -> Vec<RefCell<Room>> {
pub(super) fn filter_room_conversations(rooms_atom: UseAtomRef<ByIdRooms>) -> Vec<RefCell<Room>> {
let rooms = rooms_atom.read();
let mut filtered_rooms = Vec::<RefCell<Room>>::with_capacity(rooms.len());
@@ -50,6 +49,14 @@ pub fn filter_room_conversations(rooms_atom: UseAtomRef<ByIdRooms>) -> Vec<RefCe
filtered_rooms
}
// TODO: Handle errors
fn on_clicked_room(
room_id: &OwnedRoomId,
chats_window_interface: &UseAtomRef<ChatsWindowInterface>,
) {
let _ = chats_window_interface.read().toggle_room(room_id.clone());
}
#[component]
pub fn ContactsSection<'a>(
cx: Scope,
@@ -58,8 +65,10 @@ pub fn ContactsSection<'a>(
) -> Element {
debug!("ContactsSection rendering");
let rooms_atom = use_atom_ref(cx, &ROOMS);
let contacts = filter(rooms_atom.clone());
let rooms_atom_ref = use_atom_ref(cx, &ROOMS);
let chats_window_interface_ref = use_atom_ref(cx, &CHATS_WIN_INTERFACE);
let contacts = filter(rooms_atom_ref.clone());
let contacts_len = contacts.len();
let show = use_state(cx, || false);
@@ -80,6 +89,7 @@ pub fn ContactsSection<'a>(
.borrow()
.to_owned();
let room_name = room.name().unwrap_or(NO_NAME_REPR.to_string());
let room_id = room.id();
let is_invited = room.matrix_room.state() == RoomState::Invited;
@@ -93,6 +103,8 @@ pub fn ContactsSection<'a>(
);
rsx!(li {
onclick: move |_| on_clicked_room(&room_id, chats_window_interface_ref),
img {
src: "./images/status_online.png",
},