Skip to content

Commit b546b11

Browse files
committed
Set task :state directly
1 parent 125beba commit b546b11

12 files changed

Lines changed: 41 additions & 45 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/task.janet

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55

66
(import ./date)
77

8-
(defn build-task [title done &opt body]
8+
(defn build-task [title state &opt body]
99
(default body @[])
10-
{:title title :body body :state (if done :checked :open)})
10+
{:title title :body body :state state})
1111

1212
(defn build-scheduled-task [line title schedule]
13-
(def task (build-task title false))
13+
(def task (build-task title :open))
1414
(merge task {:line line :schedule schedule}))
1515

1616
(defn build-missed-task [title date &opt body]
17-
(def task (build-task title false body))
17+
(def task (build-task title :open body))
1818
(merge task {:missed-on date}))
1919

2020
(defn build-contact-task [title contact &opt body]
21-
(def task (build-task title false body))
21+
(def task (build-task title :open body))
2222
(merge task {:contact contact}))
2323

2424
(defn mark-as-missed

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 1 addition & 1 deletion
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

test/commands_test.janet

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
:days @[(day/build-day today)
5353
(day/build-day (d/date 2020 8 4))
5454
(day/build-day (d/date 2020 8 2) @[]
55-
@[(task/build-task "Buy milk" true)])]))
55+
@[(task/build-task "Buy milk" :checked)])]))
5656
(def arguments {"skip-backup" true "remove-empty-days" true "insert-days" "3"})
5757
(def {:plan new-plan :errors errors} (run-commands plan file-path arguments))
5858
(def days (new-plan :days))
@@ -69,7 +69,7 @@
6969
:days @[(day/build-day today)
7070
(day/build-day (d/date 2020 8 4))
7171
(day/build-day (d/date 2020 8 2) @[]
72-
@[(task/build-task "Buy milk" true)])]))
72+
@[(task/build-task "Buy milk" :checked)])]))
7373
(def arguments {"skip-backup" true "remove-empty-days" true "insert-days" "three"})
7474
(def {:plan new-plan :errors errors} (run-commands plan file-path arguments))
7575
(def days (new-plan :days))

test/day_test.janet

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,26 @@
2727
true)
2828
(test (not (empty-day? (build-day (d/date 2020 8 1)
2929
@[]
30-
@[(task/build-task "Buy milk" true)])))
30+
@[(task/build-task "Buy milk" :checked)])))
3131
true))
3232

3333
## —————————————————————————————————————————————————————————————————————————————————————————————————
3434
## Test add-tasks
3535

3636
(deftest "adds tasks to the day"
3737
(def day (build-day (d/date 2020 8 1)))
38-
(add-tasks day @[(task/build-task "Buy milk" true)
39-
(task/build-task "Fix the lamp" false)])
38+
(add-tasks day @[(task/build-task "Buy milk" :checked)
39+
(task/build-task "Fix the lamp" :open)])
4040
(test (length (day :tasks)) 2)
4141
(test (((day :tasks) 0) :title) "Buy milk")
4242
(test (((day :tasks) 1) :title) "Fix the lamp"))
4343

4444
(deftest "doesn't add duplicate tasks"
4545
(def day (build-day (d/date 2020 8 1)
4646
@[]
47-
@[(task/build-task "Fix the lamp" false)]))
48-
(add-tasks day @[(task/build-task "Buy milk" true)
49-
(task/build-task "Fix the lamp" false)])
47+
@[(task/build-task "Fix the lamp" :open)]))
48+
(add-tasks day @[(task/build-task "Buy milk" :checked)
49+
(task/build-task "Fix the lamp" :open)])
5050
(test (length (day :tasks)) 2)
5151
(test (((day :tasks) 0) :title) "Fix the lamp")
5252
(test (((day :tasks) 1) :title) "Buy milk"))

test/plan/serializer_test.janet

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
(def plan
1212
(plan/build-plan
1313
:title "Main TODO"
14-
:inbox @[(task/build-task "Fix the lamp" false)]
14+
:inbox @[(task/build-task "Fix the lamp" :open)]
1515
:days @[(day/build-day (d/date 2020 8 3))
1616
(day/build-day (d/date 2020 8 2))
1717
(day/build-day (d/date 2020 8 1)
1818
@[(event/build-event "Talked to Mike" @["- He has a new car"])]
19-
@[(task/build-task "Develop photos" false)
20-
(task/build-task "Pay bills" true @["- Electricity" "- Water"])
19+
@[(task/build-task "Develop photos" :open)
20+
(task/build-task "Pay bills" :checked @["- Electricity" "- Water"])
2121
(task/build-missed-task "Organize photos" (d/date 2020 7 20))])
2222
(day/build-day (d/date 2020 7 31)
2323
@[]
24-
@[(task/build-task "Review open pull requests" true)
25-
(task/build-task "Fix the flaky test" true)])]))
24+
@[(task/build-task "Review open pull requests" :checked)
25+
(task/build-task "Fix the flaky test" :checked)])]))
2626
(def plan-string
2727
```
2828
# Main TODO

0 commit comments

Comments
 (0)