   (om/set-state! owner :edit false)
   (-> owner (om/get-node "viewport") js/$ (.removeClass "edit")))
 
-(defn save-deck [owner]
+(defn save-deck [cursor owner]
   (end-edit owner)
-  (let [deck (om/get-state owner :deck)
+  (let [deck (assoc (om/get-state owner :deck) :date (.toJSON (js/Date.)))
         decks (:decks @app-state)
         cards (for [card (:cards deck)]
                 {:qty (:qty card) :card (get-in card [:card :title])})
         data (assoc deck :cards cards)]
     (if-let [id (:_id deck)]
-      (swap! app-state assoc :decks (map #(if (= id (:_id %)) deck %) decks))
-      (swap! app-state assoc :decks (conj decks deck)))
+      (om/update! cursor :decks (map #(if (= id (:_id %)) deck %) decks))
+      (om/update! cursor :decks (conj decks deck)))
     (go (let [response (<! (POST "/data/decks/" data :json))]))))
 
 (defn match [{:keys [side faction]} query]

      (let [add-channel (om/get-state owner :add-channel)]
        (go (while true
              (let [line (<! add-channel)]
                (-> ".deckedit textarea" js/$ (.append line))
                (handle-edit owner))))))

    om/IDidUpdate
    (did-update [this prev-props prev-state]
      (if (and (not (empty? decks)) (not (:deck prev-state)))
        (om/set-state! owner :deck (first decks))))

    om/IRenderState
    (render-state [this state]

                (if (:edit state)
                  [:span
                   [:button.big {:on-click #(end-edit owner)} "Cancel"]
                   [:button.big {:on-click #(save-deck cursor owner)} "Save"]]
                  [:span
                   [:button.big {:on-click #(handle-delete cursor owner)} "Delete"]
                   [:button.big {:on-click #(edit-deck owner)} "Edit"]])
