kind of post messages

This commit is contained in:
2024-06-21 00:53:32 -04:00
Unverified
parent add6dfa468
commit c2cdccf8ba
2 changed files with 38 additions and 25 deletions

View File

@@ -1,5 +1,5 @@
use iced::alignment::{self, Alignment}; use iced::alignment::{self, Alignment};
use iced::keyboard; use iced::{keyboard, Renderer, Theme};
use iced::widget::{ use iced::widget::{
self, button, center, checkbox, column, container, keyed_column, row, self, button, center, checkbox, column, container, keyed_column, row,
scrollable, text, text_input, Text, scrollable, text, text_input, Text,
@@ -47,6 +47,15 @@ impl RealmApp {
Command::none() Command::none()
} }
Events::SendMessage => { Events::SendMessage => {
self.messages.push(Message {
guid: "".to_string(),
text: Some(self.input_value.clone()),
attachments: None,
reply_to_guid: None,
reaction_emoji: None,
redact: false,
});
//TODO //TODO
self.input_value.clear(); self.input_value.clear();
Command::none() Command::none()
@@ -57,12 +66,6 @@ impl RealmApp {
} }
pub fn view(&self) -> Element<Events> { pub fn view(&self) -> Element<Events> {
let title = text("todos")
.width(Length::Fill)
.size(100)
.color([0.5, 0.5, 0.5])
.horizontal_alignment(alignment::Horizontal::Center);
let input = text_input("New Message", &*self.input_value) let input = text_input("New Message", &*self.input_value)
.id(INPUT_ID.clone()) .id(INPUT_ID.clone())
.on_input(Events::InputChanged) .on_input(Events::InputChanged)
@@ -70,18 +73,28 @@ impl RealmApp {
//.padding(15) //.padding(15)
.size(12); .size(12);
let messages: Vec<Text> = Vec::new(); let mut all_messages: String = String::new();
for message in &self.messages { for message in self.messages.iter() {
match message.clone().text {
None => {}
Some(text) => {
all_messages = format!("{}{}\n", all_messages, text)
}
}
} }
let content = column![title, input] let messages = text(all_messages)
.spacing(20); .size(12)
.width(Length::Fill)
.height(600)
.horizontal_alignment(alignment::Horizontal::Left);
// let content = column![title, input]
// .spacing(20);
//.max_width(800); //.max_width(800);
scrollable( column!(scrollable(
container(content).center_x(Length::Fill).padding(40), container(messages).center_x(Length::Fill).padding(40)), input).into()
).into()
} }
pub fn subscription(&self) -> Subscription<Events> { pub fn subscription(&self) -> Subscription<Events> {

View File

@@ -3,18 +3,18 @@ pub trait RealmChat {
async fn test(name: String) -> String; async fn test(name: String) -> String;
} }
#[derive(Debug)] #[derive(Debug, Clone)]
pub struct Message { pub struct Message {
guid: String, pub guid: String,
text: Option<String>, pub text: Option<String>,
attachments: Option<Vec<Attachment>>, pub attachments: Option<Vec<Attachment>>,
reply_to_guid: Option<String>, pub reply_to_guid: Option<String>,
reaction_emoji: Option<String>, pub reaction_emoji: Option<String>,
redact: bool, pub redact: bool,
} }
#[derive(Debug)] #[derive(Debug, Clone)]
pub struct Attachment { pub struct Attachment {
guid: String, pub guid: String,
//TODO //TODO
} }