Skip to content

Commit

Permalink
feat: Fix Dioxus signal read and use_effect closure
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed Dec 25, 2024
1 parent 41094d9 commit c568690
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions ui/src/components/app/freenet_api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashSet;
use futures::StreamExt;
use common::room_state::ChatRoomParametersV1;
use dioxus::prelude::{Global, GlobalSignal, UnboundedSender, use_coroutine, use_context, Signal, Writable, use_effect};
use dioxus::prelude::{Global, GlobalSignal, UnboundedSender, use_coroutine, use_context, Signal, Writable, use_effect, Readable};
use freenet_scaffold::ComposableState;
use ed25519_dalek::VerifyingKey;
use freenet_stdlib::{
Expand Down Expand Up @@ -91,21 +91,22 @@ impl FreenetApiSynchronizer {
let request_sender = request_sender.clone();

use_effect(move || {
let rooms_ref = rooms.read();
for room in rooms_ref.map.values() {
let state_bytes = to_cbor_vec(&room.room_state);
let update_request = ContractRequest::Update {
key: room.contract_key,
data: freenet_stdlib::prelude::UpdateData::State(state_bytes.into()),
};
let sender = request_sender.clone();
wasm_bindgen_futures::spawn_local(async move {
if let Err(e) = sender.send(update_request.into()).await {
log::error!("Failed to send room update: {}", e);
}
});
{
let rooms_ref = rooms.read();
for room in rooms_ref.map.values() {
let state_bytes = to_cbor_vec(&room.room_state);
let update_request = ContractRequest::Update {
key: room.contract_key,
data: freenet_stdlib::prelude::UpdateData::State(state_bytes.into()),
};
let sender = request_sender.clone();
wasm_bindgen_futures::spawn_local(async move {
if let Err(e) = sender.send(update_request.into()).await {
log::error!("Failed to send room update: {}", e);
}
});
}
}
|| ()
});

// Main event loop
Expand Down

0 comments on commit c568690

Please sign in to comment.