aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Model.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm/Model.elm')
-rw-r--r--src/client/elm/Model.elm64
1 files changed, 37 insertions, 27 deletions
diff --git a/src/client/elm/Model.elm b/src/client/elm/Model.elm
index b4213d5..9e9cdbb 100644
--- a/src/client/elm/Model.elm
+++ b/src/client/elm/Model.elm
@@ -1,13 +1,14 @@
-module Model
+module Model exposing
( Model
- , initialModel
- ) where
+ , init
+ )
import Time exposing (Time)
import Json.Decode as Json
-import TransitRouter
-import Route exposing (Route)
+import Page exposing (Page)
+import Init as Init exposing (Init)
+import Msg exposing (Msg)
import Model.View exposing (..)
import Model.Translations exposing (..)
@@ -24,27 +25,36 @@ type alias Model =
, currentTime : Time
, translations : Translations
, conf : Conf
- , transitRouter : TransitRouter.TransitRouter Route
+ , page : Page
}
-initialModel : Time -> String -> String -> InitResult -> Model
-initialModel initialTime translations conf initResult =
- { view =
- case initResult of
- InitEmpty ->
- SignInView (SignInModel.init Nothing)
- InitSuccess init ->
- LoggedInView (LoggedInModel.init init)
- InitError error ->
- SignInView (SignInModel.init (Just error))
- , currentTime = initialTime
- , translations =
- case Json.decodeString translationsDecoder translations of
- Ok translations -> translations
- Err _ -> []
- , conf =
- case Json.decodeString confDecoder conf of
- Ok conf -> conf
- Err _ -> { currency = "" }
- , transitRouter = TransitRouter.empty Route.Empty
- }
+init : Json.Value -> Result String Page -> (Model, Cmd Msg)
+init payload result =
+ let page =
+ case result of
+ Err _ -> Page.Home
+ Ok page -> page
+ model =
+ case Json.decodeValue Init.decoder payload of
+ Ok { time, translations, conf, result } ->
+ { view =
+ case result of
+ InitEmpty ->
+ SignInView (SignInModel.init Nothing)
+ InitSuccess init ->
+ LoggedInView (LoggedInModel.init init)
+ InitError error ->
+ SignInView (SignInModel.init (Just error))
+ , currentTime = time
+ , translations = translations
+ , conf = conf
+ , page = page
+ }
+ Err error ->
+ { view = SignInView (SignInModel.init (Just error))
+ , currentTime = 0
+ , translations = []
+ , conf = { currency = "" }
+ , page = page
+ }
+ in (model, Cmd.none)