some error handling improvements & start on chat send
This commit is contained in:
+50
-7
@@ -5,13 +5,31 @@ use std::collections::{BTreeMap, BTreeSet, HashMap};
|
||||
use dioxus::prelude::*;
|
||||
use ordermap::OrderSet;
|
||||
|
||||
use super::Command;
|
||||
use super::Command::*;
|
||||
use super::ConnectionState::{self, *};
|
||||
|
||||
pub type ChannelId = u32;
|
||||
pub type UserId = u32;
|
||||
|
||||
pub enum ConnectionState {
|
||||
Disconnected,
|
||||
Connecting,
|
||||
Connected,
|
||||
}
|
||||
|
||||
pub enum Command {
|
||||
Connect {
|
||||
address: String,
|
||||
username: String,
|
||||
hash: String,
|
||||
},
|
||||
SendChat {
|
||||
markdown: String,
|
||||
channels: Vec<ChannelId>,
|
||||
},
|
||||
Disconnect,
|
||||
}
|
||||
|
||||
use Command::*;
|
||||
use ConnectionState::*;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ChannelState {
|
||||
pub name: String,
|
||||
@@ -27,7 +45,7 @@ pub struct UserState {
|
||||
}
|
||||
|
||||
pub struct Chat {
|
||||
pub text: String,
|
||||
pub raw: String,
|
||||
pub dangerous_html: String,
|
||||
pub sender: Option<UserId>,
|
||||
}
|
||||
@@ -37,6 +55,13 @@ pub struct ServerState {
|
||||
pub channels: HashMap<ChannelId, ChannelState>,
|
||||
pub users: HashMap<UserId, UserState>,
|
||||
pub chat: Vec<Chat>,
|
||||
pub session: Option<UserId>,
|
||||
}
|
||||
|
||||
impl ServerState {
|
||||
pub fn this_user(&self) -> Option<&UserState> {
|
||||
self.users.get(&self.session?)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct State {
|
||||
@@ -80,8 +105,10 @@ pub fn Channel(id: ChannelId) -> Element {
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn ChatHistory() -> Element {
|
||||
pub fn ChatView() -> Element {
|
||||
let server = STATE.server.read();
|
||||
let mut draft = use_signal(|| "".to_string());
|
||||
//let net: Coroutine<Command> = use_coroutine_handle();
|
||||
rsx!(
|
||||
div {
|
||||
style: "margin: 16px; padding: 16px; border: solid black 1px;",
|
||||
@@ -98,6 +125,22 @@ pub fn ChatHistory() -> Element {
|
||||
}
|
||||
hr {}
|
||||
}
|
||||
input {
|
||||
placeholder: "say something",
|
||||
value: "{draft.read()}",
|
||||
oninput: move |evt| draft.set(evt.value().clone()),
|
||||
}
|
||||
button {
|
||||
onclick: move |_| {
|
||||
/*if let Some(user) = server.this_user() {
|
||||
net.send(SendChat {
|
||||
markdown: draft.write().split_off(0),
|
||||
channels: vec![user.channel],
|
||||
});
|
||||
}*/
|
||||
},
|
||||
"Send"
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -114,7 +157,7 @@ pub fn ServerView() -> Element {
|
||||
}
|
||||
}
|
||||
}
|
||||
ChatHistory {}
|
||||
ChatView {}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user