 ;; App State
 ;;------------------------------------------------------------------------------
 
-(def state (atom {
+(def initial-project-build-state
+  "Initial state for a new build in a project"
+  {;; tool state
+   :active? true
+   :compile-time 0
+   :last-compile-time nil
+   :error nil
+   :state :done
+   :warnings []
+
+   ;; from project.clj
+   :id nil
+   :source-paths []
+   :compiler {}})
+
+(def initial-project-state
+  "Initial state for a new project"
+  {;; tool state
+   :compile-menu-showing? false
+   :auto-compile? true
+   :state :idle
+
+   ;; from project.clj
+   :name ""
+   :filename ""
+   :version ""
+   :license {}
+   :dependencies []
+   :plugins []
+
+   ;; from project.clj, but with extra tool state
+   ;; (see initial-project-build-state)
+   :builds []})
+
+(def initial-app-state
+  {:projects {:order []}})
+
+(def state (atom initial-app-state))
+
+(defn get-ordered-projects
+  "Given a project map containing a list of keys in :order, return a vector of their ordered values."
+  [project-map]
+  (let [proj-keys (-> project-map :order)]
+    (mapv #(get project-map %) proj-keys)))
+
+(def test-app-state
+  "A test app-state for quick-testing page rendering."
+  {
   :projects {
     "/home/oakmac/t3tr0s/project.clj" {
-    ;;"C:\\t3tr0s\\project.clj" {
       :compile-menu-showing? false
       :auto-compile? true
       :name "t3tr0s"

    (map
      (fn [prj-key]
        (swap! state assoc-in [:projects prj-key :compile-menu-showing?] false))
      (-> @state :projects keys))))

(defn- click-compile-btn [prj-key]
  (let [prj (get-in @state [:projects prj-key])

          [:span.link-3d3ad [:i.fa.fa-plus] "Add project"]
          [:span.link-3d3ad [:i.fa.fa-gear] "Settings"]]
        [:div.clr-737fa]]
      (map Project (get-ordered-projects (:projects app-state)))]))

;;------------------------------------------------------------------------------
;; State Change and Rendering
