Commit 55351af6ac385d486bac480ea5fa0fb2420b51ce

Authored by Georg Hopp
1 parent 42dd5add

Add and rewire actions

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