 (re-frame/register-handler
   :replace-tea
   (fn [app-state [_ replaced-by edit-tea-input]]
-    (assoc-in app-state [:teas-list] (replace {replaced-by edit-tea-input} (:teas-list app-state)))))
+    (re-frame/dispatch [:update-tea (:id replaced-by) edit-tea-input])
+    (assoc-in app-state [:teas-list] (replace {replaced-by
+                                               {:id (:id replaced-by)
+                                                :name edit-tea-input}}
+                                      (:teas-list app-state)))))
 
 (re-frame/register-sub
   :teas

  [event]
  (-> event .-target .-value))


(defn edit-tea-form
  [tea edit?]
  (let [edit-tea (reagent/atom (:name tea))]
    (fn [tea]
      [:form.pull-left {:type "text"
                        :value @edit-tea
                        :on-change #(reset! edit-tea (value-event %))}]
      [:button.btn.btn-success.pull-right {:on-click (fn [e]
                                                      (re-frame/dispatch
                                                        [:replace-tea tea @edit-tea])
                                                      (swap! edit? not))}
       "Finalize"])))

(defn tea-edit-toggler
  [tea]
  (let [edit? (reagent/atom false)]
    (fn [tea]
      (if @edit?
        [:tr
          [:td.pull-right [edit-tea-form tea edit?]]]
        [:tr
          [:td.pull-left {:on-click #(swap! edit? not)} (:name tea)]]))))


            :error-handler (fn [response] (println "DELETE-TEA ERROR" response))
            :handler (fn [response] (println name " deleted") (re-frame/dispatch [:load-teas])(reset! edit-tea-snap nil))))

(defn post-to-teas-db
  "Sends an Ajax Request to the API route to post the tea from the form to the database"
  [tea-name]
