mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 17:47:03 +00:00
ui: Refactor page view/framing to handle titles
This commit is contained in:
@@ -255,10 +255,7 @@ setRoute route model =
|
||||
|
||||
Route.Status ->
|
||||
( { model | page = Status Status.init }
|
||||
, Cmd.batch
|
||||
[ Ports.windowTitle "Inbucket Status"
|
||||
, Cmd.map StatusMsg Status.load
|
||||
]
|
||||
, Session.none
|
||||
)
|
||||
in
|
||||
@@ -313,27 +310,30 @@ view model =
|
||||
, recentActive = mailbox
|
||||
}
|
||||
|
||||
frame =
|
||||
Page.frame controls model.session
|
||||
framePage :
|
||||
ActivePage
|
||||
-> (msg -> Msg)
|
||||
-> { title : String, content : Html msg }
|
||||
-> Document Msg
|
||||
framePage page toMsg { title, content } =
|
||||
Document title
|
||||
[ content
|
||||
|> Html.map toMsg
|
||||
|> Page.frame controls model.session page
|
||||
]
|
||||
in
|
||||
Document "Inbucket Document"
|
||||
[ case model.page of
|
||||
case model.page of
|
||||
Home subModel ->
|
||||
Html.map HomeMsg (Home.view model.session subModel)
|
||||
|> frame Page.Other
|
||||
framePage Page.Other HomeMsg (Home.view model.session subModel)
|
||||
|
||||
Mailbox subModel ->
|
||||
Html.map MailboxMsg (Mailbox.view model.session subModel)
|
||||
|> frame Page.Mailbox
|
||||
framePage Page.Mailbox MailboxMsg (Mailbox.view model.session subModel)
|
||||
|
||||
Monitor subModel ->
|
||||
Html.map MonitorMsg (Monitor.view model.session subModel)
|
||||
|> frame Page.Monitor
|
||||
framePage Page.Monitor MonitorMsg (Monitor.view model.session subModel)
|
||||
|
||||
Status subModel ->
|
||||
Html.map StatusMsg (Status.view model.session subModel)
|
||||
|> frame Page.Status
|
||||
]
|
||||
framePage Page.Status StatusMsg (Status.view model.session subModel)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -19,12 +19,7 @@ type alias Model =
|
||||
|
||||
init : ( Model, Cmd Msg )
|
||||
init =
|
||||
( Model ""
|
||||
, Cmd.batch
|
||||
[ Ports.windowTitle "Inbucket"
|
||||
, cmdGreeting
|
||||
]
|
||||
)
|
||||
( Model "", cmdGreeting )
|
||||
|
||||
|
||||
cmdGreeting : Cmd Msg
|
||||
@@ -57,8 +52,10 @@ update session msg model =
|
||||
-- VIEW --
|
||||
|
||||
|
||||
view : Session -> Model -> Html Msg
|
||||
view : Session -> Model -> { title : String, content : Html Msg }
|
||||
view session model =
|
||||
{ title = "Inbucket"
|
||||
, content =
|
||||
div [ id "page" ]
|
||||
[ Html.node "rendered-html"
|
||||
[ class "greeting"
|
||||
@@ -66,3 +63,4 @@ view session model =
|
||||
]
|
||||
[]
|
||||
]
|
||||
}
|
||||
|
||||
@@ -87,8 +87,7 @@ init mailboxName selection =
|
||||
load : String -> Cmd Msg
|
||||
load mailboxName =
|
||||
Cmd.batch
|
||||
[ Ports.windowTitle (mailboxName ++ " - Inbucket")
|
||||
, Task.perform Tick Time.now
|
||||
[ Task.perform Tick Time.now
|
||||
, getList mailboxName
|
||||
]
|
||||
|
||||
@@ -463,8 +462,10 @@ getMessage mailboxName id =
|
||||
-- VIEW
|
||||
|
||||
|
||||
view : Session -> Model -> Html Msg
|
||||
view : Session -> Model -> { title : String, content : Html Msg }
|
||||
view session model =
|
||||
{ title = model.mailboxName ++ " - Inbucket"
|
||||
, content =
|
||||
div [ id "page", class "mailbox" ]
|
||||
[ viewMessageList session model
|
||||
, main_
|
||||
@@ -486,6 +487,7 @@ view session model =
|
||||
text ""
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
viewMessageList : Session -> Model -> Html Msg
|
||||
|
||||
@@ -32,12 +32,7 @@ type alias Model =
|
||||
|
||||
init : ( Model, Cmd Msg )
|
||||
init =
|
||||
( Model False []
|
||||
, Cmd.batch
|
||||
[ Ports.windowTitle "Inbucket Monitor"
|
||||
, Ports.monitorCommand True
|
||||
]
|
||||
)
|
||||
( Model False [], Ports.monitorCommand True )
|
||||
|
||||
|
||||
|
||||
@@ -95,8 +90,10 @@ update session msg model =
|
||||
-- VIEW
|
||||
|
||||
|
||||
view : Session -> Model -> Html Msg
|
||||
view : Session -> Model -> { title : String, content : Html Msg }
|
||||
view session model =
|
||||
{ title = "Inbucket Monitor"
|
||||
, content =
|
||||
div [ id "page" ]
|
||||
[ h1 [] [ text "Monitor" ]
|
||||
, p []
|
||||
@@ -121,6 +118,7 @@ view session model =
|
||||
, tbody [] (List.map viewMessage model.messages)
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
viewMessage : MessageHeader -> Html Msg
|
||||
|
||||
@@ -217,8 +217,10 @@ getMetrics =
|
||||
-- VIEW --
|
||||
|
||||
|
||||
view : Session -> Model -> Html Msg
|
||||
view : Session -> Model -> { title : String, content : Html Msg }
|
||||
view session model =
|
||||
{ title = "Inbucket Status"
|
||||
, content =
|
||||
div [ id "page" ]
|
||||
[ h1 [] [ text "Status" ]
|
||||
, case model.metrics of
|
||||
@@ -249,6 +251,7 @@ view session model =
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
viewMetric : Metric -> Html Msg
|
||||
|
||||
@@ -3,7 +3,6 @@ port module Ports exposing
|
||||
, monitorMessage
|
||||
, onSessionChange
|
||||
, storeSession
|
||||
, windowTitle
|
||||
)
|
||||
|
||||
import Data.Session exposing (Persistent)
|
||||
@@ -20,6 +19,3 @@ port onSessionChange : (Value -> msg) -> Sub msg
|
||||
|
||||
|
||||
port storeSession : Persistent -> Cmd msg
|
||||
|
||||
|
||||
port windowTitle : String -> Cmd msg
|
||||
|
||||
@@ -34,8 +34,3 @@ function sessionObject() {
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
// Window title.
|
||||
app.ports.windowTitle.subscribe(function (title) {
|
||||
document.title = title
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user