summaryrefslogtreecommitdiffstats
path: root/src/components/chats_list
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/components/chats_list.rs33
-rw-r--r--src/components/chats_list/chats_list_item.rs48
2 files changed, 59 insertions, 22 deletions
diff --git a/src/components/chats_list.rs b/src/components/chats_list.rs
index f958ebe..43ee53e 100644
--- a/src/components/chats_list.rs
+++ b/src/components/chats_list.rs
@@ -4,7 +4,14 @@ use jid::BareJID;
use leptos::prelude::*;
use tracing::debug;
-use crate::{chat::{ArcMacawChat, MacawChat}, client::Client, components::{icon::IconComponent, new_chat::NewChatWidget, overlay::Overlay}, icon::Icon, message::{ArcMacawMessage, MacawMessage}, message_subscriptions::MessageSubscriptions};
+use crate::{
+ chat::{ArcMacawChat, MacawChat},
+ client::Client,
+ components::{icon::IconComponent, new_chat::NewChatWidget, overlay::Overlay},
+ icon::Icon,
+ message::{ArcMacawMessage, MacawMessage},
+ message_subscriptions::MessageSubscriptions,
+};
mod chats_list_item;
@@ -22,11 +29,13 @@ pub fn ChatsList() -> impl IntoView {
Ok(c) => {
let mut chats = IndexMap::new();
for ((chat, chat_user), (message, message_user)) in c {
- chats.insert(chat.correspondent.clone(), (
+ chats.insert(
+ chat.correspondent.clone(),
+ (
ArcMacawChat::got_chat_and_user(chat, chat_user).await,
ArcMacawMessage::got_message_and_user(message, message_user).await,
-
- ));
+ ),
+ );
}
set_chats.set(chats);
}
@@ -51,7 +60,10 @@ pub fn ChatsList() -> impl IntoView {
if let Some((chat, _latest_message)) = chats.shift_remove(&to) {
// TODO: check if new message is actually latest message
debug!("chat existed");
- debug!("new message: {}", new_message.message.get().read().body.body);
+ debug!(
+ "new message: {}",
+ new_message.message.get().read().body.body
+ );
chats.insert_before(0, to, (chat.clone(), new_message));
debug!("done setting");
} else {
@@ -79,15 +91,19 @@ pub fn ChatsList() -> impl IntoView {
// TODO: update icon, tooltip on hover.
<div class="header">
<h2>Chats</h2>
- <div class="new-chat header-icon" class:open=open_new_chat >
- <IconComponent icon=Icon::NewBubble24 on:click=move |_| set_open_new_chat.update(|state| *state = !*state)/>
+ <div class="new-chat header-icon" class:open=open_new_chat>
+ <IconComponent
+ icon=Icon::NewBubble24
+ on:click=move |_| set_open_new_chat.update(|state| *state = !*state)
+ />
{move || {
if *open_new_chat.read() {
view! {
<Overlay set_open=set_open_new_chat>
<NewChatWidget set_open_new_chat />
</Overlay>
- }.into_any()
+ }
+ .into_any()
} else {
view! {}.into_any()
}
@@ -102,4 +118,3 @@ pub fn ChatsList() -> impl IntoView {
</div>
}
}
-
diff --git a/src/components/chats_list/chats_list_item.rs b/src/components/chats_list/chats_list_item.rs
index ae01288..e61bf45 100644
--- a/src/components/chats_list/chats_list_item.rs
+++ b/src/components/chats_list/chats_list_item.rs
@@ -1,12 +1,21 @@
use std::ops::Deref;
use chrono::Local;
-use filamento::{chat::{Chat, ChatStoreFields, Message, MessageStoreFields}, user::User};
+use filamento::{
+ chat::{Chat, ChatStoreFields, Message, MessageStoreFields},
+ user::User,
+};
use leptos::prelude::*;
use reactive_stores::{ArcStore, Store};
use tracing::debug;
-use crate::{chat::MacawChat, components::{avatar::AvatarWithPresence, sidebar::Open}, message::MacawMessage, open_chats::{OpenChatsPanel, OpenChatsPanelStoreFields}, user::get_name};
+use crate::{
+ chat::MacawChat,
+ components::{avatar::AvatarWithPresence, sidebar::Open},
+ message::MacawMessage,
+ open_chats::{OpenChatsPanel, OpenChatsPanelStoreFields},
+ user::get_name,
+};
#[component]
pub fn ChatsListItem(chat: MacawChat, message: MacawMessage) -> impl IntoView {
@@ -44,23 +53,36 @@ pub fn ChatsListItem(chat: MacawChat, message: MacawMessage) -> impl IntoView {
let date = move || message.get().timestamp().read().naive_local();
let now = move || Local::now().naive_local();
- let timeinfo = move || if date().date() == now().date() {
- // TODO: localisation/config
- date().time().format("%H:%M").to_string()
- } else {
- date().date().format("%d/%m").to_string()
+ let timeinfo = move || {
+ if date().date() == now().date() {
+ // TODO: localisation/config
+ date().time().format("%H:%M").to_string()
+ } else {
+ date().date().format("%d/%m").to_string()
+ }
};
view! {
- <div class="chats-list-item" class:open=move || open() class:focused=move || focused() on:click=open_chat>
+ <div
+ class="chats-list-item"
+ class:open=move || open()
+ class:focused=move || focused()
+ on:click=open_chat
+ >
{move || {
- view! {
- <AvatarWithPresence user=chat.user />
- }
+ view! { <AvatarWithPresence user=chat.user /> }
}}
<div class="item-info">
- <div class="main-info"><p class="name">{name}</p><p class="timestamp">{timeinfo}</p></div>
- <div class="sub-info"><p class="message-preview">{latest_message_body}</p><p><!-- "TODO: delivery or unread state" --></p></div>
+ <div class="main-info">
+ <p class="name">{name}</p>
+ <p class="timestamp">{timeinfo}</p>
+ </div>
+ <div class="sub-info">
+ <p class="message-preview">{latest_message_body}</p>
+ <p>
+ <!-- "TODO: delivery or unread state" -->
+ </p>
+ </div>
</div>
</div>
}