Showing
2 changed files
with
25 additions
and
7 deletions
No preview for this file type
| ... | ... | @@ -5,7 +5,7 @@ use data::icons::*; |
| 5 | 5 | use js_sys::JsString; |
| 6 | 6 | use log::Level; |
| 7 | 7 | use mogwai::prelude::*; |
| 8 | -use web_sys::{RequestInit, RequestMode, Request, Response, MouseEvent}; | |
| 8 | +use web_sys::{RequestInit, RequestMode, Request, Response}; | |
| 9 | 9 | use std::panic; |
| 10 | 10 | use wasm_bindgen::prelude::*; |
| 11 | 11 | |
| ... | ... | @@ -14,6 +14,8 @@ enum AppLogic { |
| 14 | 14 | Update, |
| 15 | 15 | Toggle, |
| 16 | 16 | Store, |
| 17 | + Select(Option<i32>), | |
| 18 | + Discard, | |
| 17 | 19 | } |
| 18 | 20 | |
| 19 | 21 | fn md_to_html(source: &str) -> String { |
| ... | ... | @@ -167,6 +169,15 @@ async fn editor_logic( mut rx_logic: broadcast::Receiver<AppLogic> |
| 167 | 169 | . await.unwrap(), |
| 168 | 170 | }; |
| 169 | 171 | }, |
| 172 | + AppLogic::Discard => { | |
| 173 | + set_md(md.content.as_str()); | |
| 174 | + update(); | |
| 175 | + }, | |
| 176 | + AppLogic::Select(id) => { | |
| 177 | + md = md_from_db(id).await; | |
| 178 | + set_md(md.content.as_str()); | |
| 179 | + update(); | |
| 180 | + }, | |
| 170 | 181 | } |
| 171 | 182 | } |
| 172 | 183 | } |
| ... | ... | @@ -176,13 +187,13 @@ fn editor_view( tx_logic: broadcast::Sender<AppLogic> |
| 176 | 187 | , tx_dom: broadcast::Sender<Dom> |
| 177 | 188 | ) -> ViewBuilder<Dom> |
| 178 | 189 | { |
| 179 | - let ns = "http://www.w3.org/2000/svg"; | |
| 180 | - | |
| 181 | 190 | let input_filter = tx_logic |
| 182 | 191 | . sink() |
| 183 | 192 | . contra_map(|_| AppLogic::Update); |
| 184 | 193 | let store_filter = tx_logic |
| 185 | 194 | . sink() |
| 195 | + . contra_map(|_| AppLogic::Store); | |
| 196 | + /* keep as example how to handle concrete events. == | |
| 186 | 197 | . contra_filter_map(|e :DomEvent| { |
| 187 | 198 | if let Either::Left(e) = e.clone_inner() { |
| 188 | 199 | let e = e.dyn_into::<MouseEvent>().unwrap(); |
| ... | ... | @@ -194,9 +205,16 @@ fn editor_view( tx_logic: broadcast::Sender<AppLogic> |
| 194 | 205 | None |
| 195 | 206 | } |
| 196 | 207 | }); |
| 208 | + == */ | |
| 197 | 209 | let toggle_filter = tx_logic |
| 198 | 210 | . sink() |
| 199 | 211 | . contra_map(|_| AppLogic::Toggle); |
| 212 | + let select_filter = tx_logic | |
| 213 | + . sink() | |
| 214 | + . contra_map(|_e| AppLogic::Select(None)); | |
| 215 | + let discard_filter = tx_logic | |
| 216 | + . sink() | |
| 217 | + . contra_map(|_| AppLogic::Discard); | |
| 200 | 218 | |
| 201 | 219 | builder! { |
| 202 | 220 | <div class="input" |
| ... | ... | @@ -206,13 +224,13 @@ fn editor_view( tx_logic: broadcast::Sender<AppLogic> |
| 206 | 224 | <div contenteditable="true" |
| 207 | 225 | style:cursor="text" |
| 208 | 226 | style:display=("none", rx_view)> |
| 209 | - <pre on:click=store_filter></pre> | |
| 227 | + <pre></pre> | |
| 210 | 228 | </div> |
| 211 | 229 | <div> |
| 212 | 230 | <div> |
| 213 | - <button>{select_icon()}</button> | |
| 214 | - <button>{save_icon()}</button> | |
| 215 | - <button>{discard_icon()}</button> | |
| 231 | + <button on:click=select_filter>{select_icon()}</button> | |
| 232 | + <button on:click=store_filter>{save_icon()}</button> | |
| 233 | + <button on:click=discard_filter>{discard_icon()}</button> | |
| 216 | 234 | <button on:click=toggle_filter>{edit_icon()}</button> |
| 217 | 235 | </div> |
| 218 | 236 | <div></div> | ... | ... |
Please
register
or
login
to post a comment