39 lines
1006 B
Rust
39 lines
1006 B
Rust
|
mod model;
|
||
|
mod pages;
|
||
|
|
||
|
use model::Model;
|
||
|
use seed::empty;
|
||
|
use seed::prelude::*;
|
||
|
|
||
|
use crate::pages::{Msg, Page, PublicPage};
|
||
|
|
||
|
fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
|
||
|
Model {
|
||
|
token: LocalStorage::get("auth-token").ok(),
|
||
|
page: Page::Public(PublicPage::Listing(pages::public::listing::init(
|
||
|
url,
|
||
|
&mut orders.proxy(|msg| Msg::Public(pages::public::Msg::Listing(msg))),
|
||
|
))),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||
|
match msg {
|
||
|
Msg::UrlChanged(subs::UrlChanged(url)) => model.page = Page::init(url, orders),
|
||
|
Msg::Public(_) => {}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn view(model: &Model) -> Node<Msg> {
|
||
|
match &model.page {
|
||
|
Page::Public(PublicPage::Listing(page)) => pages::public::listing::view(&page)
|
||
|
.map_msg(|msg| Msg::Public(pages::public::Msg::Listing(msg))),
|
||
|
_ => empty![],
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[wasm_bindgen(start)]
|
||
|
pub fn start() {
|
||
|
App::start("main", init, update, view);
|
||
|
}
|