From 8e3a7bf1cb83bbb6e3dcd54308eefa52a29cd679 Mon Sep 17 00:00:00 2001 From: Joris Date: Fri, 3 Jun 2016 20:27:16 +0200 Subject: Migrate to elm 0.17 --- src/client/elm/Model.elm | 64 ++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 27 deletions(-) (limited to 'src/client/elm/Model.elm') 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) -- cgit v1.2.3