diff options
author | 2025-06-01 21:32:13 +0100 | |
---|---|---|
committer | 2025-06-01 21:32:13 +0100 | |
commit | 12d9e5955092b282a96add03ddfc148f01f3a3e8 (patch) | |
tree | bca74c6132c25c8493b8b209f20203c71b1daad6 /src/chat.rs | |
parent | 33bb7130943b5f74b3b0f08c5e6d8f7c5e54d4c0 (diff) | |
download | macaw-web-leptos-fetch.tar.gz macaw-web-leptos-fetch.tar.bz2 macaw-web-leptos-fetch.zip |
WIP: fix untracked stateleptos-fetch
Diffstat (limited to '')
-rw-r--r-- | src/chat.rs | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/chat.rs b/src/chat.rs index a1ced32..6612431 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -8,14 +8,19 @@ use leptos::prelude::*; use crate::{client::Client, user::MacawUser}; +#[derive(Clone)] +pub struct GotChat(Chat); + async fn get_chat(jid: BareJID) -> ArcStore<Chat> { - let client: Client = use_context().expect("no client in context"); - ArcStore::new(client.get_chat(jid).await.unwrap()) + // let client: Client = use_context().expect("no client in context"); + // ArcStore::new(client.get_chat(jid).await.unwrap()) + let GotChat(chat) = use_context().expect("no chat in context"); + ArcStore::new(chat) } -#[derive(Clone)] +#[derive(Clone, Copy)] pub struct MacawChat { - pub chat: ArcStore<Chat>, + pub chat: LocalResource<ArcStore<Chat>>, pub user: MacawUser, // user: StateListener<BareJID, ArcStore<User>>, } @@ -25,26 +30,18 @@ impl MacawChat { let query_client: QueryClient = expect_context(); let jid = chat.correspondent.clone(); - let chat_store = query_client.subscribe_value_local(get_chat, move || jid.clone()); - if let Some(chat_store) = chat_store.get() { - chat_store.set(chat); - let user = MacawUser::got_user(user); - Self { chat: chat_store, user } - } else { - let jid = chat.correspondent.clone(); - let chat_store = ArcStore::new(chat); - query_client.set_query_local(get_chat, jid, chat_store.clone()); - let user = MacawUser::got_user(user); - Self { - chat: chat_store, - user, - } + provide_context(GotChat(chat)); + let chat = query_client.local_resource(get_chat, move || jid.clone()); + let user = MacawUser::got_user(user); + Self { + chat, + user, } } } impl Deref for MacawChat { - type Target = ArcStore<Chat>; + type Target = LocalResource<ArcStore<Chat>>; fn deref(&self) -> &Self::Target { &self.chat |