   [status cards]
   [:div.list
    [:h1 (status->str status)]
-   (for [c (filter-by-status status cards)]
+   (for [c (filter-by-status status (map second cards))]
      ^{:key (:card-id c)} [render-card c])
   ])
 


(def fetch-and-render-app
  "Render the app - adding a fetching of data when the DOM is mounted"
  (let [append-all (fn [cards] (swap! card-list #(into % cards)))]
    (with-meta render-app
     {:component-did-mount #(fake/fake-fetch! append-all) })
  ))

  [title cards]
  (if (empty? title)
    cards
    (filter #(utils/str-contains (-> % second :title) title) cards)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; TODO - Separate concerns!
; Model at the end:
; - A map id to card
; - Collections for each status: each holding the list of IDs they have
; - Use a reaction to provide for the filtered list of cards (filtered by text)

(def card-list
  (r/atom {}))

(defn add-task-to!
  "Add a new task in the card"
  [card-id task]
  (swap! card-list
    #(update-in % [card-id :tasks] conj (api/create-task! task false))
  ))

(defn remove-task-from!
  "Remove a task from a card"
  [card-id task-id]
  (defn rem-task [cards]
    (update-in cards [card-id :tasks]
       (fn [tasks]
         (filterv #(not= (:task-id %) task-id) tasks))
    ))
  (swap! card-list rem-task))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

