mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 17:47:03 +00:00
web + ui: Pass init cookie from server to client
This commit is contained in:
@@ -2,7 +2,8 @@ module Main exposing (main)
|
||||
|
||||
import Browser exposing (Document, UrlRequest)
|
||||
import Browser.Navigation as Nav
|
||||
import Data.Session as Session exposing (Session, decoder)
|
||||
import Data.AppConfig as AppConfig exposing (AppConfig)
|
||||
import Data.Session as Session exposing (Session)
|
||||
import Html exposing (..)
|
||||
import Json.Decode as D exposing (Value)
|
||||
import Page.Home as Home
|
||||
@@ -34,11 +35,27 @@ type alias Model =
|
||||
}
|
||||
|
||||
|
||||
type alias InitConfig =
|
||||
{ appConfig : AppConfig
|
||||
, session : Session.Persistent
|
||||
}
|
||||
|
||||
|
||||
init : Value -> Url -> Nav.Key -> ( Model, Cmd Msg )
|
||||
init sessionValue location key =
|
||||
init configValue location key =
|
||||
let
|
||||
configDecoder =
|
||||
D.map2 InitConfig
|
||||
(D.field "app-config" AppConfig.decoder)
|
||||
(D.field "session" Session.decoder)
|
||||
|
||||
session =
|
||||
Session.init key location (Session.decodeValueWithDefault sessionValue)
|
||||
case D.decodeValue configDecoder configValue of
|
||||
Ok config ->
|
||||
Session.init key location config.session
|
||||
|
||||
Err error ->
|
||||
Session.initError key location (D.errorToString error)
|
||||
|
||||
( subModel, _ ) =
|
||||
Home.init session
|
||||
|
||||
Reference in New Issue
Block a user