1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 09:37:02 +00:00

ui: Initial Elm UI import

Merged from https://github.com/jhillyerd/inbucket-elm

Uses https://github.com/halfzebra/create-elm-app
This commit is contained in:
James Hillyerd
2018-06-02 12:44:15 -07:00
parent 8b5a05eb40
commit c5b5321be3
24 changed files with 3027 additions and 1 deletions

91
ui/src/Data/Session.elm Normal file
View File

@@ -0,0 +1,91 @@
module Data.Session
exposing
( Session
, Persistent
, Msg(..)
, decoder
, decodeValueWithDefault
, init
, none
, update
)
import Json.Decode as Decode exposing (..)
import Json.Decode.Pipeline exposing (..)
type alias Session =
{ flash : String
, routing : Bool
, persistent : Persistent
}
type alias Persistent =
{ recentMailboxes : List String
}
type Msg
= None
| SetFlash String
| ClearFlash
| DisableRouting
| EnableRouting
| AddRecent String
init : Persistent -> Session
init persistent =
Session "" True persistent
update : Msg -> Session -> Session
update msg session =
case msg of
None ->
session
SetFlash flash ->
{ session | flash = flash }
ClearFlash ->
{ session | flash = "" }
DisableRouting ->
{ session | routing = False }
EnableRouting ->
{ session | routing = True }
AddRecent mailbox ->
if List.head session.persistent.recentMailboxes == Just mailbox then
session
else
let
recent =
session.persistent.recentMailboxes
|> List.filter ((/=) mailbox)
|> List.take 7
|> (::) mailbox
persistent =
session.persistent
in
{ session | persistent = { persistent | recentMailboxes = recent } }
none : Msg
none =
None
decoder : Decoder Persistent
decoder =
decode Persistent
|> optional "recentMailboxes" (list string) []
decodeValueWithDefault : Value -> Persistent
decodeValueWithDefault =
Decode.decodeValue decoder >> Result.withDefault { recentMailboxes = [] }