view.rs
3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use mogwai::prelude::*;
use crate::data::icons::*;
use super::logic::MarkdownLogic;
pub(super) fn markdown_view( tx_logic: broadcast::Sender<MarkdownLogic>
, rx_toggle: broadcast::Receiver<bool>
, rx_patches: mpmc::Receiver<ListPatch<ViewBuilder<Dom>>>
, tx_dom: broadcast::Sender<Dom>
) -> ViewBuilder<Dom>
{
let input_filter = tx_logic
. sink()
. contra_map(|_| MarkdownLogic::Update);
let store_filter = tx_logic
. sink()
. contra_map(|_| MarkdownLogic::Store);
let toggle_filter = tx_logic
. sink()
. contra_map(|_| MarkdownLogic::Toggle);
let select_filter = tx_logic
. sink()
. contra_map(|_e| MarkdownLogic::Select);
let discard_filter = tx_logic
. sink()
. contra_map(|_| MarkdownLogic::Discard);
let (tx_toggle_editor, rx_toggle_editor) = broadcast::bounded(1);
let ( tx_toggle_top_padding
, rx_toggle_top_padding) = broadcast::bounded(1);
/*
* This takes a bool toggle value and turns it into various view changes
* by filling internal channels accordingly...
* Is that the way to go?
*/
mogwai::spawn( rx_toggle
. for_each(move |toggle| {
let tx_toggle_editor = tx_toggle_editor.clone();
let tx_toggle_top_padding = tx_toggle_top_padding.clone();
async move {
match toggle {
true => {
tx_toggle_editor . broadcast(String::from("block"))
. await.unwrap();
tx_toggle_top_padding . broadcast(String::from("13em"))
. await.unwrap();
},
false => {
tx_toggle_editor . broadcast(String::from("none"))
. await.unwrap();
tx_toggle_top_padding . broadcast(String::from("0"))
. await.unwrap();
},
}
}})
);
builder! {
<div class="markdown"
post:build=move |_: &mut Dom| {
tx_logic.try_broadcast(MarkdownLogic::Choose(None)).unwrap();
}
capture:view=tx_dom.sink()>
<div style:cursor="text">
<div>
<div>
<button on:click=select_filter>{select_icon()}</button>
<ul patch:children=rx_patches>
</ul>
</div>
<button on:click=store_filter>{save_icon()}</button>
<button on:click=discard_filter>{undo_point_icon()}</button>
<button on:click=toggle_filter>{edit_icon()}</button>
</div>
<pre contenteditable="true"
style:display=("none", rx_toggle_editor)
on:input=input_filter>
</pre>
</div>
<div style:padding_top=("0", rx_toggle_top_padding)></div>
</div>
}
}