Remove recipes
This commit is contained in:
parent
8ecc7e9ad4
commit
d018bcf3cf
4 changed files with 17 additions and 1 deletions
|
@ -66,6 +66,9 @@
|
|||
{:_id (:id event)}
|
||||
{mo/$set {:name (:name event) :grubs (:grubs event)}}))
|
||||
|
||||
(defmethod handle-event :remove-recipe [event]
|
||||
(mc/remove-by-id @db recipe-collection (:id event)))
|
||||
|
||||
(defmethod handle-event :unknown-event [event]
|
||||
(println "Cannot handle unknown event:" event))
|
||||
|
||||
|
|
|
@ -62,6 +62,9 @@
|
|||
(assoc-in [:recipes (:id event) :name] (:name event))
|
||||
(assoc-in [:recipes (:id event) :grubs] (:grubs event))))
|
||||
|
||||
(defmethod handle-event :remove-recipe [event state]
|
||||
(assoc state :recipes (dissoc (:recipes state) (:id event))))
|
||||
|
||||
(defn update-state-and-render [remote]
|
||||
(let [out (chan)
|
||||
view-events (view/render-app app-state)]
|
||||
|
|
|
@ -33,8 +33,9 @@
|
|||
recipe-add (chan)
|
||||
recipe-add-grubs (chan)
|
||||
recipe-update (chan)
|
||||
recipe-remove (chan)
|
||||
out (a/merge [grub-add grub-update grub-clear-all grub-remove
|
||||
recipe-add recipe-add-grubs recipe-update])
|
||||
recipe-add recipe-add-grubs recipe-update recipe-remove])
|
||||
>events (chan)
|
||||
<events (a/pub >events :type)]
|
||||
(om/root app-view
|
||||
|
@ -47,6 +48,7 @@
|
|||
:recipe-add recipe-add
|
||||
:recipe-add-grubs recipe-add-grubs
|
||||
:recipe-update recipe-update
|
||||
:recipe-remove recipe-remove
|
||||
:>events >events
|
||||
:<events <events}})
|
||||
out))
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
:name name
|
||||
:grubs grubs})
|
||||
|
||||
(defn remove-event [id]
|
||||
{:event :remove-recipe
|
||||
:id id})
|
||||
|
||||
(defn parse-grubs-from-str [grubs-str]
|
||||
(->> grubs-str
|
||||
(clojure.string/split-lines)
|
||||
|
@ -96,6 +100,10 @@
|
|||
:rows (inc (num-newlines grubs))
|
||||
:value grubs
|
||||
:on-change #(om/set-state! owner :grubs (dom/event-val %))}]
|
||||
[:button.btn.btn-danger.pull-left.recipe-remove-btn
|
||||
{:type "button"
|
||||
:on-click #(put! (om/get-shared owner :recipe-remove) (remove-event id))}
|
||||
"Delete"]
|
||||
[:button.btn.btn-primary.pull-right.recipe-done-btn
|
||||
{:type "button"
|
||||
:ref :save-btn
|
||||
|
|
Loading…
Reference in a new issue