simple chat window
This commit is contained in:
+40
-4
@@ -26,10 +26,17 @@ pub struct UserState {
|
||||
pub channel: ChannelId,
|
||||
}
|
||||
|
||||
pub struct Chat {
|
||||
pub text: String,
|
||||
pub dangerous_html: String,
|
||||
pub sender: Option<UserId>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ServerState {
|
||||
pub channels: HashMap<ChannelId, ChannelState>,
|
||||
pub users: HashMap<UserId, UserState>,
|
||||
pub chat: Vec<Chat>,
|
||||
}
|
||||
|
||||
pub struct State {
|
||||
@@ -72,14 +79,43 @@ pub fn Channel(id: ChannelId) -> Element {
|
||||
)
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn ChatHistory() -> Element {
|
||||
let server = STATE.server.read();
|
||||
rsx!(
|
||||
div {
|
||||
style: "margin: 16px; padding: 16px; border: solid black 1px;",
|
||||
for chat in server.chat.iter() {
|
||||
if let Some(sender) = chat.sender.and_then(|u| server.users.get(&u)) {
|
||||
span {
|
||||
style: "border: solid black 1px; border-radius: 4px;",
|
||||
"{sender.name}"
|
||||
}
|
||||
"\u{8194}"
|
||||
}
|
||||
span {
|
||||
dangerous_inner_html: "{chat.dangerous_html}",
|
||||
}
|
||||
hr {}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn ServerView() -> Element {
|
||||
let server = STATE.server.read();
|
||||
rsx!(for (id, state) in server.channels.iter() {
|
||||
if state.parent.is_none() {
|
||||
Channel { id: *id }
|
||||
rsx!(
|
||||
div {
|
||||
style: "margin: 16px; padding: 16px; border: solid black 1px;",
|
||||
for (id, state) in server.channels.iter() {
|
||||
if state.parent.is_none() {
|
||||
Channel { id: *id }
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
ChatHistory {}
|
||||
)
|
||||
}
|
||||
|
||||
pub fn app() -> Element {
|
||||
|
||||
Reference in New Issue
Block a user