aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm')
-rw-r--r--src/client/elm/Main.elm26
-rw-r--r--src/client/elm/Model.elm20
-rw-r--r--src/client/elm/Model/View/SignInView.elm6
-rw-r--r--src/client/elm/Update.elm5
-rw-r--r--src/client/elm/View/SignIn.elm2
5 files changed, 35 insertions, 24 deletions
diff --git a/src/client/elm/Main.elm b/src/client/elm/Main.elm
index 06b5ec3..c3d5192 100644
--- a/src/client/elm/Main.elm
+++ b/src/client/elm/Main.elm
@@ -7,6 +7,7 @@ import Graphics.Element exposing (..)
import Html exposing (Html)
import StartApp exposing (App)
import Effects exposing (Effects, Never)
+import Json.Decode as Json
import Task exposing (..)
import Time exposing (..)
@@ -20,18 +21,26 @@ import View exposing (view)
import Server
+import Utils.Maybe exposing (isJust)
+
main : Signal Html
main = app.html
app : App Model
app = StartApp.start
{ init =
- ( initialModel initialTime translations conf
- , Server.init
- |> Task.map GoLoggedInView
- |> flip Task.onError (always <| Task.succeed GoSignInView)
- |> Effects.task
- )
+ case Json.decodeString Json.string signInError of
+ Ok signInError ->
+ ( initialModel initialTime translations conf (Just signInError)
+ , Effects.none
+ )
+ Err _ ->
+ ( initialModel initialTime translations conf Nothing
+ , Server.init
+ |> Task.map GoLoggedInView
+ |> flip Task.onError (always <| Task.succeed GoSignInView)
+ |> Effects.task
+ )
, view = view
, update = update
, inputs = [ Signal.map UpdateTime (Time.every 1000) ]
@@ -45,7 +54,4 @@ port tasks = app.tasks
port initialTime : Time
port translations : String
port conf : String
-
--- Output ports
-
-port signInError : Maybe String
+port signInError : String
diff --git a/src/client/elm/Model.elm b/src/client/elm/Model.elm
index 5dc6692..7852c9a 100644
--- a/src/client/elm/Model.elm
+++ b/src/client/elm/Model.elm
@@ -7,9 +7,12 @@ import Time exposing (Time)
import Json.Decode as Json
import Model.View exposing (..)
+import Model.View.SignInView exposing (initSignInView)
import Model.Translations exposing (..)
import Model.Conf exposing (..)
+import Utils.Maybe exposing (isJust)
+
type alias Model =
{ view : View
, currentTime : Time
@@ -17,16 +20,19 @@ type alias Model =
, conf : Conf
}
-initialModel : Time -> String -> String -> Model
-initialModel initialTime translationsValue confValue =
- { view = LoadingView
+initialModel : Time -> String -> String -> Maybe String -> Model
+initialModel initialTime translations conf mbSignInError =
+ { view =
+ if isJust mbSignInError
+ then SignInView (initSignInView mbSignInError)
+ else LoadingView
, currentTime = initialTime
, translations =
- case Json.decodeString translationsDecoder translationsValue of
+ case Json.decodeString translationsDecoder translations of
Ok translations -> translations
- Err err -> []
+ Err _ -> []
, conf =
- case Json.decodeString confDecoder confValue of
+ case Json.decodeString confDecoder conf of
Ok conf -> conf
- Err err -> { currency = "" }
+ Err _ -> { currency = "" }
}
diff --git a/src/client/elm/Model/View/SignInView.elm b/src/client/elm/Model/View/SignInView.elm
index 0d69445..f72d05a 100644
--- a/src/client/elm/Model/View/SignInView.elm
+++ b/src/client/elm/Model/View/SignInView.elm
@@ -9,9 +9,9 @@ type alias SignInView =
, result : Maybe (Result String String)
}
-initSignInView : SignInView
-initSignInView =
+initSignInView : Maybe String -> SignInView
+initSignInView mbSignInError =
{ login = ""
, waitingServer = False
- , result = Nothing
+ , result = Maybe.map Err mbSignInError
}
diff --git a/src/client/elm/Update.elm b/src/client/elm/Update.elm
index adb90ab..1625167 100644
--- a/src/client/elm/Update.elm
+++ b/src/client/elm/Update.elm
@@ -34,8 +34,7 @@ update action model =
, Server.signIn email
|> Task.map (always (UpdateSignIn SignInAction.ValidLogin))
|> flip Task.onError (\error ->
- let errorMessage = getMessage (errorKey error) model.translations
- in Task.succeed (UpdateSignIn (SignInAction.ErrorLogin errorMessage))
+ Task.succeed (UpdateSignIn (SignInAction.ErrorLogin (errorKey error)))
)
|> Effects.task
)
@@ -49,7 +48,7 @@ update action model =
({ model | currentTime = time }, Effects.none)
GoSignInView ->
- ({ model | view = V.SignInView initSignInView }, Effects.none)
+ ({ model | view = V.SignInView (initSignInView Nothing) }, Effects.none)
UpdateSignIn signInAction ->
(applySignIn model signInAction, Effects.none)
diff --git a/src/client/elm/View/SignIn.elm b/src/client/elm/View/SignIn.elm
index 6fba764..acff960 100644
--- a/src/client/elm/View/SignIn.elm
+++ b/src/client/elm/View/SignIn.elm
@@ -57,6 +57,6 @@ signInResult model signInView =
Err error ->
div
[ class "error" ]
- [ text error ]
+ [ text (getMessage error model.translations) ]
Nothing ->
text ""