Component settings
This commit is contained in:
@@ -25,7 +25,7 @@ pub enum Route {
|
||||
|
||||
|
||||
#[function_component(App)]
|
||||
pub fn app() -> Html {
|
||||
pub fn app() -> Html {
|
||||
html! {
|
||||
<BrowserRouter>
|
||||
<nav::Nav/>
|
||||
|
||||
@@ -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 }}"/>
|
||||
</div>
|
||||
impl Component for Settings {
|
||||
type Message = Msg;
|
||||
type Properties = ();
|
||||
|
||||
<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>
|
||||
fn create(_ctx: &Context<Self>) -> Self {
|
||||
init_config();
|
||||
load_config()
|
||||
}
|
||||
|
||||
<div class="option">
|
||||
<button type="submit">{"Save Settings"}</button>
|
||||
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>
|
||||
</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