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

ui: Give Layout it's own Model/Msg

This commit is contained in:
James Hillyerd
2019-02-17 10:24:07 -08:00
parent 7cd45ff3c7
commit cfbd30d8b0
2 changed files with 95 additions and 71 deletions

View File

@@ -23,10 +23,8 @@ import Url exposing (Url)
type alias Model =
{ page : PageModel
, mailboxName : String
, menuVisible : Bool
, recentVisible : Bool
{ layout : Layout.Model Msg
, page : PageModel
}
@@ -63,10 +61,8 @@ init configValue location key =
Home.init session
initModel =
{ page = Home subModel
, mailboxName = ""
, menuVisible = False
, recentVisible = False
{ layout = Layout.init LayoutMsg ClearFlash ViewMailbox
, page = Home subModel
}
route =
@@ -84,10 +80,8 @@ type Msg
| SessionUpdated (Result D.Error Session.Persistent)
| TimeZoneLoaded Time.Zone
| ClearFlash
| OnMailboxNameInput String
| ViewMailbox String
| ToggleMenu
| ShowRecent Bool
| LayoutMsg Layout.Msg
| HomeMsg Home.Msg
| MailboxMsg Mailbox.Msg
| MonitorMsg Monitor.Msg
@@ -211,19 +205,13 @@ updateMain msg model session =
, Cmd.none
)
OnMailboxNameInput name ->
( { model | mailboxName = name }, Cmd.none )
ViewMailbox name ->
( applyToModelSession Session.clearFlash { model | mailboxName = "" }
( applyToModelSession Session.clearFlash model
, Route.pushUrl session.key (Route.Mailbox name)
)
ToggleMenu ->
( { model | menuVisible = not model.menuVisible }, Cmd.none )
ShowRecent visible ->
( { model | recentVisible = visible }, Cmd.none )
LayoutMsg subMsg ->
( { model | layout = Layout.update subMsg model.layout }, Cmd.none )
_ ->
updatePage msg model
@@ -262,7 +250,7 @@ changeRouteTo route model =
getSession model
newModel =
{ model | menuVisible = False, recentVisible = False }
{ model | layout = Layout.reset model.layout }
in
case route of
Route.Unknown path ->
@@ -378,19 +366,6 @@ view model =
_ ->
""
controls =
{ menuVisible = model.menuVisible
, toggleMenu = ToggleMenu
, recentVisible = model.recentVisible
, showRecent = ShowRecent
, viewMailbox = ViewMailbox
, mailboxOnInput = OnMailboxNameInput
, mailboxValue = model.mailboxName
, recentOptions = session.persistent.recentMailboxes
, recentActive = mailbox
, clearFlash = ClearFlash
}
framePage :
Layout.Page
-> (msg -> Msg)
@@ -399,11 +374,13 @@ view model =
framePage page toMsg { title, modal, content } =
Document title
[ Layout.frame
controls
session
page
(Maybe.map (Html.map toMsg) modal)
(List.map (Html.map toMsg) content)
{ model = model.layout
, session = session
, activePage = page
, activeMailbox = mailbox
, modal = Maybe.map (Html.map toMsg) modal
, content = List.map (Html.map toMsg) content
}
]
in
case model.page of