Component settings
This commit is contained in:
@@ -7,9 +7,11 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
yew = { version = "0.21", features = ["csr"] }
|
yew = { version = "0.21", features = ["csr"] }
|
||||||
yew-router = "0.18"
|
yew-router = "0.18"
|
||||||
|
walkdir = "2.3.2"
|
||||||
wasm-bindgen = "0.2"
|
wasm-bindgen = "0.2"
|
||||||
wasm-bindgen-futures = "0.4"
|
wasm-bindgen-futures = "0.4"
|
||||||
web-sys = "0.3"
|
web-sys = "0.3"
|
||||||
|
toml = "0.5"
|
||||||
js-sys = "0.3"
|
js-sys = "0.3"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde-wasm-bindgen = "0.6"
|
serde-wasm-bindgen = "0.6"
|
||||||
|
|||||||
3
config.toml
Normal file
3
config.toml
Normal file
@@ -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 = ""
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use rocket::config;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, FromForm)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub cslol_dir: String,
|
pub cslol_dir: String,
|
||||||
pub wad_dir: String,
|
pub wad_dir: String,
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
mod app;
|
mod app;
|
||||||
mod views;
|
mod views;
|
||||||
|
mod extractor;
|
||||||
|
mod config_settings;
|
||||||
|
|
||||||
use app::App;
|
use app::App;
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
console_error_panic_hook::set_once();
|
console_error_panic_hook::set_once();
|
||||||
yew::Renderer::<App>::new().render();
|
yew::Renderer::<App>::new().render();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,116 @@
|
|||||||
|
use web_sys::HtmlInputElement;
|
||||||
use yew::prelude::*;
|
use yew::prelude::*;
|
||||||
|
use crate::config_settings::*;
|
||||||
|
pub enum Msg {
|
||||||
|
UpdateCSLoLDir(String),
|
||||||
|
UpdateWadDir(String),
|
||||||
|
UpdateExtractDir(String),
|
||||||
|
Submit,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type Settings = Config;
|
||||||
|
|
||||||
|
|
||||||
#[function_component(Settings)]
|
impl Component for Settings {
|
||||||
pub fn settings() -> Html {
|
type Message = Msg;
|
||||||
|
type Properties = ();
|
||||||
|
|
||||||
|
fn create(_ctx: &Context<Self>) -> Self {
|
||||||
|
init_config();
|
||||||
|
load_config()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self, _ctx: &Context<Self>, 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<Self>) -> Html {
|
||||||
html! {
|
html! {
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h2>{"Settings"}</h2>
|
<h2>{"Settings"}</h2>
|
||||||
<form action="/write-settings" method="post">
|
<form onsubmit={ctx.link().callback(|e: SubmitEvent| {
|
||||||
|
e.prevent_default();
|
||||||
|
Msg::Submit
|
||||||
|
})}>
|
||||||
<div class="option">
|
<div class="option">
|
||||||
<label for="cslol_dir">{"Location of CSLoL"}</label>
|
<label for="cslol_dir">{"Location of CSLoL"}</label>
|
||||||
<br/>
|
<br/>
|
||||||
<input type="text" name="cslol_dir" id="cslol_dir" value="{{ config.cslol_dir }}"/>
|
<input type="text"
|
||||||
|
id="cslol_dir"
|
||||||
|
oninput={ctx.link().callback(|e: InputEvent| Msg::UpdateCSLoLDir(e.target_unchecked_into::<HtmlInputElement>().value()))}
|
||||||
|
value={self.cslol_dir.clone()} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="option">
|
<div class="option">
|
||||||
<label for="wad_dir">{"Custom location of Champion Wads"}</label>
|
<label for="wad_dir">{"Custom location of Champion Wads"}</label>
|
||||||
<br/>
|
<br/>
|
||||||
<input type="text" name="wad_dir" id="wad_dir" value="{{ config.wad_dir }}"/>
|
<input type="text"
|
||||||
|
id="wad_dir"
|
||||||
|
oninput={ctx.link().callback(|e: InputEvent| Msg::UpdateWadDir(e.target_unchecked_into::<HtmlInputElement>().value()))}
|
||||||
|
value={self.wad_dir.clone()} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="option">
|
<div class="option">
|
||||||
<label for="extract_dir">{"Custom location to Extract to"}</label>
|
<label for="extract_dir">{"Custom location to Extract to"}</label>
|
||||||
<br/>
|
<br/>
|
||||||
<input type="text" name="extract_dir" id="extract_dir" value="{{ config.extract_dir }}"/>
|
<input type="text"
|
||||||
|
id="extract_dir"
|
||||||
|
oninput={ctx.link().callback(|e: InputEvent| Msg::UpdateExtractDir(e.target_unchecked_into::<HtmlInputElement>().value()))}
|
||||||
|
value={self.extract_dir.clone()} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="option">
|
<div class="option">
|
||||||
<button type="submit">{"Save Settings"}</button>
|
<button type="submit">{"Save Settings"}</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #[function_component(Settings)]
|
||||||
|
// pub fn settings() -> Html {
|
||||||
|
// html! {
|
||||||
|
// <div class="content">
|
||||||
|
// <h2>{"Settings"}</h2>
|
||||||
|
// <form action="/write-settings" method="post">
|
||||||
|
// <div class="option">
|
||||||
|
// <label for="cslol_dir">{"Location of CSLoL"}</label>
|
||||||
|
// <br/>
|
||||||
|
// <input type="text" name="cslol_dir" id="cslol_dir" value="{{ config.cslol_dir }}"/>
|
||||||
|
// </div>
|
||||||
|
|
||||||
|
// <div class="option">
|
||||||
|
// <label for="wad_dir">{"Custom location of Champion Wads"}</label>
|
||||||
|
// <br/>
|
||||||
|
// <input type="text" name="wad_dir" id="wad_dir" value="{{ config.wad_dir }}"/>
|
||||||
|
// </div>
|
||||||
|
|
||||||
|
// <div class="option">
|
||||||
|
// <label for="extract_dir">{"Custom location to Extract to"}</label>
|
||||||
|
// <br/>
|
||||||
|
// <input type="text" name="extract_dir" id="extract_dir" value="{{ config.extract_dir }}"/>
|
||||||
|
// </div>
|
||||||
|
|
||||||
|
// <div class="option">
|
||||||
|
// <button type="submit">{"Save Settings"}</button>
|
||||||
|
// </div>
|
||||||
|
// </form>
|
||||||
|
// </div>
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|||||||
Reference in New Issue
Block a user