                        (map #(assoc % :css "collection-item")))]
       (dispatch [:received-surveys surveys]))))
 
-(defn validate-geojson
-  [coords]
-  (go
-    (let [resp (<! (http/post "http://geojsonlint.com/validate" {:json-params coords}))]
-      (.log js/console "validate: " (clj->js resp)))))
-
 (defn fetch-survey-details
   [survey]
   (go

(register-handler
 :fetch-survey-details
 (fn [app-db [_ survey]]
   (let [updated-surveys (map (fn [it]
                                (let [year  (:year survey)
                                      month (:month survey)]
                                  (if (and (= year (:year it)) (= month (:month it)))
                                    (if (= "collection-item active" (:css it))
                                      (assoc it :css "collection-item")
                                      (do 
                                        (fetch-survey-details survey)
                                        (assoc it :css "collection-item active")))
                                    (assoc it :css "collection-item"))))
                              (:surveys app-db))]

     (assoc app-db :surveys updated-surveys))))

(register-handler
 :received-survey-deatils
 (fn [app-db [_ details]]
   (map-coords details)
   (assoc app-db :survey-details details)))

          month (:month survey)
          url   (str "/api/survey-details?year=" year "&month=" month)
          resp  (<! (http/get url {"accept" "application/json"}))]
      (dispatch [:received-survey-deatils (get-in resp [:body :features])]))))

(defn remove-coords
  [coords coord-to-remove]
  (remove (fn [coord]
            (= (get-in coord [:survey :id]) (:_id coord-to-remove))) 
          coords))


(defn find-updated-surveys
  "Finds surveys that have been updated and toggles its
  css class.
  If a survey matches the year and month, but it 
  is not 'active', then an xhr request is made
  to fetch that survey's features; and an `active`
  css class is attached to it. If the survey is `active`, then
  the css class `active` is removed from it."
  [surveys year month]
  (map (fn [survey]
         (if (and (= year (:year survey))
                  (= month (:month survey)))
           (if (= "collection-item active" (:css survey))
             (assoc survey :css "collection-item")
             (do (fetch-survey-details survey)
                 (assoc survey :css "collection-item active")))
           survey))
       surveys))

(defn get-final-features
  "Removes all features for the surveys that are `unselected`.
  The survey's css is not changed yet, and it is active, so we 
  need to check for that and the survey's year and month to determine
  which feature to remove."
  [{:keys [surveys features year month]}]
  (reduce (fn [acc survey]
            (if (and (= year (:year survey))
                     (= month (:month survey))
                     (= "collection-item active" (:css survey)))
              (remove-coords acc survey)
              acc))
          features
          surveys))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Handlers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(register-handler
 :initialize-db 
 (fn [_ _]
