diff options
author | Joris | 2016-03-23 00:45:33 +0100 |
---|---|---|
committer | Joris | 2016-03-23 00:46:53 +0100 |
commit | a11ad41b52ed3682d33382f2a378bf3294d688b2 (patch) | |
tree | f1d0f7835965ebcc6a61225186cad6b5de565bca /src/client | |
parent | 32db6a74d8578f993dd1cce3367fc7615ec730cd (diff) |
Sign in token link to /
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/elm/Main.elm | 26 | ||||
-rw-r--r-- | src/client/elm/Model.elm | 20 | ||||
-rw-r--r-- | src/client/elm/Model/View/SignInView.elm | 6 | ||||
-rw-r--r-- | src/client/elm/Update.elm | 5 | ||||
-rw-r--r-- | src/client/elm/View/SignIn.elm | 2 | ||||
-rw-r--r-- | src/client/js/main.js | 14 |
6 files changed, 40 insertions, 33 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 "" diff --git a/src/client/js/main.js b/src/client/js/main.js index 4c7e2df..0928ab5 100644 --- a/src/client/js/main.js +++ b/src/client/js/main.js @@ -1,13 +1,9 @@ +// Remove query params +window.history.pushState({html: document.documentElement.innerHTML, pageTitle: document.title}, '', '/'); + Elm.fullscreen(Elm.Main, { - signInError: getParameterByName('signInError'), initialTime: new Date().getTime(), translations: document.getElementById('messages').innerHTML, - conf: document.getElementById('conf').innerHTML + conf: document.getElementById('conf').innerHTML, + signInError: document.getElementById('signInError').innerHTML }); - -function getParameterByName(name) { - name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); - var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), - results = regex.exec(location.search); - return results && decodeURIComponent(results[1].replace(/\+/g, " ")); -} |