 (defn- frequency-stat [title data]
   (format "%s: %s - %s" title (count data) (frequencies-string data)))
 
+(defn clear-id [id]
+  (fn [_ _ _] (dom/set-html! (dom/by-id id) "")))
+
+(defn focus-fn [screen]
+  (fn [{:keys [transform messages]}]
+    (msg/fill transform messages {:value (name screen)})))
+
+(defn navigate-fn [screen]
+  (fn [_ _ input-queue]
+    (history/navigated input-queue screen)))
+
 ;; Rendering fns
 
 (def templates (html-templates/semtag-web-templates))
 
+;;; Home
+;;;
 (defn render-home-page [renderer [_ path] input-queue]
   (history/navigated input-queue :home)
   (let [html (templates/add-template renderer path (:semtag-web-page templates))]
     ;; didn't use get-parent-id cause it doesn't work for new multi-level paths
     (dom/set-html! (dom/by-id "content") (html {}))))
-
-(defn clear-id [id]
-  (fn [_ _ _] (dom/set-html! (dom/by-id id) "")))
 
 (defn set-search-title [renderer [_ path _ new-value] _]
   (dom/set-html! (dom/by-id "search_title") new-value))

                      :caption (str "Total: " (count new-value))
                      :fields [:type :name :url :tags :created-at])))

(defn focus-fn [screen]
  (fn [{:keys [transform messages]}]
    (msg/fill transform messages {:value (name screen)})))

(defn url-search [{:keys [transform messages]}]
  (msg/fill transform messages {:query (.-value (dom/by-id "url_search_text"))
                                :search-type (dom/value (css/sel "input[name=search_type]:checked"))}))

(defn create-url [{:keys [transform messages]}]
  (msg/fill transform messages {:value (dom/value (dom/by-id "add_url_text"))}))

(defn render-types-page [_ _ input-queue]
  (history/navigated input-queue :types))

(defn render-tag-stats-page [_ _ input-queue]
  (history/navigated input-queue :tag-stats))

(defn navigate-fn [screen]
  (fn [_ _ input-queue]
    (history/navigated input-queue screen)))

(defn render-config []
  (reduce
    into

                        :row-partial p/tag-search-row
                        :caption (format "Total: %s" (count (map :url things)))))))

(defn render-tags-results [_ [_ _ _ new-value] _]
  (dom/insert-after!
    (dom/by-id "url_search_text")
    (p/generate-datalist new-value)))

(defn url-search [{:keys [transform messages]}]
  (msg/fill transform messages {:query (.-value (dom/by-id "url_search_text"))
                                :search-type (dom/value (css/sel "input[name=search_type]:checked"))}))

(defn create-url [{:keys [transform messages]}]
  (msg/fill transform messages {:value (dom/value (dom/by-id "add_url_text"))}))

;;; Other pages
;;;
(defn render-types-results [_ [_ _ _ new-value] _]
  (dom/set-html!
    (dom/by-id "content")
