mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 18:17:03 +00:00
web + ui: Pass init cookie from server to client
This commit is contained in:
15
ui/src/Data/AppConfig.elm
Normal file
15
ui/src/Data/AppConfig.elm
Normal file
@@ -0,0 +1,15 @@
|
||||
module Data.AppConfig exposing (AppConfig, decoder)
|
||||
|
||||
import Json.Decode as D
|
||||
import Json.Decode.Pipeline as P
|
||||
|
||||
|
||||
type alias AppConfig =
|
||||
{ monitorVisible : Bool
|
||||
}
|
||||
|
||||
|
||||
decoder : D.Decoder AppConfig
|
||||
decoder =
|
||||
D.succeed AppConfig
|
||||
|> P.required "monitor-visible" D.bool
|
||||
@@ -4,11 +4,11 @@ module Data.Session exposing
|
||||
, Session
|
||||
, addRecent
|
||||
, clearFlash
|
||||
, decodeValueWithDefault
|
||||
, decoder
|
||||
, disableRouting
|
||||
, enableRouting
|
||||
, init
|
||||
, initError
|
||||
, showFlash
|
||||
)
|
||||
|
||||
@@ -54,6 +54,17 @@ init key location persistent =
|
||||
}
|
||||
|
||||
|
||||
initError : Nav.Key -> Url -> String -> Session
|
||||
initError key location error =
|
||||
{ key = key
|
||||
, host = location.host
|
||||
, flash = Just (Flash "Initialization failed" [ ( "Error", error ) ])
|
||||
, routing = True
|
||||
, zone = Time.utc
|
||||
, persistent = Persistent []
|
||||
}
|
||||
|
||||
|
||||
addRecent : String -> Session -> Session
|
||||
addRecent mailbox session =
|
||||
if List.head session.persistent.recentMailboxes == Just mailbox then
|
||||
@@ -99,11 +110,6 @@ decoder =
|
||||
|> optional "recentMailboxes" (D.list D.string) []
|
||||
|
||||
|
||||
decodeValueWithDefault : D.Value -> Persistent
|
||||
decodeValueWithDefault =
|
||||
D.decodeValue decoder >> Result.withDefault { recentMailboxes = [] }
|
||||
|
||||
|
||||
encode : Persistent -> E.Value
|
||||
encode persistent =
|
||||
E.object
|
||||
|
||||
Reference in New Issue
Block a user