From a22a32d996c82a394695f167ea2db93b86c56e6b Mon Sep 17 00:00:00 2001 From: Nicholas Kariniemi Date: Sun, 27 Jul 2014 10:20:00 +0300 Subject: [PATCH] Set new recipe to edit mode --- src/cljs/grub/view/app.cljs | 16 +++++++----- src/cljs/grub/view/grub.cljs | 9 ++++--- src/cljs/grub/view/recipe.cljs | 48 +++++++++++++++++++++++++++++----- 3 files changed, 55 insertions(+), 18 deletions(-) diff --git a/src/cljs/grub/view/app.cljs b/src/cljs/grub/view/app.cljs index d3e4a23..403486c 100644 --- a/src/cljs/grub/view/app.cljs +++ b/src/cljs/grub/view/app.cljs @@ -25,18 +25,20 @@ (dom/on-body-mousedown #(put! >events {:type :body-mousedown :event %})))))) (defn render-app [state] - (let [add (chan) - update (chan) - clear-all (chan) - out (a/merge [add update clear-all]) + (let [grub-add (chan) + grub-update (chan) + grub-clear-all (chan) + recipe-add (chan) + out (a/merge [grub-add grub-update grub-clear-all recipe-add]) >events (chan) events :type)] (om/root app-view state {:target (.getElementById js/document "container") - :shared {:add add - :update update - :clear-all clear-all + :shared {:grub-add grub-add + :grub-update grub-update + :grub-clear-all grub-clear-all + :recipe-add recipe-add :>events >events :local-events :mouse-up) :on-mouse-leave #(put! >local-events :mouse-leave) :on-click #(when (#{:waiting :pressed} edit-state) - (put! (om/get-shared owner :update) (complete-event @props)))} + (put! (om/get-shared owner :grub-update) (complete-event @props)))} [:span.grub-static (if completed [:span.glyphicon.glyphicon-check] @@ -85,7 +85,7 @@ (recur)))) (a/unsub local-events publisher + :local-events]}] (html [:div [:h3.recipes-title "Recipes"] [:div.panel.panel-default.recipe-panel + {:on-click #(put! >local-events :click)} [:div.panel-heading.recipe-header [:input.form-control.recipe-header-input {:id "recipe-name" :type "text" - :placeholder "Grub pie"}] - [:button.btn.btn-primary.btn-sm.recipe-add-grubs-btn {:type "button"} "Add Grubs"]] - [:div.panel-body.recipe-grubs.hidden + :placeholder "Grub pie"}]] + [:div.panel-body.recipe-grubs + {:class (when (not editing) "hidden")} [:textarea.form-control.recipe-grubs-input {:id "recipe-grubs" :rows 3 @@ -55,4 +64,29 @@ {:type "button"} "Done"]]] [:ul#recipe-list.list-group.recipe-list (for [recipe (vals recipes)] - (om/build recipe-view recipe {:key :id}))]])))) + (om/build recipe-view recipe {:key :id}))]])) + + om/IWillMount + (will-mount [_] + (let [