Skip to content

Instantly share code, notes, and snippets.

@brandonbloom
Last active December 21, 2015 14:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonbloom/0acd45c60860e4dd562f to your computer and use it in GitHub Desktop.
Save brandonbloom/0acd45c60860e4dd562f to your computer and use it in GitHub Desktop.
(defn task-form []
[(textbox :new-task)
(when (key-pressed? :enter)
(when-let [description (clean-value :new-task)]
(create-task description)))])
(defn task-header []
(header
(h1 "todos")
(task-form)))
(defn toggler [tasks]
(when (seq tasks)
[(checkbox :all-complete?)
(label :all-complete? "Mark all as complete")
(when (toggled? :all-complete?)
(toggle-all (checked? toggle-all)))]))
(defn task-item [task]
(li
[(checkbox :complete?)
(if (:editing? task)
[(div :description (:description task))
(when (double-clicked? :description)
(edit (:id task)))]
[(textbox :description (:description task))
(when (or (key-pressed? :enter) (lost-focus? :description))
(edit nil))])
(button :destroy)
(when (clicked? :destroy)
(delete (:id task)))]))
(defn task-list [tasks]
(section :main
(toggler tasks)
(ul
(for [task (filter-tasks tasks)]
(task-item task)))))
(defn task-footer [tasks]
(footer
;;TODO are strings OK? plural vs singular
[(span :todo-count (strong (count tasks)) " items left")
(ul
(li (a :all "All"))
(li (a :active "Active"))
(li (a :completed "Completed"))
;;TODO filter clicked
)
(when (seq (completed tasks))
[(button :clear-completed
(str "Clear completed (" (count (completed tasks)) ")"))
(when (clicked? :clear-completed)
(clear-completed))])]))
(defn todo-app [tasks]
[(task-header)
(task-list tasks)
(task-footer tasks)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment