1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-18 10:07:02 +00:00

ui: Re-implement websockets with ports+JS

This commit is contained in:
James Hillyerd
2018-11-13 21:26:37 -08:00
parent ac3a94412d
commit ecd0c124d4
11 changed files with 188 additions and 79 deletions

View File

@@ -180,54 +180,68 @@ updatePage msg model =
setRoute : Route -> Model -> ( Model, Cmd Msg, Session.Msg )
setRoute route model =
case route of
Route.Unknown hash ->
( model, Cmd.none, Session.SetFlash ("Unknown route requested: " ++ hash) )
let
( newModel, newCmd, newSession ) =
case route of
Route.Unknown hash ->
( model, Cmd.none, Session.SetFlash ("Unknown route requested: " ++ hash) )
Route.Home ->
let
( subModel, subCmd ) =
Home.init
in
( { model | page = Home subModel }
, Cmd.map HomeMsg subCmd
, Session.none
)
Route.Home ->
let
( subModel, subCmd ) =
Home.init
in
( { model | page = Home subModel }
, Cmd.map HomeMsg subCmd
, Session.none
)
Route.Mailbox name ->
let
( subModel, subCmd ) =
Mailbox.init name Nothing
in
( { model | page = Mailbox subModel }
, Cmd.map MailboxMsg subCmd
, Session.none
)
Route.Mailbox name ->
let
( subModel, subCmd ) =
Mailbox.init name Nothing
in
( { model | page = Mailbox subModel }
, Cmd.map MailboxMsg subCmd
, Session.none
)
Route.Message mailbox id ->
let
( subModel, subCmd ) =
Mailbox.init mailbox (Just id)
in
( { model | page = Mailbox subModel }
, Cmd.map MailboxMsg subCmd
, Session.none
)
Route.Message mailbox id ->
let
( subModel, subCmd ) =
Mailbox.init mailbox (Just id)
in
( { model | page = Mailbox subModel }
, Cmd.map MailboxMsg subCmd
, Session.none
)
Route.Monitor ->
( { model | page = Monitor (Monitor.init model.session.host) }
, Ports.windowTitle "Inbucket Monitor"
, Session.none
)
Route.Monitor ->
let
( subModel, subCmd ) =
Monitor.init
in
( { model | page = Monitor subModel }
, Cmd.map MonitorMsg subCmd
, Session.none
)
Route.Status ->
( { model | page = Status Status.init }
, Cmd.batch
[ Ports.windowTitle "Inbucket Status"
, Cmd.map StatusMsg Status.load
]
, Session.none
)
Route.Status ->
( { model | page = Status Status.init }
, Cmd.batch
[ Ports.windowTitle "Inbucket Status"
, Cmd.map StatusMsg Status.load
]
, Session.none
)
in
case model.page of
Monitor _ ->
-- Leaving Monitor page, shut down the web socket.
( newModel, Cmd.batch [ Ports.monitorCommand False, newCmd ], newSession )
_ ->
( newModel, newCmd, newSession )
applySession : ( Model, Cmd Msg, Session.Msg ) -> ( Model, Cmd Msg )