 (ns lambdacd.ui-core
   (:require-macros [cljs.core.async.macros :refer [go go-loop]])
   (:require [reagent.core :as reagent :refer [atom]]
+            [secretary.core :as secretary :refer-macros [defroute]]
+            [goog.events :as events]
+            [goog.history.EventType :as EventType]
+            [reagent.session :as session]
             [cljs.core.async :as async]
             [lambdacd.utils :as utils]
             [lambdacd.api :as api]
             )
   (:import goog.History))
 
+
+(secretary/set-config! :prefix "#")
+
+(defroute build-route "/builds/:buildnumber" [buildnumber] (session/put! :build-number buildnumber))
+(defroute default-route "/" []
+          (.setToken (History.) "/builds/1"))
+
+
 (enable-console-print!)
 
 (def history-poll-frequency 5000)
-
 
 (defn poll [atom fn]
   (go-loop []


(defn current-build-component [build-state-atom build-number output-atom]
  [:div {:key build-number :class "blocked"}
   [:h2 (str "Current Build " @build-number)]
   [:div {:id "pipeline" }
    [:ol
     (map #(build-step-component % output-atom) @build-state-atom)]]

(defn poll-history [history-atom]
  (poll history-atom api/get-build-history))

(defn poll-state [history-atom build-number]
  (poll history-atom #(api/get-build-state build-number)))

(defn history-item-component [{build-number :build-number status :status}]
  [:li {:key build-number} [:a {:href (build-route {:buildnumber build-number})} (str "Build " build-number)]])

(defn build-history-component [history]
  (let [history-to-display (sort-by :build-number @history)]
