2020-03-30 14:26:25 +02:00
|
|
|
use seed::fetch::FetchObject;
|
2020-03-30 08:16:26 +02:00
|
|
|
use seed::{prelude::*, *};
|
2020-03-27 12:17:27 +01:00
|
|
|
|
2020-03-30 23:19:00 +02:00
|
|
|
use crate::model::Page;
|
|
|
|
|
2020-03-30 14:26:25 +02:00
|
|
|
mod api;
|
|
|
|
mod login;
|
2020-03-30 08:16:26 +02:00
|
|
|
mod model;
|
2020-03-30 14:26:25 +02:00
|
|
|
mod project;
|
|
|
|
mod project_settings;
|
|
|
|
mod register;
|
|
|
|
mod shared;
|
2020-03-30 08:16:26 +02:00
|
|
|
|
2020-03-30 14:26:25 +02:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub enum Msg {
|
|
|
|
ChangePage(model::Page),
|
|
|
|
CurrentProjectResult(FetchObject<String>),
|
|
|
|
CurrentUserResult(FetchObject<String>),
|
|
|
|
InternalFailure(String),
|
2020-03-30 23:19:00 +02:00
|
|
|
ToggleAboutTooltip,
|
2020-03-31 08:56:46 +02:00
|
|
|
|
|
|
|
// project
|
|
|
|
ProjectTextFilterChanged(String),
|
2020-03-29 19:56:55 +02:00
|
|
|
}
|
|
|
|
|
2020-03-30 14:26:25 +02:00
|
|
|
fn update(msg: Msg, model: &mut model::Model, orders: &mut impl Orders<Msg>) {
|
|
|
|
if cfg!(debug_assertions) {
|
|
|
|
log!(msg);
|
|
|
|
}
|
2020-03-30 08:16:26 +02:00
|
|
|
match msg {
|
2020-03-30 14:26:25 +02:00
|
|
|
Msg::ChangePage(page) => {
|
|
|
|
model.page = page;
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
crate::shared::update(&msg, model, orders);
|
|
|
|
match model.page {
|
|
|
|
Page::Project => project::update(msg, model, orders),
|
|
|
|
Page::ProjectSettings => project_settings::update(msg, model, orders),
|
|
|
|
Page::Login => login::update(msg, model, orders),
|
|
|
|
Page::Register => register::update(msg, model, orders),
|
|
|
|
}
|
|
|
|
if cfg!(debug_assertions) {
|
|
|
|
log!(model);
|
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 14:26:25 +02:00
|
|
|
fn view(model: &model::Model) -> Node<Msg> {
|
|
|
|
match model.page {
|
|
|
|
Page::Project => project::view(model),
|
|
|
|
Page::ProjectSettings => project_settings::view(model),
|
|
|
|
Page::Login => login::view(model),
|
|
|
|
Page::Register => register::view(model),
|
|
|
|
}
|
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 routes(url: Url) -> Option<Msg> {
|
|
|
|
if url.path.is_empty() {
|
2020-03-30 14:26:25 +02:00
|
|
|
return Some(Msg::ChangePage(model::Page::Project));
|
2020-03-30 08:16:26 +02:00
|
|
|
}
|
2020-03-29 19:56:55 +02:00
|
|
|
|
2020-03-30 08:16:26 +02:00
|
|
|
match url.path[0].as_ref() {
|
2020-03-30 14:26:25 +02:00
|
|
|
"board" => Some(Msg::ChangePage(model::Page::Project)),
|
|
|
|
"project-settings" => Some(Msg::ChangePage(model::Page::ProjectSettings)),
|
|
|
|
"login" => Some(Msg::ChangePage(model::Page::Login)),
|
|
|
|
"register" => Some(Msg::ChangePage(model::Page::Register)),
|
|
|
|
_ => Some(Msg::ChangePage(model::Page::Project)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub static mut HOST_URL: String = String::new();
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
pub fn set_host_url(url: String) {
|
|
|
|
unsafe {
|
|
|
|
HOST_URL = url;
|
2020-03-29 19:56:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-30 14:26:25 +02:00
|
|
|
#[wasm_bindgen]
|
2020-03-30 08:16:26 +02:00
|
|
|
pub fn render() {
|
|
|
|
App::builder(update, view).routes(routes).build_and_start();
|
2020-03-29 19:56:55 +02:00
|
|
|
}
|