🏗️ Rearchitecting the interface with the MatrixClient
- Replace RwStore with channels. - Use of fermi to handle application data. - Use of tracing.
This commit is contained in:
@@ -3,9 +3,11 @@ 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 tracing::{debug, warn};
|
||||
|
||||
use crate::base::Room;
|
||||
use crate::base::{ByIdRooms, Room, ROOMS};
|
||||
|
||||
turf::style_sheet!("src/components/contacts_window/contacts_section.scss");
|
||||
|
||||
@@ -19,11 +21,46 @@ fn ContactsArrow(cx: Scope) -> Element {
|
||||
})
|
||||
}
|
||||
|
||||
static NO_NAME_REPR: &str = "No name";
|
||||
static NO_SUBJECT_REPR: &str = "No subject";
|
||||
|
||||
#[inline_props]
|
||||
pub fn ContactsSection<'a>(cx: Scope, name: &'a str, contacts: RefCell<Vec<Room>>) -> Element {
|
||||
println!("ContactsSection rendering");
|
||||
pub 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());
|
||||
|
||||
for room in rooms.values() {
|
||||
let is_direct = room.borrow().is_direct.unwrap();
|
||||
if !is_direct {
|
||||
filtered_rooms.push(room.to_owned());
|
||||
}
|
||||
}
|
||||
filtered_rooms
|
||||
}
|
||||
|
||||
pub 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());
|
||||
|
||||
for room in rooms.values() {
|
||||
let is_direct = room.borrow().is_direct.unwrap();
|
||||
if is_direct {
|
||||
filtered_rooms.push(room.to_owned());
|
||||
}
|
||||
}
|
||||
filtered_rooms
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn ContactsSection<'a>(
|
||||
cx: Scope,
|
||||
name: &'a str,
|
||||
filter: &'a dyn Fn(UseAtomRef<ByIdRooms>) -> Vec<RefCell<Room>>,
|
||||
) -> Element {
|
||||
debug!("ContactsSection rendering");
|
||||
|
||||
let rooms_atom = use_atom_ref(cx, &ROOMS);
|
||||
let contacts = filter(rooms_atom.clone());
|
||||
let contacts_len = contacts.len();
|
||||
|
||||
let show = use_state(cx, || false);
|
||||
|
||||
@@ -33,11 +70,19 @@ pub fn ContactsSection<'a>(cx: Scope, name: &'a str, contacts: RefCell<Vec<Room>
|
||||
]
|
||||
.join(" ");
|
||||
|
||||
let contacts_len = contacts.borrow().len();
|
||||
let rendered_contacts = contacts.into_iter().map(|room_ref| {
|
||||
let room = room_ref.borrow();
|
||||
|
||||
let room_topic = room
|
||||
.topic
|
||||
.as_ref()
|
||||
.unwrap_or(&RefCell::new(NO_SUBJECT_REPR.to_string()))
|
||||
.borrow()
|
||||
.to_owned();
|
||||
let room_name = room.name().unwrap_or(NO_NAME_REPR.to_string());
|
||||
|
||||
let rendered_contacts = contacts.borrow_mut().clone().into_iter().map(|room| {
|
||||
let room_name = room.name().unwrap();
|
||||
let is_invited = room.matrix_room.state() == RoomState::Invited;
|
||||
|
||||
let formatted = format!(
|
||||
"{room_name} - {}",
|
||||
if is_invited {
|
||||
@@ -47,8 +92,6 @@ pub fn ContactsSection<'a>(cx: Scope, name: &'a str, contacts: RefCell<Vec<Room>
|
||||
}
|
||||
);
|
||||
|
||||
let room_topic = room.topic.unwrap_or(NO_SUBJECT_REPR.to_string()).to_owned();
|
||||
|
||||
rsx!(li {
|
||||
img {
|
||||
src: "./images/status_online.png",
|
||||
@@ -60,8 +103,7 @@ pub fn ContactsSection<'a>(cx: Scope, name: &'a str, contacts: RefCell<Vec<Room>
|
||||
style: "color: darkgrey;",
|
||||
room_topic,
|
||||
},
|
||||
},
|
||||
)
|
||||
})
|
||||
});
|
||||
|
||||
cx.render(rsx! {
|
||||
|
Reference in New Issue
Block a user