 
 (om/root deck-builder app-state {:target (. js/document (getElementById "deckbuilder"))})
 
-;; (defn load-deck [data]
-;;   (let [cards (:cards @cb/app-state)
-;;         decks (for [deck data line (:cards deck)]
-;;                 (some #(when (= (:code %) (:card line)) %) cards)
-;;                 )]
-;;       ;; (swap! app-state assoc :decks data)
-;;       (println decks)
-;;       ))
-
 (when-not (empty? (:user @auth/app-state))
-  (go (swap! app-state assoc :decks (:json (<! (GET (str "/data/decks" (:username user))))))))
+  (go (let [data (:json (<! (GET (str "/data/decks" (:username user)))))
+            decks (for [deck data]
+                    (let [cards (map #(str (:qty %) " " (:card %)) (:cards deck))]
+                      (assoc deck :cards (parse-deck (join "\n" cards)))))]
+        (swap! app-state assoc :decks decks))))

  (end-edit owner)
  (let [deck (om/get-state owner :deck)
        cards (for [card (:cards deck)]
                {:qty (:qty card) :card (get-in card [:card :code])})
        data (assoc deck :cards cards)]
    (swap! app-state assoc :decks (conj (:decks @app-state) data))
    (go (let [response (<! (POST "/data/decks/" data :json))]))))

(defn handle-edit [event owner]
  (let [deck (-> owner (om/get-node "deck-edit") .-value)]
    (om/set-state! owner [:deck :cards] (parse-deck deck))))

(defn deck-view [{:keys [name identity]} owner]
  (reify
    om/IRenderState
    (render-state [this state]
      (sab/html
       [:div.block-link
        [:h4 name]
        [:p identity]]))))

(defn decklist-view [{:keys [name identity cards]} owner]
  (om/component

            [:button {:on-click #(new-deck "Runner" owner)} "New Runner deck"]]
           (if (empty? decks)
             [:h4 "You have no deck"]
             (for [deck decks]
               [:div.block-link {:class (when (= (:deck state) deck) "active")
                                 :on-click #(om/set-state! owner :deck deck)}
                [:h4 (:name deck)]
                [:p (:identity deck)]]))]

          [:div.decklist
           (when-not (empty? (:deck state))
