view.rs 1.55 KB
use mogwai::prelude::*;

pub(super) fn upload_preview_view( tx_canvas :broadcast::Sender<Dom>
                                 , 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();
    };

    builder! {
        <li style:display="flex">
            <div style:width="100px"
                 style:height="100px">
                <canvas post:build=post_build />
            </div>
            <div style:width="fit-content">
                <ul>
                    <li>{format!("filename: {}", filename)}</li>
                    <li>{format!("size: {}", size)}</li>
                    <li>{format!("mime type: {}", mime_type)}</li>
                    <li>{format!("modification time: {}", mtime)}</li>
                </ul>
            </div>
        </li>
    }
}

pub(super) fn upload_view( tx_logic: broadcast::Sender<DomEvent>
                         , rx_previews: mpmc::Receiver<ListPatch<ViewBuilder<Dom>>>
                         ) -> ViewBuilder<Dom> {
    builder! {
        <div class="upload">
            <div class="spin"></div>
            <div>
                <input type="file"
                       multiple="multiple"
                       accept="image/*"
                       on:change=tx_logic.sink()/>
            </div>
            <ul patch:children=rx_previews>
            </ul>
        </div>
    }
}