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

ui: Improve layout menu function

- Rename menu to mainMenu for clarity
- Rename recent to recentMenu
- Add a mouseOut timer to recentMenu
This commit is contained in:
James Hillyerd
2020-04-05 15:30:08 -07:00
parent 107b649738
commit 8a3d291ff3

View File

@@ -38,7 +38,9 @@ import Html.Attributes
) )
import Html.Events as Events import Html.Events as Events
import Modal import Modal
import Process
import Route exposing (Route) import Route exposing (Route)
import Task
{-| Used to highlight current page in navbar. {-| Used to highlight current page in navbar.
@@ -52,17 +54,48 @@ type Page
type alias Model msg = type alias Model msg =
{ mapMsg : Msg -> msg { mapMsg : Msg -> msg
, menuVisible : Bool , mainMenuVisible : Bool
, recentVisible : Bool , recentMenuVisible : Bool
, recentMenuTimer : Timer
, mailboxName : String , mailboxName : String
} }
type Timer
= New
| Idle Int
| Timer Int
replaceTimer : Timer -> Timer
replaceTimer previous =
case previous of
New ->
Timer 0
Idle index ->
Timer (index + 1)
Timer index ->
Timer (index + 1)
cancelTimer : Timer -> Timer
cancelTimer previous =
case previous of
Timer index ->
Idle (index + 1)
_ ->
previous
init : (Msg -> msg) -> Model msg init : (Msg -> msg) -> Model msg
init mapMsg = init mapMsg =
{ mapMsg = mapMsg { mapMsg = mapMsg
, menuVisible = False , mainMenuVisible = False
, recentVisible = False , recentMenuVisible = False
, recentMenuTimer = New
, mailboxName = "" , mailboxName = ""
} }
@@ -72,20 +105,24 @@ init mapMsg =
reset : Model msg -> Model msg reset : Model msg -> Model msg
reset model = reset model =
{ model { model
| menuVisible = False | mainMenuVisible = False
, recentVisible = False , recentMenuVisible = False
, recentMenuTimer = cancelTimer model.recentMenuTimer
, mailboxName = "" , mailboxName = ""
} }
type Msg type Msg
= ClearFlash = ClearFlash
| MainMenuToggled
| ModalFocused Modal.Msg | ModalFocused Modal.Msg
| ModalUnfocused | ModalUnfocused
| OnMailboxNameInput String | OnMailboxNameInput String
| OpenMailbox | OpenMailbox
| ShowRecent Bool | RecentMenuMouseOver
| ToggleMenu | RecentMenuMouseOut
| RecentMenuTimeout Timer ()
| RecentMenuToggled
update : Msg -> Model msg -> Session -> ( Model msg, Session, Cmd msg ) update : Msg -> Model msg -> Session -> ( Model msg, Session, Cmd msg )
@@ -97,6 +134,12 @@ update msg model session =
, Cmd.none , Cmd.none
) )
MainMenuToggled ->
( { model | mainMenuVisible = not model.mainMenuVisible }
, session
, Cmd.none
)
ModalFocused message -> ModalFocused message ->
( model ( model
, Modal.updateSession message session , Modal.updateSession message session
@@ -122,14 +165,43 @@ update msg model session =
, Route.pushUrl session.key (Route.Mailbox model.mailboxName) , Route.pushUrl session.key (Route.Mailbox model.mailboxName)
) )
ShowRecent visible -> RecentMenuMouseOver ->
( { model | recentVisible = visible } ( { model
| recentMenuVisible = True
, recentMenuTimer = cancelTimer model.recentMenuTimer
}
, session , session
, Cmd.none , Cmd.none
) )
ToggleMenu -> RecentMenuMouseOut ->
( { model | menuVisible = not model.menuVisible } let
newTimer =
replaceTimer model.recentMenuTimer
in
( { model
| recentMenuTimer = newTimer
}
, session
, Process.sleep 400 |> Task.perform (RecentMenuTimeout newTimer >> model.mapMsg)
)
RecentMenuTimeout timer _ ->
if timer == model.recentMenuTimer then
( { model
| recentMenuVisible = False
, recentMenuTimer = cancelTimer timer
}
, session
, Cmd.none
)
else
-- Timer was no longer valid.
( model, session, Cmd.none )
RecentMenuToggled ->
( { model | recentMenuVisible = not model.recentMenuVisible }
, session , session
, Cmd.none , Cmd.none
) )
@@ -150,11 +222,11 @@ frame { model, session, activePage, activeMailbox, modal, content } =
div [ class "app" ] div [ class "app" ]
[ header [] [ header []
[ nav [ class "navbar" ] [ nav [ class "navbar" ]
[ button [ class "navbar-toggle", Events.onClick (ToggleMenu |> model.mapMsg) ] [ button [ class "navbar-toggle", Events.onClick (MainMenuToggled |> model.mapMsg) ]
[ i [ class "fas fa-bars" ] [] ] [ i [ class "fas fa-bars" ] [] ]
, span [ class "navbar-brand" ] , span [ class "navbar-brand" ]
[ a [ Route.href Route.Home ] [ text "@ inbucket" ] ] [ a [ Route.href Route.Home ] [ text "@ inbucket" ] ]
, ul [ class "main-nav", classList [ ( "active", model.menuVisible ) ] ] , ul [ class "main-nav", classList [ ( "active", model.mainMenuVisible ) ] ]
[ if session.config.monitorVisible then [ if session.config.monitorVisible then
navbarLink Monitor Route.Monitor [ text "Monitor" ] activePage navbarLink Monitor Route.Monitor [ text "Monitor" ] activePage
@@ -256,15 +328,15 @@ navbarRecent page activeMailbox model session =
[ class "navbar-dropdown-container" [ class "navbar-dropdown-container"
, classList [ ( "navbar-active", active ) ] , classList [ ( "navbar-active", active ) ]
, attribute "aria-haspopup" "true" , attribute "aria-haspopup" "true"
, ariaExpanded model.recentVisible , ariaExpanded model.recentMenuVisible
, Events.onMouseOver (ShowRecent True |> model.mapMsg) , Events.onMouseOver (RecentMenuMouseOver |> model.mapMsg)
, Events.onMouseOut (ShowRecent False |> model.mapMsg) , Events.onMouseOut (RecentMenuMouseOut |> model.mapMsg)
] ]
[ span [ class "navbar-dropdown" ] [ span [ class "navbar-dropdown" ]
[ text title [ text title
, button , button
[ class "navbar-dropdown-button" [ class "navbar-dropdown-button"
, Events.onClick (ShowRecent (not model.recentVisible) |> model.mapMsg) , Events.onClick (RecentMenuToggled |> model.mapMsg)
] ]
[ i [ class "fas fa-chevron-down" ] [] ] [ i [ class "fas fa-chevron-down" ] [] ]
] ]