              :class (if (= visibility key) "selected")}
             title]])]
 
-   (if has-completed-todos?
+   (when has-completed-todos?
      [:button.clear-completed {:on-click #(dispatch :on-clear-completed)} "Clear completed"])])
 
 (defn view

(ns app.view
  (:require [reagent.core :as r]))

(defn -enter-key?
  [e]
  (= (.-keyCode e) 13))

(defn -escape-key?
  [e]
  (= (.-keyCode e) 27))

(defn -view-header
  [field dispatch]
  [:header.header
   [:h1 "todos"]

                   (fn [this]
                     (.focus (r/dom-node this)))}))

(defn -todo
  [{:keys [id title editing? completed?] :as _todo} dispatch]
  [:li {:class (cond editing? "editing" completed? "completed")}
   [:div.view
    [:input.toggle {:type      "checkbox"
                    :checked   completed?
                    :on-change #(dispatch [:on-toggle id])}]
    [:label {:on-double-click #(dispatch [:on-start-editing id])} title]
    [:button.destroy {:on-click #(dispatch [:on-remove id])}]]

   [-todo-input id title editing? dispatch]])

(defn -todo-list
  [todos all-completed? dispatch]
  [:section.main
   [:input.toggle-all {:type      "checkbox"
                       :checked   all-completed?
                       :on-change #(dispatch :on-toggle-all)}]
   [:label {:for "toggle-all"} "Mark all as complete"]
   [:ul.todo-list
    (for [todo todos]
      ^{:key (:id todo)}
      [-todo todo dispatch])]])

(defn -footer
  [active-count has-completed-todos? visibility visibility-spec dispatch]
  [:footer.footer
   [:span.todo-count
    [:strong active-count] " " (if (= active-count 1) "item" "items") " left"]

   [:ul.filters
    (for [{:keys [key title href]} visibility-spec]
      ^{:key key}
