                (dom/button 
                  #js {:onClick (fn [e]
                                  (.preventDefault e)
-                                 (new-search data state owner))}
+                                 (when (not (empty? (:text state)))
+                                   (set! js/window.location.hash ((-> @data :routes :search) 
+                                                                  {:query (:text state)}))
+                                   (om/set-state! owner :text ""))
+                                 )}
                  "Search")
                ; clear button
                (dom/button
                  #js {:onClick (fn [e]
                                  (.preventDefault e)
                                  (om/set-state! owner :text "")
-                                 (om/transact! data reset-state)
                                  )}
                  "Clear")))))
 

(defn items-view [data owner]
  (let [col-n (quot (:window-width data) IMGSIZE)
        left-offset (int (/ (mod (.. js/window -innerWidth) IMGSIZE) 2))]
    (apply dom/div #js {:className "images"}
           (om/build-all 
             item-view 
             (->> (:current-items data)
                  #(loop [items   %
                          coll    []
                          idx     0
                          offsets (zipmap (range col-n) (repeat 0))]
                     (if (empty? items) coll
                       (let [item  (first items)
                             title (s/replace (:slug item)  #"-"  " ") 
                             photo (-> item :photos first :alt_sizes second)]
                         (if (or (nil? (:height photo)) (nil? (:width photo)))
                           ; nil size found - drop the image
                           (recur (rest items) coll idx offsets)
                           ; ok
                           (let [offset-n    (mod idx col-n)
                                 offset      (apply min-key second offsets)
                                 offset-x    (+ left-offset (* IMGSIZE (first offset)))
                                 offset-y    (second offset)
                                 new-height  (int (* (:height photo) (/ IMGSIZE (:width photo))))
                                 new-offsets (update-in offsets [(first offset)] #(+ % new-height))
                                 new-item {:index idx
                                           :title title
                                           :photo photo
                                           :post_url (:post_url item)
                                           :x offset-x
                                           :y offset-y
                                           }]
                             (recur
                               (rest itemss)
                               (conj coll new-item)
                               (inc idx)
                               new-offsets)))))))))))


;; Loading ------------------------------------------------

                   )))))
  (atom initial-state)
  {:target (. js/document (getElementById "app"))})


;; Routing


(fw/watch-and-reload
  :websocket-url   "ws://localhost:3449/figwheel-ws"
  :jsload-callback (fn [] (print "reloaded")))

