Skip to content

Commit

Permalink
missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed Dec 16, 2024
1 parent 863baf9 commit 568e45d
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[build]
target = "wasm32-unknown-unknown"

[profile]

[profile.dioxus-wasm]
Expand Down
16 changes: 13 additions & 3 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"rust-analyzer.cargo.target": "wasm32-unknown-unknown"
"rust-analyzer.diagnostics.enable": false
}
46 changes: 24 additions & 22 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "dx build",
"type": "shell",
"command": "dx",
"args": ["build", "--platform", "web"],
"options": {
"cwd": "${workspaceFolder}/ui"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": {
"owner": "rust",
"fileLocation": ["relative", "${workspaceFolder}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s(\\d+):\\s(.*)$",
"file": 1,
"line": 2,
"column": 3,
"message": 5
{
"label": "Build with dx in ui directory",
"type": "shell",
"command": "dx build --platform web",
"options": {
"cwd": "${workspaceFolder}/ui"
},
"problemMatcher": {
"owner": "rust",
"fileLocation": ["relative", "${workspaceFolder}"],
"pattern": [
{
"regexp": "^(.+):(\\d+):(\\d+):\\s+(error|warning):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
]
},
"group": {
"kind": "build",
"isDefault": true
}
}
}
]
}
9 changes: 1 addition & 8 deletions ui/src/components/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@ mod freenet_api;
use super::{conversation::Conversation, members::MemberList, room_list::RoomList};
use crate::components::members::member_info_modal::MemberInfoModal;
use crate::components::room_list::edit_room_modal::EditRoomModal;
use crate::constants::ROOM_CONTRACT_WASM;
use crate::room_data::{CurrentRoom, Rooms};
use crate::util::to_cbor_vec;
use common::room_state::member::MemberId;
use common::room_state::ChatRoomParametersV1;
use dioxus::prelude::*;
use document::Stylesheet;
use ed25519_dalek::VerifyingKey;
use freenet_stdlib::client_api::WebApi;
use freenet_stdlib::client_api::{ClientError, ClientRequest, HostResponse};
use freenet_stdlib::prelude::{ContractCode, ContractInstanceId, Parameters};
use futures::SinkExt;

pub fn App() -> Element {
use_context_provider(|| Signal::new(initial_rooms()));
Expand All @@ -23,7 +16,7 @@ pub fn App() -> Element {
use_context_provider(|| Signal::new(EditRoomModalSignal { room: None }));
use_context_provider(|| Signal::new(CreateRoomModalSignal { show: false }));

connect_to_freenet();
//connect_to_freenet();

rsx! {
Stylesheet { href: asset!("./assets/bulma.min.css") }
Expand Down
65 changes: 65 additions & 0 deletions ui/src/components/app/freenet_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use common::room_state::ChatRoomParametersV1;
use ed25519_dalek::VerifyingKey;
use freenet_stdlib::{client_api::{ClientError, ClientRequest, ContractRequest, HostResponse}, prelude::{ContractCode, ContractInstanceId, ContractKey, Parameters}};
use freenet_stdlib::client_api::WebApi;

use crate::{constants::ROOM_CONTRACT_WASM, util::to_cbor_vec};
use futures::sink::SinkExt;

pub struct FreenetApi<'a> {
pub api: WebApi,
pub requests: futures::channel::mpsc::UnboundedReceiver<ClientRequest<'a>>,
pub host_responses: futures::channel::mpsc::UnboundedSender<HostResponse>,
}

impl FreenetApi<'_> {
pub fn new() -> Self {
let conn = web_sys::WebSocket::new(
"ws://localhost:50509/contract/command?encodingProtocol=native",
)
.unwrap();
let (send_host_responses, host_responses) = futures::channel::mpsc::unbounded();
let (send_half, requests) =
futures::channel::mpsc::unbounded::<freenet_stdlib::client_api::ClientRequest>();
let result_handler = move |result: Result<HostResponse, ClientError>| {
let mut send_host_responses_clone = send_host_responses.clone();
let _ = wasm_bindgen_futures::future_to_promise(async move {
send_host_responses_clone
.send(result)
.await
.expect("channel open");
Ok(wasm_bindgen::JsValue::NULL)
});
};
let (tx, rx) = futures::channel::oneshot::channel();
let onopen_handler = move || {
let _ = tx.send(());
};
let mut api = WebApi::start(
conn,
result_handler,
|err| {
log::error!("host error: {}", err);
},
onopen_handler,
);
todo!()
//Self {
// api,
// requests: requests,
// host_responses: host_responses,
// }
}

pub fn subscribe(&mut self, room_owner: &VerifyingKey) {
let parameters = ChatRoomParametersV1 { owner: *room_owner };
let parameters = to_cbor_vec(&parameters);
let parameters: Parameters = parameters.into();
let contract_code = ContractCode::from(ROOM_CONTRACT_WASM);
let contract_instance_id =
ContractInstanceId::from_params_and_code(parameters, contract_code);
let contract_key = ContractKey::from(contract_instance_id);
let request = ContractRequest::Subscribe {key : contract_key, summary : None };
// self.api.send_request(request);
}
}

0 comments on commit 568e45d

Please sign in to comment.