aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Model.elm
blob: e006e97ee02e2bee3b55a107f1d7314bcd8798cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module Model
  ( Model
  , initialModel
  ) where

import Time exposing (Time)
import Json.Decode as Json

import TransitRouter
import Route exposing (..)

import Model.View exposing (..)
import Model.Translations exposing (..)
import Model.Conf exposing (..)

import SignIn.Model as SignInModel

import Utils.Maybe exposing (isJust)

type alias Model =
  { view : View
  , currentTime : Time
  , translations : Translations
  , conf : Conf
  , transitRouter : TransitRouter.TransitRouter Route
  }

initialModel : Time -> String -> String -> Maybe String -> Model
initialModel initialTime translations conf mbSignInError =
  { view =
      if isJust mbSignInError
        then SignInView (SignInModel.init mbSignInError)
        else LoadingView
  , 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 Home
  }