diff options
-rw-r--r-- | client/elm.json | 4 | ||||
-rw-r--r-- | client/src/Client.elm | 35 |
2 files changed, 30 insertions, 9 deletions
diff --git a/client/elm.json b/client/elm.json index dea3450..4fdc946 100644 --- a/client/elm.json +++ b/client/elm.json @@ -8,12 +8,12 @@ "direct": { "elm/browser": "1.0.2", "elm/core": "1.0.5", - "elm/html": "1.0.0" + "elm/html": "1.0.0", + "elm/url": "1.0.0" }, "indirect": { "elm/json": "1.1.3", "elm/time": "1.0.0", - "elm/url": "1.0.0", "elm/virtual-dom": "1.0.2" } }, diff --git a/client/src/Client.elm b/client/src/Client.elm index 77168c1..cc144e2 100644 --- a/client/src/Client.elm +++ b/client/src/Client.elm @@ -1,20 +1,41 @@ module Client exposing (main) import Browser -import Html +import Html exposing (Html) +import Url exposing (Url) type Message = Ignore -main : Program () () Message +type Model + = Error String + | JoinRoom + { id : String + } + +parseRoomId : Url -> Result String String +parseRoomId url = case String.split "/" url.path of + _ :: "rooms" :: roomId :: _ -> Ok roomId + _ -> Err <| "Invalid path: " ++ url.path + +view : Model -> List (Html Message) +view model = case model of + Error str -> + [ Html.h1 [] [Html.text "Error"] + , Html.p [] [Html.text str] + ] + JoinRoom room -> + [ Html.h1 [] [Html.text <| "Room " ++ room.id] + ] + +main : Program () Model Message main = Browser.application - { init = \() url key -> ((), Cmd.none) + { init = \() url key -> case parseRoomId url of + Err str -> (Error <| "Could not parse room ID: " ++ str, Cmd.none) + Ok roomId -> (JoinRoom {id = roomId}, Cmd.none) , update = \_ model -> (model, Cmd.none) , subscriptions = \_ -> Sub.none - , view = \model -> - { title = "Client" - , body = [Html.h1 [] [Html.text "Hi"]] - } + , view = \model -> {title = "Client", body = view model} , onUrlChange = \url -> Ignore , onUrlRequest = \urlRequest -> Ignore } |