Render "<count> days until" for upcoming trips
Per the assignment spec.
This commit is contained in:
parent
e9e84f6a08
commit
90d1451895
1 changed files with 42 additions and 19 deletions
|
@ -71,20 +71,34 @@ createTrip model =
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
renderTrip : State.Trip -> Html State.Msg
|
renderTrip : Date.Date -> State.Trip -> Html State.Msg
|
||||||
renderTrip trip =
|
renderTrip today trip =
|
||||||
li
|
li
|
||||||
[ [ "py-2" ]
|
[ [ "py-2" ]
|
||||||
|> Tailwind.use
|
|> Tailwind.use
|
||||||
|> class
|
|> class
|
||||||
]
|
]
|
||||||
[ UI.paragraph
|
[ if Date.compare today trip.startDate == GT then
|
||||||
(Date.toIsoString trip.startDate
|
UI.paragraph
|
||||||
++ " - "
|
(String.fromInt (Date.diff Date.Days trip.startDate today)
|
||||||
++ Date.toIsoString trip.endDate
|
++ " days until you're travelling to "
|
||||||
++ " -> "
|
++ trip.destination
|
||||||
++ 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.paragraph ("\"" ++ trip.comment ++ "\"")
|
||||||
, UI.wrapNoPrint
|
, UI.wrapNoPrint
|
||||||
(UI.textButton
|
(UI.textButton
|
||||||
|
@ -98,7 +112,7 @@ renderTrip trip =
|
||||||
trips : State.Model -> Html State.Msg
|
trips : State.Model -> Html State.Msg
|
||||||
trips model =
|
trips model =
|
||||||
div []
|
div []
|
||||||
[ UI.header 3 "Upcoming Trips"
|
[ UI.header 3 "Your Trips"
|
||||||
, case model.trips of
|
, case model.trips of
|
||||||
RemoteData.NotAsked ->
|
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"
|
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)
|
UI.paragraph ("Error: " ++ Utils.explainHttpError e)
|
||||||
|
|
||||||
RemoteData.Success xs ->
|
RemoteData.Success xs ->
|
||||||
div [ [ "mb-10" ] |> Tailwind.use |> class ]
|
case model.todaysDate of
|
||||||
[ ul [ [ "my-4" ] |> Tailwind.use |> class ] (xs |> List.map renderTrip)
|
Nothing ->
|
||||||
, UI.wrapNoPrint
|
text ""
|
||||||
(UI.simpleButton
|
|
||||||
{ label = "Print iternary"
|
Just today ->
|
||||||
, handleClick = State.PrintPage
|
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
|
||||||
|
}
|
||||||
|
)
|
||||||
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue