view.rs
2.07 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
use mogwai::prelude::*;
use chrono::prelude::*;
use crate::component::upload::logic::UploadLogic;
pub(super) fn upload_preview_view( tx_canvas :broadcast::Sender<Dom>
, tx_click :broadcast::Sender<DomEvent>
, filename :String
, size :f64
, mime_type :String
, mtime :f64
) -> ViewBuilder<Dom> {
let post_build = move |dom: &mut Dom| {
tx_canvas.try_broadcast(dom.clone()).unwrap();
};
let size = format!("{}", size);
let mtime = format!("{}", Utc.timestamp_millis(mtime as i64));
builder! {
<li on:click=tx_click.sink()>
<canvas width="75px"
height="75px"
post:build=post_build />
<ul>
<li><span>"Name"</span><span>{filename}</span></li>
<li><span>"Size"</span><span>{size}</span></li>
<li><span>"Mime-Type"</span><span>{mime_type}</span></li>
<li><span>"Date"</span><span>{mtime}</span></li>
</ul>
</li>
}
}
pub(super) fn upload_view( tx_logic: broadcast::Sender<UploadLogic>
, rx_previews: mpmc::Receiver<ListPatch<ViewBuilder<Dom>>>
) -> ViewBuilder<Dom> {
let select_filter = tx_logic.sink()
. contra_map(|e| UploadLogic::Add(e));
let upload_filter = tx_logic.sink()
. contra_map(|_| UploadLogic::Upload);
// <div class="spin"></div>
builder! {
<div class="upload">
<div>
<input type="file"
multiple="multiple"
accept="image/*"
on:change=select_filter />
<button on:click=upload_filter>"Upload"</button>
</div>
<ul patch:children=rx_previews>
</ul>
<p>"Click on preview to "<em>"deselect"</em>"."</p>
</div>
}
}