-
-
Save brandonbloom/0acd45c60860e4dd562f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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