   (reify
     om/IInitState
     (init-state [_]
-      {:comm (chan)})
+      {:comm (chan)
+       :loading false})
     om/IWillMount
     (will-mount [_]
-      (let [comm (om/get-state owner :comm)
-            core-comm (om/get-state owner :core-comm)]
-        (go
+      (when (empty? (:geolocation data))
+        (om/set-state! owner :loading true))
+      (go
+        (let [loc (<! (get-geolocation))]
+          (om/update! data [:geolocation] loc))
+        (om/set-state! owner :loading false))
+      (go
+        (let [comm (om/get-state owner :comm)
+              core-comm (om/get-state owner :core-comm)]
           (while true
             (let [[msg msg-data] (<! comm)]
               (case msg


(defn channel-list [{:keys [params data]} owner]
  (reify
    om/IInitState
    (init-state [_]
      {:loading false})
    om/IWillMount
    (will-mount [_]
      (when (empty? (:channels data))
        (om/set-state! owner :loading true))
      (om/set-state! owner :interval-chan
        (go
          (let [loc (<! (get-geolocation))]
            (om/update! data [:geolocation] loc)
            (let [response (<! (http/get "/api/channels" {:query-params loc}))]
              (om/update! data [:channels] (:body response)))
            (om/set-state! owner :loading false)
            (js/setInterval
              #(go
                 ;(let [loc (<! (get-geolocation))]
                 ;  (om/update! data [:geolocation] loc)
                   (let [response (<! (http/get "/api/channels" {:query-params loc}))]
                     (om/update! data [:channels] (:body response))))
              3000)))))
    om/IWillUnmount
    (will-unmount [_]
      (go
        (js/clearInterval (<! (om/get-state owner :interval-chan)))))
    om/IRenderState
    (render-state [_ {:keys [comm]}]
      (if (om/get-state owner :loading)
        (om/build loading nil)
        (dom/div nil
          (apply dom/ul #js {:className "virt-list"}
            (om/build-all list-item (:channels data) {:init-state {:comm comm}})))))))

(defn new-channel [_ owner]
  (reify



(def app-state
  {:channels []
   :geolocation nil})

(def routes ["new" ::new])
