 )
 
 
-
-
-(defonce app-state (atom {:stories  (some-stories)}))
+(defonce app-state 
+  ;; View = 0 corresponds to the items list view
+  ;; View = 1 corresponds to the single item view
+  (atom {:stories (some-stories) :view 0 })
+)
 
 
 (defn display-title [{:keys [Title Introduction] :as story}]
   (str Title)
 )
 
-
+(defn error-handler [{:keys [status status-text]}]
+  (.log js/console (str "something bad happened: " status " " status-text)))
+
+
+
+(defn OnDownloadStory [response]
+  (
+    let [     
+      ;;newdata (js->clj response)
+      newdata (vector {:Title (get response "Title")  :Introduction (get response "Introduction")
+         :Reference (get response "Reference") :Body (get response "Body")}  
+     )
+
+
+;;[{:Title (get (first response) "Title") :Introduction  (get (first response) "Introduction") :Reference  (get (first response) "Reference") :Updated  (get (first response) "Updated") :Published (get (first response) "Pub;ished")}]
+    ]
+
+    (.log js/console (str newdata))
+    ;;(.log js/console (str (select-keys (js->clj response) [:Title :Reference :Introduction])  ))    
+    ;(swap! app-state assoc-in pageid newdata )
+    (swap! app-state assoc-in [:stories] newdata )
+    (swap! app-state assoc-in [:view] 1 )
+  )
+  
+  ;;(.log js/console (str  (response) ))
+  ;;(.log js/console (str  (get (first response)  "Title") ))
+
+  
+  
+)
+
+
+(defn downloadstory [href]
+  (GET (str "http://localhost:8083/api/story/" href)  {:handler OnDownloadStory
+                                              :error-handler error-handler})
+
+)
 
 
 (defn story-view [story owner]

)


(defn stripe [story bgc]0
  (let [st #js {:backgroundColor bgc}]
    (dom/li #js {:style st} (get story :Title))))

(defn stories-view [app owner]
  (reify
    om/IRender
    (render [_]


(defn some-stories []
[
  {:Title "The title 1" :Introduction "The introduction 1" :Published "04/27/2016 - 18:38" :Reference "aHR0cDovL3d3dy56ZXJvaGVkZ2UuY29tL25ld3MvMjAxNi0wNC0yNy9lbmQtdmVuZXp1ZWxhLXJ1bnMtb3V0LW1vbmV5LXByaW50LW5ldy1tb25leQ==" :Body "The story body" } 
  {:Title "The title 2" :Introduction "The introduction 2" :Published "04/27/2017 - 18:38" :Reference "R0cDovL3d3dy56ZXJvaGVkZ2UuY29tL25ld3MvMjAxNi0wNC0yNy9lbmQtdmVuZXp1ZWxhLXJ1bnMtb3V0LW1vbmV5LXByaW50LW5ldy1tb25leQ=="}
  {:Title "The title 3" :Introduction "The introduction 3" :Published "04/27/2016 - 18:38" :Reference "HR0cDovL3d3dy56ZXJvaGVkZ2UuY29tL25ld3MvMjAxNi0wNC0yNy9lbmQtdmVuZXp1ZWxhLXJ1bnMtb3V0LW1vbmV5LXByaW50LW5ldy1tb25leQ=="}
;  "Lion" "Zebra" "Buffalo" "Antelope"
