Use routes to navigate.

This commit is contained in:
2018-12-08 19:09:20 -08:00
parent 7d97fc1aba
commit e492452451
4 changed files with 38 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ module Scylla.Model exposing (..)
import Scylla.Api exposing (..)
import Scylla.Sync exposing (SyncResponse, JoinedRoom)
import Scylla.Login exposing (LoginResponse, Username, Password)
import Scylla.Route exposing (Route)
import Browser.Navigation as Nav
import Dict exposing (Dict)
import Browser
@@ -10,6 +11,7 @@ import Url exposing (Url)
type alias Model =
{ key : Nav.Key
, route : Route
, token : Maybe ApiToken
, loginUsername : Username
, loginPassword : Password
@@ -24,7 +26,7 @@ type Msg =
| ChangeLoginPassword Password -- During login screen: the password
| AttemptLogin -- During login screen, login button presed
| TryUrl Browser.UrlRequest -- User attempts to change URL
| ChangeUrl Url -- URL changes
| ChangeRoute Route -- URL changes
| ReceiveSyncResponse (Result Http.Error SyncResponse) -- HTTP, Sync has finished
| ReceiveLoginResponse (Result Http.Error LoginResponse) -- HTTP, Login has finished

18
src/Scylla/Route.elm Normal file
View File

@@ -0,0 +1,18 @@
module Scylla.Route exposing (..)
import Url.Parser exposing (Parser, oneOf, map, s, string, (</>), top)
type alias RoomId = String
type Route =
Base
| Unknown
| Login
| Room RoomId
route : Parser (Route -> a) a
route =
oneOf
[ map Base top
, map Login (s "login")
, map Room (s "room" </> string)
]

View File

@@ -1,6 +1,7 @@
module Scylla.Views exposing (..)
import Scylla.Model exposing (..)
import Scylla.Sync exposing (..)
import Scylla.Route exposing (..)
import Json.Decode as Decode
import Html exposing (Html, div, input, text, button, div, span)
import Html.Attributes exposing (type_, value)
@@ -10,9 +11,11 @@ import Dict
viewFull : Model -> List (Html Msg)
viewFull model =
let
core = case model.token of
Just _ -> normalView model
Nothing -> loginView model
core = case model.route of
Login -> loginView model
Base -> normalView model
Room r -> normalView model
_ -> div [] []
errorList = errorsView model.errors
in
[ errorList ] ++ [ core ]