diff --git a/src/Main.elm b/src/Main.elm index f54dfb1..64a2f34 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -9,9 +9,11 @@ import Scylla.Views exposing (viewFull) import Scylla.Route exposing (Route(..)) import Scylla.UserData exposing (..) import Scylla.Notification exposing (..) +import Scylla.Storage exposing (..) import Url exposing (Url) import Url.Parser exposing (parse) import Url.Builder +import Json.Encode import Html exposing (div, text) import Http import Dict @@ -122,6 +124,7 @@ updateLoginResponse model r = case r of Ok lr -> ( { model | token = Just lr.accessToken, loginUsername = lr.userId } , Cmd.batch [ firstSync model.apiUrl lr.accessToken , Nav.pushUrl model.key <| Url.Builder.absolute [] [] + , setStoreValuePort ("scylla.loginInfo", Json.Encode.string (lr.accessToken ++ "\n" ++ model.apiUrl)) ] ) Err e -> (model, Cmd.none) diff --git a/src/Scylla/Storage.elm b/src/Scylla/Storage.elm new file mode 100644 index 0000000..945bd22 --- /dev/null +++ b/src/Scylla/Storage.elm @@ -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 diff --git a/static/js/storage.js b/static/js/storage.js new file mode 100644 index 0000000..ac3110f --- /dev/null +++ b/static/js/storage.js @@ -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)); + }); +}