From add6dfa46877bc6c5e38797d3936de566e2f2978 Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Thu, 20 Jun 2024 22:03:56 -0400 Subject: [PATCH] further stripping idk if this is still worth it, if the docs are really this bad --- client/src/app.rs | 121 ++++++++++++++------------------------------- client/src/main.rs | 1 - 2 files changed, 36 insertions(+), 86 deletions(-) diff --git a/client/src/app.rs b/client/src/app.rs index 0c52802..7239af1 100644 --- a/client/src/app.rs +++ b/client/src/app.rs @@ -6,6 +6,7 @@ use iced::widget::{ }; use iced::window; use iced::{Command, Element, Font, Length, Subscription}; +use iced::futures::StreamExt; use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; @@ -15,14 +16,7 @@ use realm_server::types::Message; static INPUT_ID: Lazy = Lazy::new(text_input::Id::unique); #[derive(Default, Debug)] -pub enum RealmApp { - #[default] - Loading, - Loaded(State), -} - -#[derive(Debug, Default)] -pub struct State { +pub struct RealmApp { input_value: String, messages: Vec, } @@ -46,91 +40,48 @@ impl RealmApp { } pub fn update(&mut self, event: Events) -> Command { - match self { - RealmApp::Loading => { - text_input::focus(INPUT_ID.clone()) + let command = match event { + Events::InputChanged(value) => { + self.input_value = value; + + Command::none() } - RealmApp::Loaded(state) => { - let command = match event { - Events::InputChanged(value) => { - state.input_value = value; - - Command::none() - } - Events::SendMessage => { - //TODO - - Command::none() - } - }; - - Command::batch(vec![command]) + Events::SendMessage => { + //TODO + self.input_value.clear(); + Command::none() } - } + }; + + Command::batch(vec![command]) } pub fn view(&self) -> Element { - match self { - RealmApp::Loading => loading_message(), - RealmApp::Loaded(State { - input_value, - messages: tasks, - .. - }) => { - let title = text("todos") - .width(Length::Fill) - .size(100) - .color([0.5, 0.5, 0.5]) - .horizontal_alignment(alignment::Horizontal::Center); + 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("What needs to be done?", input_value) - .id(INPUT_ID.clone()) - .on_input(Events::InputChanged) - .on_submit(Events::SendMessage) - .padding(15) - .size(30); + let input = text_input("New Message", &*self.input_value) + .id(INPUT_ID.clone()) + .on_input(Events::InputChanged) + .on_submit(Events::SendMessage) + //.padding(15) + .size(12); - // let controls = view_controls(tasks, *filter); - // let filtered_tasks = - // tasks.iter().filter(|task| filter.matches(task)); - // - // let tasks: Element<_> = if filtered_tasks.count() > 0 { - // keyed_column( - // tasks - // .iter() - // .enumerate() - // .filter(|(_, task)| filter.matches(task)) - // .map(|(i, task)| { - // ( - // task.id, - // task.view(i).map(move |message| { - // Events::TaskMessage(i, message) - // }), - // ) - // }), - // ) - // .spacing(10) - // .into() - // } else { - // empty_message(match filter { - // Filter::All => "You have not created a task yet...", - // Filter::Active => "All your tasks are done! :D", - // Filter::Completed => { - // "You have not completed a task yet..." - // } - // }) - // }; - - let content = column![title, input] - .spacing(20) - .max_width(800); - - scrollable( - container(content).center_x(Length::Fill).padding(40), - ) - .into() - } + let messages: Vec = Vec::new(); + for message in &self.messages { + } + + let content = column![title, input] + .spacing(20); + //.max_width(800); + + scrollable( + container(content).center_x(Length::Fill).padding(40), + ).into() } pub fn subscription(&self) -> Subscription { diff --git a/client/src/main.rs b/client/src/main.rs index cdb6eea..b2b3beb 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -2,7 +2,6 @@ use realm_client::RealmApp; pub fn main() -> iced::Result { tracing_subscriber::fmt::init(); - iced::program(RealmApp::title, RealmApp::update, RealmApp::view) .load(RealmApp::load) .subscription(RealmApp::subscription)