From 23c6cd1a8ce292a442ef8c2928b7ab85cc8dcb2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Wo=C5=BAniak?= Date: Fri, 15 Jan 2021 22:57:26 +0100 Subject: [PATCH] Remove unused code --- README.md | 2 + jirs-client/src/elements.rs | 288 ------------------ jirs-client/src/lib.rs | 7 - .../modals/issue_statuses_delete/update.rs | 7 +- 4 files changed, 4 insertions(+), 300 deletions(-) delete mode 100644 jirs-client/src/elements.rs diff --git a/README.md b/README.md index c90c220e..f0d595a2 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,8 @@ https://git.sr.ht/~tsumanu/jirs * Handle upload avatar with stream * Move config to `./config` directory * Fix S3 upload with upgraded version of `rusoto` +* Remove Custom Elements +* Replace CSS with SCSS ##### Work Progress diff --git a/jirs-client/src/elements.rs b/jirs-client/src/elements.rs deleted file mode 100644 index 195b2718..00000000 --- a/jirs-client/src/elements.rs +++ /dev/null @@ -1,288 +0,0 @@ -// use syntect::easy::HighlightLines; -// use syntect::highlighting::{FontStyle, Style}; -// use syntect::parsing::SyntaxReference; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen(final, js_name = JirsCodeBuilder)] -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct JirsCodeBuilder {} - -#[wasm_bindgen] -impl JirsCodeBuilder { - #[wasm_bindgen(constructor)] - pub fn new() -> Self { - Self {} - } - - #[wasm_bindgen] - pub fn hi_code(&mut self, _lang: &str, code: &str) -> String { - // let syntax = { - // match crate::hi::syntax_set::load().find_syntax_by_name(lang) { - // Some(s) => s.clone(), - // _ => { - // return code.to_string(); - // } - // } - // }; - // let mut buffer: Vec = Vec::with_capacity(code.lines().count() * 2); - // for line in code.lines() { - // self.hi(&syntax, line, &mut buffer); - // buffer.push("
".to_string()); - // } - // buffer.join("") - code.to_string() - } - - // fn hi<'l>(&mut self, syntax: &SyntaxReference, line: &'l str, buffer: &mut Vec) { - // let mut h = HighlightLines::new(syntax, &crate::hi::THEME_SET.themes["base16-ocean-dark"]); // inspired-github - // let tokens = { h.highlight(line, &crate::hi::syntax_set::load()) }; - // - // for (style, token) in tokens.into_iter() { - // let Style { - // foreground: f, - // background: b, - // font_style, - // } = style; - // let fs = if font_style == FontStyle::BOLD { - // "font-weight: bold" - // } else if font_style == FontStyle::ITALIC { - // "font-style: italic" - // } else if font_style == FontStyle::UNDERLINE { - // "text-decoration: underline" - // } else { - // "" - // }; - // - // buffer.push(format!( - // r#"{t}"#, - // t = if token.is_empty() { " " } else { token }, - // f_r = f.r, f_g = f.g, f_b = f.b, f_a = f.a, b_r = b.r, b_g = b.g, b_b = b.b, b_a = b.a, - // fs = fs - // )); - // } - // } -} - -pub fn define() { - { - let el_name = "JirsCodeView"; - let tag = "jirs-code-view"; - - ElementBuilder::default() - .identifier(el_name, tag) - .runtime("JirsCodeBuilder") - .body( - r#" - -
-
- "#, - ) - .on_connected(FillShadowElement::new(el_name, "#view", "")) - .on_connected( - r#" - const lang = this.getAttribute('lang') || ''; - setTimeout(() => {{ - const code = (this.innerHTML || '').trim(); - console.log('connected'); - shadow.querySelector('#view').innerHTML = runtime.hi_code(lang, code); - }}, 1); - "#, - ) - .on_attr_changed("lang", r#""#) - .on_attr_changed( - "file-path", - r#" - shadow.querySelector('#file-name').innerText = newV; - "#, - ) - .mount(); - }; -} - -trait ToJs { - fn to_js(&self) -> String; -} - -impl ToJs for &str { - fn to_js(&self) -> String { - self.to_string() - } -} - -struct FillShadowElement { - el_name: String, - target: String, - source: String, -} - -impl FillShadowElement { - pub fn new, S: Into, Source: ToJs>( - el_name: N, - target: S, - source: Source, - ) -> Self { - Self { - el_name: el_name.into(), - target: target.into(), - source: source.to_js(), - } - } -} - -impl ToJs for FillShadowElement { - fn to_js(&self) -> String { - let shadow = ElementBuilder::shadow_handle(&self.el_name); - format!( - "{shadow}.querySelector('{selector}').innerHTML = `{content}`;", - shadow = shadow, - selector = self.target, - content = self.source - ) - } -} - -#[derive(Default)] -struct ElementBuilder { - name: String, - tag: String, - body: String, - runtime: String, - on_connected: Vec, - on_attr_changed: std::collections::HashMap>, -} - -impl ToJs for ElementBuilder { - fn to_js(&self) -> String { - let shadow = Self::shadow_handle(&self.name); - let runtime = Self::runtime_handle(&self.name); - let (observe, attr_body) = if self.on_attr_changed.is_empty() { - ("".to_string(), "".to_string()) - } else { - let observe = self - .on_attr_changed - .keys() - .map(|s| format!("'{}'", s)) - .collect::>() - .join(","); - let mut on_changed = "switch (name) {".to_string(); - for (k, v) in self.on_attr_changed.iter() { - let body = v.join(";"); - on_changed.push_str( - format!("case '{attr}': {{ {body}; break; }}", attr = k, body = body).as_str(), - ); - } - on_changed.push_str("}"); - - ( - format!( - "static get observedAttributes() {{ return [{}]; }}", - observe - ), - on_changed, - ) - }; - let on_connected: String = self.on_connected.join(";"); - - format!( - r#" - class {name} extends HTMLElement {{ - static RUNTIME = Symbol(); - static SHADOW = Symbol(); - - {observe} - - constructor() {{ - super(); - {shadow} = this.attachShadow({{ 'mode': 'closed' }}); - {shadow}.innerHTML = `{html}`; - }} - - connectedCallback() {{ - const runtime = {runtime} = new JirsCodeBuilder(); - const shadow = {shadow}; - - {on_connected} - }} - - disconnectedCallback() {{ - {runtime}.free(); - }} - - attributeChangedCallback(name, oldV, newV) {{ - const runtime = {runtime}; - const shadow = {shadow}; - {attr_body} - }} - }} - customElements.define( '{tag}', {name}); - "#, - name = self.name, - tag = self.tag, - html = self.body, - shadow = shadow, - runtime = runtime, - observe = observe, - attr_body = attr_body, - on_connected = on_connected, - ) - } -} - -impl ElementBuilder { - pub fn identifier, T: Into>(mut self, name: N, tag: T) -> Self { - self.name = name.into(); - self.tag = tag.into(); - self - } - - pub fn runtime>(mut self, runtime: S) -> Self { - self.runtime = runtime.into(); - self - } - - pub fn body>(mut self, body: S) -> Self { - self.body = body.into(); - self - } - - pub fn on_connected(mut self, c: B) -> Self { - self.on_connected.push(c.to_js()); - self - } - - pub fn on_attr_changed, R: Into>(mut self, attr: N, run: R) -> Self { - let a = attr.into(); - let r = run.into(); - self.on_attr_changed - .entry(a) - .or_insert_with(|| vec![]) - .push(r); - self - } - - pub fn shadow_handle(name: &str) -> String { - format!("this[ {name} . SHADOW]", name = name) - } - - pub fn runtime_handle(name: &str) -> String { - format!("this[ {name} . RUNTIME]", name = name) - } - - pub fn mount(&self) { - let source = self.to_js(); - { - // use seed::*; - // log!(source); - } - use seed::*; - match js_sys::eval(source.as_str()) { - Ok(_v) => (), - Err(e) => error!(e), - }; - } -} diff --git a/jirs-client/src/lib.rs b/jirs-client/src/lib.rs index ab68ecfa..7f0e4ef0 100644 --- a/jirs-client/src/lib.rs +++ b/jirs-client/src/lib.rs @@ -21,7 +21,6 @@ pub use {changes::*, fields::*, images::*}; // use crate::shared::styled_rte::RteMsg; mod changes; -pub mod elements; mod fields; mod images; mod modal; @@ -302,7 +301,6 @@ pub fn render(host_url: String, ws_url: String) { HOST_URL = host_url; WS_URL = ws_url; } - elements::define(); let app = seed::App::start("app", init, update, view); @@ -347,11 +345,6 @@ fn init(url: Url, orders: &mut impl Orders) -> Model { model.page = resolve_page(url).unwrap_or(Page::Project); open_socket(&mut model, orders); - // orders.subscribe(|subs::UrlChanged(url)| { - // if let Some(page) = resolve_page(url) { - // orders.send_msg(Msg::ChangePage(page)); - // } - // }); model } diff --git a/jirs-client/src/modals/issue_statuses_delete/update.rs b/jirs-client/src/modals/issue_statuses_delete/update.rs index 8ab85fd6..ff5347c3 100644 --- a/jirs-client/src/modals/issue_statuses_delete/update.rs +++ b/jirs-client/src/modals/issue_statuses_delete/update.rs @@ -2,7 +2,7 @@ use { crate::{ modals::issue_statuses_delete::Model as DeleteIssueStatusModal, model::{ModalType, Model}, - Msg, WebSocketChanged, + Msg, OperationKind, ResourceKind, }, jirs_data::WsMsg, seed::prelude::*, @@ -26,10 +26,7 @@ pub fn update(msg: &Msg, model: &mut Model, orders: &mut impl Orders) { orders, ); } - Msg::WebSocketChange(WebSocketChanged::WsMsg(WsMsg::IssueStatusDeleted( - _id, - _n_deleted, - ))) => { + Msg::ResourceChanged(ResourceKind::IssueStatus, OperationKind::SingleRemoved, Some(_)) => { orders.skip().send_msg(Msg::ModalDropped); } _ => (),