view.rs 2.25 KB
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 toggle_map = rx_toggle
                   . map(|t| match t {
                       true => String::from("block"),
                       false => String::from("none") });

    builder! {
        <div class="input"
             style:width="33%"
             post:build=move |_: &mut Dom| {
                 tx_logic.try_broadcast(MarkdownLogic::Choose(None)).unwrap();
             }
             capture:view=tx_dom.sink()>
            <div contenteditable="true"
                 style:cursor="text"
                 on:input=input_filter
                 style:display=("none", toggle_map)>
                <pre></pre>
            </div>
            <div>
                <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>
                <div></div>
                <div></div>
            </div>
        </div>
    }
}