aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorJasper Van der Jeugt2020-07-29 17:19:07 +0200
committerJasper Van der Jeugt2020-07-29 17:19:07 +0200
commit676bf9936b9b51e24979657d50d8f019b2f64ac2 (patch)
tree8265c4d0759edca8bd14db51e148c27deba2f645 /client
parentd6265dd7f44538858989c1fe6837e1cafc489455 (diff)
Parse room ID
Diffstat (limited to 'client')
-rw-r--r--client/elm.json4
-rw-r--r--client/src/Client.elm35
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
}