@@ -21,7 +21,7 @@ import Css exposing (hover, url)
21
21
import Css.Media exposing (withMediaQuery )
22
22
import Graphql.Http
23
23
import Graphql.OptionalArgument exposing (OptionalArgument (..) )
24
- import Graphql.SelectionSet as SelectionSet exposing (SelectionSet )
24
+ import Graphql.SelectionSet as SelectionSet exposing (SelectionSet , with )
25
25
import Html.Styled
26
26
exposing
27
27
( a
76
76
type alias TodoItem =
77
77
{ ulid : Maybe String
78
78
, body : Maybe String
79
+ , state : Maybe String
79
80
, closed_utc : Maybe String
80
81
, due_utc : Maybe String
81
82
, review_utc : Maybe String
@@ -89,6 +90,7 @@ emptyTodo : TodoItem
89
90
emptyTodo =
90
91
{ ulid = Nothing
91
92
, body = Nothing
93
+ , state = Nothing
92
94
, closed_utc = Nothing
93
95
, due_utc = Nothing
94
96
, review_utc = Nothing
@@ -111,8 +113,7 @@ type Msg
111
113
| AddTaskAt Posix
112
114
| AddTask Posix Ulid
113
115
| InsertAffectedRowsResponse ( RemoteData ( Graphql . Http . Error Int ) Int )
114
- | SetCompletedNow String
115
- | SetCompletedAt Posix String
116
+ | SetDone String
116
117
| CompleteAffectedRowsResponse ( RemoteData ( Graphql . Http . Error Int ) Int )
117
118
| DeleteTask String
118
119
| DeleteAffectedRowsResponse ( RemoteData ( Graphql . Http . Error Int ) Int )
@@ -272,7 +273,7 @@ viewTodo now todo =
272
273
onCheck
273
274
( \ bool ->
274
275
if bool then
275
- SetCompletedNow ulid
276
+ SetDone ulid
276
277
277
278
else
278
279
-- TODO: Implement
@@ -519,28 +520,30 @@ view model =
519
520
520
521
tasksHeadSelection : SelectionSet TodoItem Tasks_head_row
521
522
tasksHeadSelection =
522
- SelectionSet . map8 TodoItem
523
- Tasks_head_row . ulid
524
- Tasks_head_row . body
525
- Tasks_head_row . closed_utc
526
- Tasks_head_row . due_utc
527
- Tasks_head_row . review_utc
528
- Tasks_head_row . tags
529
- Tasks_head_row . repetition_duration
530
- Tasks_head_row . recurrence_duration
523
+ SelectionSet . succeed TodoItem
524
+ |> with Tasks_head_row . ulid
525
+ |> with Tasks_head_row . body
526
+ |> with Tasks_head_row . state
527
+ |> with Tasks_head_row . closed_utc
528
+ |> with Tasks_head_row . due_utc
529
+ |> with Tasks_head_row . review_utc
530
+ |> with Tasks_head_row . tags
531
+ |> with Tasks_head_row . repetition_duration
532
+ |> with Tasks_head_row . recurrence_duration
531
533
532
534
533
535
tasksViewSelection : SelectionSet TodoItem Tasks_view_row
534
536
tasksViewSelection =
535
- SelectionSet . map8 TodoItem
536
- Tasks_view_row . ulid
537
- Tasks_view_row . body
538
- Tasks_view_row . closed_utc
539
- Tasks_view_row . due_utc
540
- Tasks_view_row . review_utc
541
- Tasks_view_row . tags
542
- Tasks_view_row . repetition_duration
543
- Tasks_view_row . recurrence_duration
537
+ SelectionSet . succeed TodoItem
538
+ |> with Tasks_view_row . ulid
539
+ |> with Tasks_view_row . body
540
+ |> with Tasks_view_row . state
541
+ |> with Tasks_view_row . closed_utc
542
+ |> with Tasks_view_row . due_utc
543
+ |> with Tasks_view_row . review_utc
544
+ |> with Tasks_view_row . tags
545
+ |> with Tasks_view_row . repetition_duration
546
+ |> with Tasks_view_row . recurrence_duration
544
547
545
548
546
549
getTodos : Cmd Msg
@@ -628,11 +631,11 @@ insertTodo now ulid body =
628
631
( RemoteData . fromResult >> InsertAffectedRowsResponse )
629
632
630
633
631
- {- | Set task as completed (aka set `closed_utc`)
632
- TODO: Allow completing repetition and recurrence tasks
634
+ {- | Set task as done
635
+ TODO: Support completing repetition and recurrence tasks
633
636
-}
634
- setTodoCompleted : Posix -> String -> Cmd Msg
635
- setTodoCompleted closedUtc ulid =
637
+ setTodoCompleted : String -> Cmd Msg
638
+ setTodoCompleted ulid =
636
639
Mutation . update_tasks
637
640
{ filter =
638
641
buildTasks_filter
@@ -656,22 +659,25 @@ setTodoCompleted closedUtc ulid =
656
659
}
657
660
)
658
661
, set =
659
- { closed_utc = Present ( Iso8601 . fromTime closedUtc)
662
+ { state = Present " Done" -- SQL trigger will update `closed_utc`
663
+
664
+ -- TODO: Figure out why setting `modified_utc`
665
+ -- prevents recursive trigger calls
666
+ , modified_utc = Present " "
660
667
661
668
--
669
+ , closed_utc = Absent
662
670
, awake_utc = Absent
663
671
, body = Absent
664
672
, due_utc = Absent
665
673
, group_ulid = Absent
666
674
, metadata = Absent
667
- , modified_utc = Absent
668
675
, priority_adjustment = Absent
669
676
, ready_utc = Absent
670
677
, recurrence_duration = Absent
671
678
, repetition_duration = Absent
672
679
, review_utc = Absent
673
680
, rowid = Absent
674
- , state = Absent
675
681
, ulid = Absent
676
682
, user = Absent
677
683
, waiting_utc = Absent
@@ -835,31 +841,22 @@ update msg model =
835
841
, getTodos
836
842
)
837
843
838
- SetCompletedNow ulid ->
839
- ( { model | submissionStatus = RemoteData . Loading }
840
- , Task . perform ( \ time -> SetCompletedAt time ulid) Time . now
841
- )
842
-
843
- SetCompletedAt time ulid ->
844
+ SetDone ulid ->
844
845
( { model
845
846
| remoteTodos =
846
847
model. remoteTodos
847
848
|> RemoteData . map
848
849
( List . map
849
850
( \ todo ->
850
851
if todo. ulid == Just ulid then
851
- { todo
852
- | closed_utc =
853
- Just <|
854
- Iso8601 . fromTime time
855
- }
852
+ { todo | state = Just " Done" }
856
853
857
854
else
858
855
todo
859
856
)
860
857
)
861
858
}
862
- , setTodoCompleted time ulid
859
+ , setTodoCompleted ulid
863
860
)
864
861
865
862
CompleteAffectedRowsResponse response ->
0 commit comments