Compare commits
2 Commits
720e6db334
...
471f5b301b
Author | SHA1 | Date | |
---|---|---|---|
471f5b301b | |||
6f1e3da27b |
12
src/Main.elm
12
src/Main.elm
|
@ -3,15 +3,18 @@ import Browser.Navigation as Nav
|
||||||
import Browser.Dom exposing (Viewport, setViewportOf)
|
import Browser.Dom exposing (Viewport, setViewportOf)
|
||||||
import Scylla.Sync exposing (..)
|
import Scylla.Sync exposing (..)
|
||||||
import Scylla.Login exposing (..)
|
import Scylla.Login exposing (..)
|
||||||
|
import Scylla.Api exposing (..)
|
||||||
import Scylla.Model exposing (..)
|
import Scylla.Model exposing (..)
|
||||||
import Scylla.Http exposing (..)
|
import Scylla.Http exposing (..)
|
||||||
import Scylla.Views exposing (viewFull)
|
import Scylla.Views exposing (viewFull)
|
||||||
import Scylla.Route exposing (Route(..))
|
import Scylla.Route exposing (Route(..))
|
||||||
import Scylla.UserData exposing (..)
|
import Scylla.UserData exposing (..)
|
||||||
import Scylla.Notification exposing (..)
|
import Scylla.Notification exposing (..)
|
||||||
|
import Scylla.Storage exposing (..)
|
||||||
import Url exposing (Url)
|
import Url exposing (Url)
|
||||||
import Url.Parser exposing (parse)
|
import Url.Parser exposing (parse)
|
||||||
import Url.Builder
|
import Url.Builder
|
||||||
|
import Json.Encode
|
||||||
import Html exposing (div, text)
|
import Html exposing (div, text)
|
||||||
import Http
|
import Http
|
||||||
import Dict
|
import Dict
|
||||||
|
@ -65,7 +68,7 @@ update msg model = case msg of
|
||||||
ChangeRoute r -> updateChangeRoute model r
|
ChangeRoute r -> updateChangeRoute model r
|
||||||
ViewportAfterMessage v -> updateViewportAfterMessage model v
|
ViewportAfterMessage v -> updateViewportAfterMessage model v
|
||||||
ViewportChangeComplete _ -> (model, Cmd.none)
|
ViewportChangeComplete _ -> (model, Cmd.none)
|
||||||
ReceiveLoginResponse r -> updateLoginResponse model r
|
ReceiveLoginResponse a r -> updateLoginResponse model a r
|
||||||
ReceiveFirstSyncResponse r -> updateSyncResponse model r False
|
ReceiveFirstSyncResponse r -> updateSyncResponse model r False
|
||||||
ReceiveSyncResponse r -> updateSyncResponse model r True
|
ReceiveSyncResponse r -> updateSyncResponse model r True
|
||||||
ReceiveUserData s r -> updateUserData model s r
|
ReceiveUserData s r -> updateUserData model s r
|
||||||
|
@ -117,11 +120,12 @@ updateTryUrl m ur = case ur of
|
||||||
Internal u -> (m, Nav.pushUrl m.key (Url.toString u))
|
Internal u -> (m, Nav.pushUrl m.key (Url.toString u))
|
||||||
_ -> (m, Cmd.none)
|
_ -> (m, Cmd.none)
|
||||||
|
|
||||||
updateLoginResponse : Model -> Result Http.Error LoginResponse -> (Model, Cmd Msg)
|
updateLoginResponse : Model -> ApiUrl -> Result Http.Error LoginResponse -> (Model, Cmd Msg)
|
||||||
updateLoginResponse model r = case r of
|
updateLoginResponse model a r = case r of
|
||||||
Ok lr -> ( { model | token = Just lr.accessToken, loginUsername = lr.userId } , Cmd.batch
|
Ok lr -> ( { model | token = Just lr.accessToken, loginUsername = lr.userId, apiUrl = a }, Cmd.batch
|
||||||
[ firstSync model.apiUrl lr.accessToken
|
[ firstSync model.apiUrl lr.accessToken
|
||||||
, Nav.pushUrl model.key <| Url.Builder.absolute [] []
|
, Nav.pushUrl model.key <| Url.Builder.absolute [] []
|
||||||
|
, setStoreValuePort ("scylla.loginInfo", Json.Encode.string (lr.accessToken ++ "\n" ++ model.apiUrl))
|
||||||
] )
|
] )
|
||||||
Err e -> (model, Cmd.none)
|
Err e -> (model, Cmd.none)
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ login apiUrl username password = request
|
||||||
] )
|
] )
|
||||||
, ("password", string password)
|
, ("password", string password)
|
||||||
]
|
]
|
||||||
, expect = expectJson ReceiveLoginResponse loginResponseDecoder
|
, expect = expectJson (ReceiveLoginResponse apiUrl) loginResponseDecoder
|
||||||
, timeout = Nothing
|
, timeout = Nothing
|
||||||
, tracker = Nothing
|
, tracker = Nothing
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ type Msg =
|
||||||
| ViewportChangeComplete (Result Browser.Dom.Error ()) -- We're done changing the viewport.
|
| ViewportChangeComplete (Result Browser.Dom.Error ()) -- We're done changing the viewport.
|
||||||
| ReceiveFirstSyncResponse (Result Http.Error SyncResponse) -- HTTP, Sync has finished
|
| ReceiveFirstSyncResponse (Result Http.Error SyncResponse) -- HTTP, Sync has finished
|
||||||
| ReceiveSyncResponse (Result Http.Error SyncResponse) -- HTTP, Sync has finished
|
| ReceiveSyncResponse (Result Http.Error SyncResponse) -- HTTP, Sync has finished
|
||||||
| ReceiveLoginResponse (Result Http.Error LoginResponse) -- HTTP, Login has finished
|
| ReceiveLoginResponse ApiUrl (Result Http.Error LoginResponse) -- HTTP, Login has finished
|
||||||
| ReceiveUserData Username (Result Http.Error UserData)
|
| ReceiveUserData Username (Result Http.Error UserData)
|
||||||
| ReceiveCompletedReadMarker (Result Http.Error ())
|
| ReceiveCompletedReadMarker (Result Http.Error ())
|
||||||
|
|
||||||
|
|
6
src/Scylla/Storage.elm
Normal file
6
src/Scylla/Storage.elm
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
port module Scylla.Storage exposing (..)
|
||||||
|
import Json.Encode
|
||||||
|
|
||||||
|
port setStoreValuePort : (String, Json.Encode.Value) -> Cmd msg
|
||||||
|
port getStoreValuePort : (String) -> Cmd msg
|
||||||
|
port receiveStoreValuePort : (Json.Encode.Value -> msg) -> Sub msg
|
10
static/js/storage.js
Normal file
10
static/js/storage.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
function setupStorage(app) {
|
||||||
|
app.ports.setStoreValuePort.subscribe(function(data) {
|
||||||
|
key = data[0];
|
||||||
|
value = data[1];
|
||||||
|
localStorage.setItem(key, value);
|
||||||
|
});
|
||||||
|
app.ports.getStoreValuePort.subscribe(function(data) {
|
||||||
|
app.ports.receiveStoreValuePort.send(localStorage.getItem(data));
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user