From c60c8fee4b435273c1c5bb9eab383f842024f666 Mon Sep 17 00:00:00 2001 From: poslop Date: Tue, 4 Jun 2024 19:31:45 -0500 Subject: [PATCH] Component settings --- Cargo.toml | 2 + config.toml | 3 + src/app.rs | 2 +- src/config_settings.rs | 3 +- src/main.rs | 4 +- src/views/settings.rs | 134 +++++++++++++++++++++++++++++++++-------- 6 files changed, 118 insertions(+), 30 deletions(-) create mode 100644 config.toml diff --git a/Cargo.toml b/Cargo.toml index 1fa9c00..00a8a77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,9 +7,11 @@ edition = "2021" [dependencies] yew = { version = "0.21", features = ["csr"] } yew-router = "0.18" +walkdir = "2.3.2" wasm-bindgen = "0.2" wasm-bindgen-futures = "0.4" web-sys = "0.3" +toml = "0.5" js-sys = "0.3" serde = { version = "1", features = ["derive"] } serde-wasm-bindgen = "0.6" diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..1752b44 --- /dev/null +++ b/config.toml @@ -0,0 +1,3 @@ +cslol_dir = "C:\\Users\\poslop\\Games\\lol\\cslol-manager" +wad_dir = "C:\\Riot Games\\League of Legends\\Game\\DATA\\FINAL\\Champions" +extract_dir = "" diff --git a/src/app.rs b/src/app.rs index 77d2312..731dec4 100644 --- a/src/app.rs +++ b/src/app.rs @@ -25,7 +25,7 @@ pub enum Route { #[function_component(App)] -pub fn app() -> Html { +pub fn app() -> Html { html! { diff --git a/src/config_settings.rs b/src/config_settings.rs index dc1dc27..60c27df 100644 --- a/src/config_settings.rs +++ b/src/config_settings.rs @@ -1,8 +1,7 @@ use std::fs; -use rocket::config; use serde::{Deserialize, Serialize}; -#[derive(Debug, Deserialize, Serialize, FromForm)] +#[derive(Debug, Deserialize, Serialize)] pub struct Config { pub cslol_dir: String, pub wad_dir: String, diff --git a/src/main.rs b/src/main.rs index a15bbb5..f0a7826 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,12 @@ mod app; mod views; +mod extractor; +mod config_settings; use app::App; - fn main() { + console_error_panic_hook::set_once(); yew::Renderer::::new().render(); } diff --git a/src/views/settings.rs b/src/views/settings.rs index 72d7e5a..9a0732e 100644 --- a/src/views/settings.rs +++ b/src/views/settings.rs @@ -1,34 +1,116 @@ +use web_sys::HtmlInputElement; use yew::prelude::*; +use crate::config_settings::*; +pub enum Msg { + UpdateCSLoLDir(String), + UpdateWadDir(String), + UpdateExtractDir(String), + Submit, +} + +pub type Settings = Config; -#[function_component(Settings)] -pub fn settings() -> Html { - html! { -
-

{"Settings"}

-
-
- -
- -
+impl Component for Settings { + type Message = Msg; + type Properties = (); -
- -
- -
- -
- -
- -
+ fn create(_ctx: &Context) -> Self { + init_config(); + load_config() + } -
- + fn update(&mut self, _ctx: &Context, msg: Self::Message) -> bool { + match msg { + Msg::UpdateCSLoLDir(value) => { + self.cslol_dir = value; + true + }, + Msg::UpdateWadDir(value) => { + self.wad_dir = value; + true + }, + Msg::UpdateExtractDir(value) => { + self.extract_dir = value; + true + }, + Msg::Submit => { + write_config(&self); + false + } + } + } + + fn view(&self, ctx: &Context) -> Html { + html! { +
+

{"Settings"}

+ +
+ +
+ ().value()))} + value={self.cslol_dir.clone()} /> +
+
+ +
+ ().value()))} + value={self.wad_dir.clone()} /> +
+
+ +
+ ().value()))} + value={self.extract_dir.clone()} /> +
+
+ +
+
- -
+ } } } + + +// #[function_component(Settings)] +// pub fn settings() -> Html { +// html! { +//
+//

{"Settings"}

+//
+//
+// +//
+// +//
+ +//
+// +//
+// +//
+ +//
+// +//
+// +//
+ +//
+// +//
+//
+//
+// } +// }