Component settings
This commit is contained in:
@@ -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"
|
||||
|
||||
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 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,
|
||||
|
||||
@@ -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::<App>::new().render();
|
||||
}
|
||||
|
||||
@@ -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! {
|
||||
<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 }}"/>
|
||||
impl Component for Settings {
|
||||
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! {
|
||||
<div class="content">
|
||||
<h2>{"Settings"}</h2>
|
||||
<form onsubmit={ctx.link().callback(|e: SubmitEvent| {
|
||||
e.prevent_default();
|
||||
Msg::Submit
|
||||
})}>
|
||||
<div class="option">
|
||||
<label for="cslol_dir">{"Location of CSLoL"}</label>
|
||||
<br/>
|
||||
<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 class="option">
|
||||
<label for="wad_dir">{"Custom location of Champion Wads"}</label>
|
||||
<br/>
|
||||
<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 class="option">
|
||||
<label for="extract_dir">{"Custom location to Extract to"}</label>
|
||||
<br/>
|
||||
<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 class="option">
|
||||
<button type="submit">{"Save Settings"}</button>
|
||||
</div>
|
||||
</form>
|
||||
</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>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// #[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