2020-03-30 08:16:26 +02:00
|
|
|
use seed::{prelude::*, *};
|
2020-03-27 12:17:27 +01:00
|
|
|
|
2020-03-30 08:16:26 +02:00
|
|
|
mod model;
|
|
|
|
|
|
|
|
type Model = i32;
|
2020-03-29 19:56:55 +02:00
|
|
|
|
|
|
|
enum Msg {
|
2020-03-30 08:16:26 +02:00
|
|
|
Increment,
|
|
|
|
ChangeGuidePage(i32),
|
|
|
|
ChangePage(i32),
|
2020-03-29 19:56:55 +02:00
|
|
|
}
|
|
|
|
|
2020-03-30 08:16:26 +02:00
|
|
|
fn update(msg: Msg, model: &mut Model, _: &mut impl Orders<Msg>) {
|
|
|
|
match msg {
|
|
|
|
Msg::Increment => *model += 1,
|
2020-03-29 19:56:55 +02:00
|
|
|
}
|
2020-03-30 08:16:26 +02:00
|
|
|
}
|
2020-03-29 19:56:55 +02:00
|
|
|
|
2020-03-30 08:16:26 +02:00
|
|
|
fn view(model: &Model) -> Node<Msg> {
|
|
|
|
div![
|
|
|
|
"This is a counter: ",
|
|
|
|
class!["counter"],
|
|
|
|
button![model.to_string(), ev(Ev::Click, |_| Msg::Increment),],
|
|
|
|
]
|
|
|
|
}
|
2020-03-29 19:56:55 +02:00
|
|
|
|
2020-03-30 08:16:26 +02:00
|
|
|
fn routes(url: Url) -> Option<Msg> {
|
|
|
|
if url.path.is_empty() {
|
|
|
|
return Some(Msg::ChangePage(0));
|
|
|
|
}
|
2020-03-29 19:56:55 +02:00
|
|
|
|
2020-03-30 08:16:26 +02:00
|
|
|
match url.path[0].as_ref() {
|
|
|
|
"guide" => match url.path.get(1).as_ref() {
|
|
|
|
Some(page) => Some(Msg::ChangeGuidePage(page.parse::<usize>().unwrap())),
|
|
|
|
None => Some(Msg::ChangePage(0)),
|
|
|
|
},
|
|
|
|
"changelog" => Some(Msg::ChangePage(1)),
|
|
|
|
_ => Some(Msg::ChangePage(0)),
|
2020-03-29 19:56:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-30 08:16:26 +02:00
|
|
|
#[wasm_bindgen(start)]
|
|
|
|
pub fn render() {
|
|
|
|
App::builder(update, view).routes(routes).build_and_start();
|
2020-03-29 19:56:55 +02:00
|
|
|
}
|