Skip to content

Commit 8715c3f

Browse files
authored
Merge pull request #143 from hackberrydev/task-state
Replace :done with :state in task
2 parents 84fb151 + 3113695 commit 8715c3f

17 files changed

Lines changed: 114 additions & 71 deletions

src/commands/insert_task.janet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
task-title - Task title.
2121
```
2222
[plan date task-title]
23-
(def task (task/build-task task-title false))
23+
(def task (task/build-task task-title :open))
2424
(def day (plan/day-with-date plan date))
2525
(if day
2626
(day/add-task day task))

src/plan.janet

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@
114114
(tasks-from-days (days-between plan start-date end-date)))
115115

116116
(defn completed-tasks [plan]
117-
(filter (fn [t] (t :done)) (all-tasks plan)))
117+
(filter (fn [t] (= (t :state) :checked)) (all-tasks plan)))
118118

119119
(defn pending-tasks [plan]
120-
(filter (fn [t] (not (t :done))) (all-tasks plan)))
120+
(filter (fn [t] (= (t :state) :open)) (all-tasks plan)))
121121

122122
(defn has-task-after?
123123
```

src/plan/parser.janet

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
:tasks
4040
{:main (group (any :task))
4141
:task
42-
{:main (replace (* (constant :done) :task-begin
42+
{:main (replace (* (constant :state) :task-begin
4343
" "
4444
(constant :title) (capture (some (if-not (+ "\n" " (missed on") 1)))
4545
(? :task-missed-on-date)
@@ -51,8 +51,8 @@
5151
{:main (* "- " :checkbox)
5252
:checkbox
5353
{:main (+ :checkbox-done :checkbox-pending)
54-
:checkbox-done (* (+ "[x]" "[X]") (constant true))
55-
:checkbox-pending (* "[ ]" (constant false))}}
54+
:checkbox-done (* (+ "[x]" "[X]") (constant :checked))
55+
:checkbox-pending (* "[ ]" (constant :open))}}
5656
:task-missed-on-date (* " (missed on " (constant :missed-on) :date ")")
5757
:task-body
5858
{:main (group (any :task-body-line))

src/plan/serializer.janet

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
(defn- plan-title [plan]
99
(string "# " (plan :title)))
1010

11-
(defn- checkbox [done]
12-
(if done "[X]" "[ ]"))
11+
(defn- checkbox [task]
12+
(if (= (task :state) :checked) "[X]" "[ ]"))
1313

1414
(defn- serialize-event-title [event]
1515
(string "- " (event :title)))
@@ -34,7 +34,7 @@
3434
""))
3535

3636
(defn- serialize-task-title [task]
37-
(string "- " (checkbox (task :done)) " " (task :title) (task-mark task)))
37+
(string "- " (checkbox task) " " (task :title) (task-mark task)))
3838

3939
(defn- serialize-task-body [task]
4040
(def body (task :body))

src/task.janet

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,25 @@
33

44
(import ./date)
55

6-
(defn build-task [title done &opt body]
6+
(def states [:open :checked])
7+
8+
(defn build-task [title state &opt body]
79
(default body @[])
8-
{:title title :body body :done done})
10+
(if (index-of state states)
11+
{:title title :body body :state state}
12+
(error (string "task doesn't support the state '" state "'"))))
913

1014
(defn build-scheduled-task [line title schedule]
11-
{:line line :title title :done false :schedule schedule})
15+
(def task (build-task title :open))
16+
(merge task {:line line :schedule schedule}))
1217

1318
(defn build-missed-task [title date &opt body]
14-
(default body @[])
15-
{:title title :body body :done false :missed-on date})
19+
(def task (build-task title :open body))
20+
(merge task {:missed-on date}))
1621

1722
(defn build-contact-task [title contact &opt body]
18-
(default body @[])
19-
{:title title :body body :done false :contact contact})
23+
(def task (build-task title :open body))
24+
(merge task {:contact contact}))
2025

2126
(defn mark-as-missed
2227
```

test/commands/insert_task_test.janet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
(deftest "when the task already exists"
2626
(def day (day/build-day (d/date 2020 8 10)
2727
@[]
28-
@[(task/build-task "Upgrade OS" false)]))
28+
@[(task/build-task "Upgrade OS" :open)]))
2929
(def plan (plan/build-plan :days @[day]))
3030
(def new-plan (insert-task plan (d/date 2020 8 10) "Upgrade OS"))
3131
(def new-day (first (new-plan :days)))

test/commands/remove_empty_days_test.janet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
(day/build-day (d/date 2020 8 5))
1717
(day/build-day (d/date 2020 8 4))
1818
(day/build-day (d/date 2020 8 3) @[]
19-
@[(task/build-task "Buy milk" true)])]))
19+
@[(task/build-task "Buy milk" :checked)])]))
2020
(def new-plan (remove-empty-days plan (d/date 2020 8 6)))
2121
(test (length (new-plan :days)) 2)
2222
(test (((new-plan :days) 0) :date)

test/commands/report_test.janet

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
(def plan
1414
(plan/build-plan
1515
:days @[(day/build-day (d/date 2020 8 7) @[]
16-
@[(task/build-task "Task 1" true)])
16+
@[(task/build-task "Task 1" :checked)])
1717
(day/build-day (d/date 2020 8 6) @[]
18-
@[(task/build-task "Task 2" true)
19-
(task/build-task "Task 3" true)])
18+
@[(task/build-task "Task 2" :checked)
19+
(task/build-task "Task 3" :checked)])
2020
(day/build-day (d/date 2020 8 5) @[]
21-
@[(task/build-task "Task 3" true)
22-
(task/build-task "Task 4" true)])
21+
@[(task/build-task "Task 3" :checked)
22+
(task/build-task "Task 4" :checked)])
2323
(day/build-day (d/date 2020 8 4) @[]
24-
@([(task/build-task "Task 5" true)]))]))
24+
@([(task/build-task "Task 5" :checked)]))]))
2525
(def tasks (report plan (d/date 2020 8 7) 2))
2626
(test (length tasks) 3)
2727
(test ((tasks 0) :title) "Task 2")

test/commands/schedule_contacts_test.janet

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
(let [day ((plan :days) 0)
1818
task ((day :tasks) 0)]
1919
(test (task :title) "Contact John Doe")
20-
(test (task :done) false)
20+
(test (task :state) :open)
2121
(test (empty? (task :body)) true)))
2222

2323
(deftest "schedules contacts for future"
@@ -33,7 +33,7 @@
3333
(if (= 1 (length (day-2 :tasks)))
3434
(let [task ((day-2 :tasks) 0)]
3535
(test (task :title) "Contact John Doe")
36-
(test (task :done) false)
36+
(test (task :state) :open)
3737
(test (empty? (task :body)) true))))
3838

3939
(deftest "schedules contacts with birthday"
@@ -46,7 +46,7 @@
4646
(let [day ((plan :days) 0)
4747
task ((day :tasks) 0)]
4848
(test (task :title) "Congratulate birthday to John Doe")
49-
(test (task :done) false)
49+
(test (task :state) :open)
5050
(test (empty? (task :body)) true)))
5151

5252
(deftest "schedules contacts with missed birthday"
@@ -70,7 +70,7 @@
7070
(def day-1 (day/build-day (d/date 2022 4 26)))
7171
(def day-2 (day/build-day (d/date 2022 4 25)
7272
@[]
73-
@[(task/build-task "Weekly meeting" false)]))
73+
@[(task/build-task "Weekly meeting" :open)]))
7474
(def plan (plan/build-plan :days @[day-1 day-2]))
7575
(schedule-contacts plan @[contact] (d/date 2022 4 26))
7676
(test (not (empty? (day-1 :tasks))) true)
@@ -103,10 +103,10 @@
103103
(def day-1 (day/build-day (d/date 2022 4 27)))
104104
(def day-2 (day/build-day (d/date 2022 4 26)
105105
@[]
106-
@[(task/build-task "Congratulate birthday to John Doe" true)]))
106+
@[(task/build-task "Congratulate birthday to John Doe" :checked)]))
107107
(def day-3 (day/build-day (d/date 2022 4 25)
108108
@[]
109-
@[(task/build-task "Weekly meeting" false)]))
109+
@[(task/build-task "Weekly meeting" :open)]))
110110
(def plan (plan/build-plan :days @[day-1 day-2 day-3]))
111111
(schedule-contacts plan @[contact] (d/date 2022 4 27))
112112
(test (empty? (day-1 :tasks)) true))

test/commands/schedule_tasks_test.janet

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
(def plan (plan/build-plan
145145
:days @[(day/build-day (d/date 2022 8 2)
146146
@[]
147-
@[(task/build-task "Weekly meeting" true)])
147+
@[(task/build-task "Weekly meeting" :checked)])
148148
(day/build-day (d/date 2022 8 1))]))
149149
(test (not (missed? plan scheduled-task (d/date 2022 8 3))) true))
150150

@@ -170,7 +170,7 @@
170170
(let [day ((plan :days) 1)
171171
task ((day :tasks) 0)]
172172
(test (task :title) "Weekly meeting")
173-
(test (task :done) false)
173+
(test (task :state) :open)
174174
(test (task :schedule) "every Monday")))
175175

176176
(deftest "doesn't insert duplicate tasks"
@@ -194,7 +194,7 @@
194194
(let [task ((day :tasks) 0)]
195195
(test (task :title) "Weekly meeting")
196196
(test (d/equal? (d/date 2022 1 17) (task :missed-on)) true)
197-
(test (task :done) false)
197+
(test (task :state) :open)
198198
(test (task :schedule) "every Monday")))))
199199

200200
(deftest "schedules missed monthly tasks"
@@ -221,7 +221,7 @@
221221
(if (not (empty? (day :tasks)))
222222
(let [task ((day :tasks) 0)]
223223
(test (task :title) "Weekly meeting")
224-
(test (task :done) false)
224+
(test (task :state) :open)
225225
(test (task :schedule) "every Monday")))))
226226

227227
(deftest "doesn't schedule tasks that are not scheduled for future day that is not in the plan"

0 commit comments

Comments
 (0)