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-02T19·56+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-08-02T19·56+0100
commitc2419cd9127c0077561c6f2c4c801998d231cc41 (patch)
tree3715b5e8db3615389af36821e062933f355ecbe1 /client/src/User.elm
parent239ff24c95458fdff0706b99b8dab9d2fc8c8386 (diff)
Support updating trips from the client
Edit existing trips.
Diffstat (limited to 'client/src/User.elm')
-rw-r--r--client/src/User.elm75
1 files changed, 74 insertions, 1 deletions
diff --git a/client/src/User.elm b/client/src/User.elm
index 84523ef59e01..87871b78dbc4 100644
--- a/client/src/User.elm
+++ b/client/src/User.elm
@@ -71,6 +71,61 @@ createTrip model =
         ]
 
 
+renderEditTrip : State.Model -> State.Trip -> Html State.Msg
+renderEditTrip model trip =
+    li []
+        [ div []
+            [ UI.textField
+                { handleInput = State.UpdateEditTripDestination
+                , inputId = "edit-trip-destination"
+                , inputValue = model.editTripDestination
+                , pholder = "Destination"
+                }
+            , UI.textField
+                { handleInput = State.UpdateEditTripComment
+                , inputId = "edit-trip-comment"
+                , inputValue = model.editTripComment
+                , pholder = "Comment"
+                }
+            ]
+        , div []
+            [ UI.baseButton
+                { enabled =
+                    case model.updateTripStatus of
+                        RemoteData.Loading ->
+                            False
+
+                        _ ->
+                            True
+                , extraClasses = []
+                , label =
+                    case model.updateTripStatus of
+                        RemoteData.Loading ->
+                            "Saving..."
+
+                        _ ->
+                            "Save"
+                , handleClick =
+                    State.AttemptUpdateTrip
+                        { username = trip.username
+                        , destination = trip.destination
+                        , startDate = trip.startDate
+                        }
+                        { username = trip.username
+                        , destination = model.editTripDestination
+                        , startDate = trip.startDate
+                        , endDate = trip.endDate
+                        , comment = model.editTripComment
+                        }
+                }
+            , UI.simpleButton
+                { label = "Cancel"
+                , handleClick = State.CancelEditTrip
+                }
+            ]
+        ]
+
+
 renderTrip : Date.Date -> State.Trip -> Html State.Msg
 renderTrip today trip =
     li
@@ -102,6 +157,12 @@ renderTrip today trip =
         , UI.paragraph ("\"" ++ trip.comment ++ "\"")
         , UI.wrapNoPrint
             (UI.textButton
+                { label = "Edit"
+                , handleClick = State.EditTrip trip
+                }
+            )
+        , UI.wrapNoPrint
+            (UI.textButton
                 { label = "Delete"
                 , handleClick = State.AttemptDeleteTrip trip
                 }
@@ -133,7 +194,19 @@ trips model =
                             [ ul [ [ "my-4" ] |> Tailwind.use |> class ]
                                 (xs
                                     |> List.sortWith (\x y -> Date.compare y.startDate x.startDate)
-                                    |> List.map (renderTrip today)
+                                    |> List.map
+                                        (\trip ->
+                                            case model.editingTrip of
+                                                Nothing ->
+                                                    renderTrip today trip
+
+                                                Just x ->
+                                                    if x == trip then
+                                                        renderEditTrip model trip
+
+                                                    else
+                                                        renderTrip today trip
+                                        )
                                 )
                             , UI.wrapNoPrint
                                 (UI.simpleButton