use seed::{prelude::*, *}; use wasm_bindgen::JsCast; use jirs_data::Issue; use crate::model::{Icon, Model}; use crate::{IssueId, Msg}; pub mod aside; pub mod modal; pub mod navbar_left; pub mod styled_avatar; pub mod styled_button; pub mod styled_input; pub mod styled_select; pub mod styled_tooltip; pub fn find_issue(model: &Model, issue_id: IssueId) -> Option<&Issue> { match model.project.as_ref() { Some(p) => p.issues.iter().find(|issue| issue.id == issue_id), _ => None, } } pub trait ToNode { fn into_node(self) -> Node; } pub fn styled_icon(icon: Icon) -> Node { let style = icon .to_color() .map(|s| format!("color: {}", s)) .unwrap_or_default(); i![ attrs![At::Class => format!("styledIcon {}", icon), At::Style => style], "" ] } pub fn divider() -> Node { div![attrs![At::Class => "divider"], ""] } pub fn inner_layout( model: &Model, page_name: &str, children: Vec>, modal_node: Node, ) -> Node { article![ modal_node, attrs![At::Class => "inner-layout"], id![page_name], navbar_left::render(model), aside::render(model), children, ] } pub fn host_client(host_url: String, path: &str) -> Result { let url = format!("{}{}", host_url, path); let w = window(); let store = match w.local_storage() { Ok(Some(store)) => store, _ => return Err("Local storage is not available".to_string()), }; let token = match store.get_item("authToken") { Ok(Some(s)) => s, _ => "".to_string(), }; Ok(Request::new(url).header("Authorization", format!("Bearer {}", token).as_str())) } pub fn update(msg: &Msg, model: &mut crate::model::Model, _orders: &mut impl Orders) { match msg { Msg::CurrentProjectResult(fetched) => { crate::api_handlers::current_project_response(fetched, model); } Msg::CurrentUserResult(fetched) => { crate::api_handlers::current_user_response(fetched, model); } _ => (), } } pub fn drag_ev( trigger: impl Into, handler: impl FnOnce(web_sys::DragEvent) -> Ms + 'static + Clone, ) -> EventHandler { let closure_handler = move |event: web_sys::Event| { (handler.clone())(event.dyn_ref::().unwrap().clone()) }; EventHandler::new(trigger, closure_handler) }