 
 ;;; PAGE
 
-(def email-regex #"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$")
-
-(defn validate-user
-  "Build map of {key error} pairs, where each {error} relates to persion.{key}"
-  [doc]
-  (let [person (:person doc)]
-    (cond-> {}
-      (empty? (:first-name person))
-      (assoc :first-name "First name is empty")
-
-      (empty? (:last-name person))
-      (assoc :last-name "Last name is empty")
-
-      (empty? (:email person))
-      (assoc :email "Email is empty")
-
-      (when-let [email (:email person)]
-        (nil? (re-find email-regex email)))
-      (assoc :email "Email is not valid")
-
-      (nil? (:age person))
-      (assoc :age "Age is not set"))))
-
-(defn validate-user!
-  "Update errors atom, and return true if there were any errors."
-  [doc]
-  (let [errors (validate-user @doc)]
-    (swap! doc assoc :errors errors)
-    (empty? errors)))
-
-(defn submit!
-  "Ensure the signing user exists and their support is noted."
-  [doc]
-  (db/create-user! (:person doc) @db/supported-ideas))
+(defonce user-doc
+  (atom {:person {:first-name       "Blake"
+                  :last-name        "Hake"
+                  :email            "blake@hake.fake.com"
+                  :age              :18-24
+                  :alert-ideas?     true
+                  :alert-volunteer? true
+                  :alert-districts? true}}))
 
 (defn page []
-  (let [doc (atom {:person {:first-name       "Blake"
-                            :last-name        "Hake"
-                            :email            "blake@hake.fake.com"
-                            :age              :18-24
-                            :alert-ideas?     true
-                            :alert-volunteer? true
-                            :alert-districts? true}})]
-    (fn []
-      [:div
-       [bind-fields
-        form-template
-        doc
-        (fn [k v _]
-          (let [after (assoc-in @doc k v)
-                errors (validate-user after)]
-            (assoc after :errors errors)))]
-
-       [:button.btn.btn-default
-        {:on-click #(when (validate-user! doc)
-                      (submit! @doc))}
-        "Submit"]])))
+  (fn []
+    [:div
+     [bind-fields
+      form-template
+      user-doc
+      (fn [k v _]
+        (let [after (assoc-in @user-doc k v)
+              errors (validate-user after)]
+          (assoc after :errors errors)))]
+
+     [:button.btn.btn-default
+      {:on-click #(when (validate-user! user-doc) (submit! @user-doc))}
+      "Submit"]]))

                           :on-change #(let [supported? (-> % .-target .-checked)]
                                         (db/set-idea-support! id supported?))}
            [:label [:input {:type :checkbox :id id}] title]])
         [idea-form d]
         [:br]]))]))

(defn add-idea-component []
  [:div
   (input-placeholder "Idea title" :text :idea.idea)
   [select-cat-component]
   [:p
    [:textarea.form-control
     {:rows "4" :placeholder "If necessary, add a description"}]]
   (for [i (range 3)]
     [:div {:key i}
      (input-placeholder "Add a reference URL" :text (symbol (str "idea.url." i)))])
   [:button.btn.btn-default
    {:on-click #(db/create-idea! {:title     "More pizza"
                                  :desc      "Food for me"

            [reagent-forms.core :refer [bind-fields init-field value-of]]
            [geoforms.db :as db]))

;;; state and logic

(def app-state
  (atom
