@@ -130,6 +130,7 @@ type alias Model =
130130, newTask : String
131131, submissionStatus : RemoteData (Graphql.Http.Error Int) Int
132132, now : Posix
133+, tags : List String
133134}
134135135136@@ -187,6 +188,25 @@ viewMaybe maybeValue viewFunc =
187188 viewFunc value
188189189190191+viewTagStr : String -> Html.Styled.Html Msg
192+viewTagStr tagsStr =
193+ span []
194+(tagsStr
195+|> String.split ","
196+|> List.map
197+(\tag ->
198+ a
199+[ css
200+[ text_color blue_400
201+, mr_2
202+]
203+, href <| "/tags/" ++ tag
204+]
205+[ text <| "+" ++ tag ]
206+)
207+)
208+209+190210viewTodo : Posix -> TodoItem -> Html.Styled.Html Msg
191211viewTodo now todo =
192212let
@@ -305,24 +325,7 @@ viewTodo now todo =
305325]
306326[ text due_utc ]
307327)
308-, viewMaybe todo.tags
309-(\tagsStr ->
310- span []
311-(tagsStr
312-|> String.split ","
313-|> List.map
314-(\tag ->
315- a
316-[ css
317-[ text_color blue_400
318-, mr_2
319-]
320-, href <| "/tags/" ++ tag
321-]
322-[ text <| "+" ++ tag ]
323-)
324-)
325-)
328+, viewMaybe todo.tags viewTagStr
326329]
327330, div
328331[ css
@@ -383,9 +386,9 @@ viewBody model =
383386]
384387[ main_
385388[ css [ max_w_3xl, mx_auto, px_4, py_8 ] ]
386-[ nav [ css [ flex ] ]
389+[ nav [ css [ flex, items_baseline ] ]
387390[ h1
388-[ css [ mb_4, inline_block, mr_4, flex_1 ] ]
391+[ css [ mb_4, inline_block, mr_4 ] ]
389392[ a
390393[ href "/"
391394, css
@@ -396,18 +399,28 @@ viewBody model =
396399]
397400[ text "TaskLite" ]
398401]
399-, button
400-[ css
401-[ mb_4
402-, border_none
403-, text_2xl
404-, cursor_pointer
405-, bg_color transparent
406-, dark [ opacity_60, hover [ opacity_100 ] ]
402+, div [ css [ text_color gray_500 ] ]
403+(model.tags
404+|> List.map
405+(\tag ->
406+ span [ css [ mr_2 ] ] [ text <| "+" ++ tag ]
407+)
408+)
409+, div
410+[ css [ flex, flex_1, justify_end ] ]
411+[ button
412+[ css
413+[ mb_4
414+, border_none
415+, text_2xl
416+, cursor_pointer
417+, bg_color transparent
418+, dark [ opacity_60, hover [ opacity_100 ] ]
419+]
420+, onClick ReloadTasks
407421]
408-, onClick ReloadTasks
422+ [ text "🔁" ]
409423]
410-[ text "🔁" ]
411424]
412425, let
413426 inputForm =
@@ -539,34 +552,40 @@ getTodos =
539552540553getTodosWithTag : String -> Cmd Msg
541554getTodosWithTag tag =
542-let
543- setTags filter =
544-{ filter
545-| tags =
555+if String.contains "," tag then
556+-- TODO: Add support for specifying multiple tags
557+Cmd.none
558+559+else
560+let
561+ setTags filter =
562+{ filter
563+| tags =
564+Present <|
565+ buildStringComparison
566+(\c ->
567+{ c
568+| like =
569+Present <| "%" ++ tag ++ "%"
570+}
571+)
572+, closed_utc =
573+Present <|
574+ buildStringComparison (\c -> { c | eq = Null })
575+}
576+in
577+Query.tasks_view
578+(\_ ->
579+{ filter = Present <| buildTasks_view_filter setTags
580+, order_by =
546581Present <|
547- buildStringComparison
548-(\c ->
549-{ c
550-| like =
551-Present <| "%" ++ tag ++ "%"
552-}
553-)
554-, closed_utc =
555-Present <| buildStringComparison (\c -> { c | eq = Null })
556-}
557-in
558-Query.tasks_view
559-(\_ ->
560-{ filter = Present <| buildTasks_view_filter setTags
561-, order_by =
562-Present <|
563- buildTasks_view_order_by
564-(\o -> { o | priority = Present Desc })
565-}
566-)
567- tasksViewSelection
568-|> Graphql.Http.queryRequest graphqlApiUrl
569-|> Graphql.Http.send (RemoteData.fromResult >> GotTasksResponse)
582+ buildTasks_view_order_by
583+(\o -> { o | priority = Present Desc })
584+}
585+)
586+ tasksViewSelection
587+|> Graphql.Http.queryRequest graphqlApiUrl
588+|> Graphql.Http.send (RemoteData.fromResult >> GotTasksResponse)
570589571590572591insertTodo : Posix -> Ulid -> String -> Cmd Msg
@@ -715,24 +734,18 @@ routeParser =
715734]
716735717736718-handleUrl : Url -> Cmd Msg
719-handleUrl url =
720-let
721- route =
722- url
723-|> parse routeParser
724-|> Maybe.withDefault NotFound
725-in
726-case Debug.log "route" route of
737+handleRoute : Route -> Cmd Msg
738+handleRoute route =
739+case route of
727740Home ->
728741Cmd.batch
729742[ getTodos
730743, Task.perform ReceivedTime Time.now
731744]
732745733-Tags tag ->
746+Tags tagStr ->
734747Cmd.batch
735-[ getTodosWithTag tag
748+[ getTodosWithTag tagStr
736749, Task.perform ReceivedTime Time.now
737750]
738751@@ -745,13 +758,24 @@ handleUrl url =
745758746759init : Flags -> Url -> Key -> ( Model, Cmd Msg )
747760init _ url key =
761+let
762+ route =
763+ url |> parse routeParser |> Maybe.withDefault NotFound
764+in
748765( { key = key
749766, remoteTodos = RemoteData.Loading
750767, newTask = ""
751768, submissionStatus = RemoteData.NotAsked
752769, now = Time.millisToPosix 0
770+, tags =
771+case route of
772+Tags tagStr ->
773+String.split "," tagStr
774+775+ _ ->
776+[]
753777}
754-, handleUrl url
778+, handleRoute route
755779)
756780757781@@ -863,7 +887,27 @@ update msg model =
863887)
864888865889UrlChanged url ->
866-( { model | remoteTodos = RemoteData.Loading }, handleUrl url )
890+let
891+ _ =
892+Debug.log "UrlChanged" url
893+894+ route =
895+ url
896+|> parse routeParser
897+|> Maybe.withDefault NotFound
898+in
899+( { model
900+| remoteTodos = RemoteData.Loading
901+, tags =
902+case route of
903+Tags tagStr ->
904+String.split "," tagStr
905+906+ _ ->
907+[]
908+}
909+, handleRoute route
910+)
867911868912ClickedLink urlRequest ->
869913case urlRequest of