about summary refs log tree commit diff
path: root/client/src/User.elm
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-08-02T16·45+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-08-02T16·45+0100
commit90d145189532b3691294ffb6d9326487942df4bc (patch)
tree187841e6f49a19273a3f8a6433982ee5f6e00552 /client/src/User.elm
parente9e84f6a08c0711c498c7f1f0c9aefc39520c7a7 (diff)
Render "<count> days until" for upcoming trips
Per the assignment spec.
Diffstat (limited to 'client/src/User.elm')
-rw-r--r--client/src/User.elm61
1 files changed, 42 insertions, 19 deletions
diff --git a/client/src/User.elm b/client/src/User.elm
index 0c87e85bf98b..84523ef59e01 100644
--- a/client/src/User.elm
+++ b/client/src/User.elm
@@ -71,20 +71,34 @@ createTrip model =
         ]
 
 
-renderTrip : State.Trip -> Html State.Msg
-renderTrip trip =
+renderTrip : Date.Date -> State.Trip -> Html State.Msg
+renderTrip today trip =
     li
         [ [ "py-2" ]
             |> Tailwind.use
             |> class
         ]
-        [ UI.paragraph
-            (Date.toIsoString trip.startDate
-                ++ " - "
-                ++ Date.toIsoString trip.endDate
-                ++ " -> "
-                ++ trip.destination
-            )
+        [ if Date.compare today trip.startDate == GT then
+            UI.paragraph
+                (String.fromInt (Date.diff Date.Days trip.startDate today)
+                    ++ " days until you're travelling to "
+                    ++ trip.destination
+                    ++ " for "
+                    ++ String.fromInt
+                        (Date.diff
+                            Date.Days
+                            trip.startDate
+                            trip.endDate
+                        )
+                    ++ " days."
+                )
+
+          else
+            UI.paragraph
+                (String.fromInt (Date.diff Date.Days today trip.endDate)
+                    ++ " days ago you returned from your trip to "
+                    ++ trip.destination
+                )
         , UI.paragraph ("\"" ++ trip.comment ++ "\"")
         , UI.wrapNoPrint
             (UI.textButton
@@ -98,7 +112,7 @@ renderTrip trip =
 trips : State.Model -> Html State.Msg
 trips model =
     div []
-        [ UI.header 3 "Upcoming Trips"
+        [ UI.header 3 "Your Trips"
         , case model.trips of
             RemoteData.NotAsked ->
                 UI.paragraph "Somehow we've reached the user home page without requesting your trips data. Please report this to our engineering team at bugs@tripplaner.tld"
@@ -110,15 +124,24 @@ trips model =
                 UI.paragraph ("Error: " ++ Utils.explainHttpError e)
 
             RemoteData.Success xs ->
-                div [ [ "mb-10" ] |> Tailwind.use |> class ]
-                    [ ul [ [ "my-4" ] |> Tailwind.use |> class ] (xs |> List.map renderTrip)
-                    , UI.wrapNoPrint
-                        (UI.simpleButton
-                            { label = "Print iternary"
-                            , handleClick = State.PrintPage
-                            }
-                        )
-                    ]
+                case model.todaysDate of
+                    Nothing ->
+                        text ""
+
+                    Just today ->
+                        div [ [ "mb-10" ] |> Tailwind.use |> class ]
+                            [ ul [ [ "my-4" ] |> Tailwind.use |> class ]
+                                (xs
+                                    |> List.sortWith (\x y -> Date.compare y.startDate x.startDate)
+                                    |> List.map (renderTrip today)
+                                )
+                            , UI.wrapNoPrint
+                                (UI.simpleButton
+                                    { label = "Print iternary"
+                                    , handleClick = State.PrintPage
+                                    }
+                                )
+                            ]
         ]