mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 10:07:02 +00:00
ui: Cleanup routing
This commit is contained in:
@@ -127,7 +127,7 @@ update msg model =
|
||||
|
||||
SetRoute route ->
|
||||
-- Updates broser URL to requested route.
|
||||
( model, Route.newUrl model.session.key route, Session.none )
|
||||
( model, Route.pushUrl model.session.key route, Session.none )
|
||||
|
||||
UpdateSession (Ok persistent) ->
|
||||
let
|
||||
@@ -150,7 +150,7 @@ update msg model =
|
||||
|
||||
ViewMailbox name ->
|
||||
( { model | mailboxName = "" }
|
||||
, Route.newUrl model.session.key (Route.Mailbox name)
|
||||
, Route.pushUrl model.session.key (Route.Mailbox name)
|
||||
, Session.none
|
||||
)
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ update session msg model =
|
||||
( updateSelected model id
|
||||
, Cmd.batch
|
||||
[ -- Update browser location.
|
||||
Route.newUrl session.key (Route.Message model.mailboxName id)
|
||||
Route.replaceUrl session.key (Route.Message model.mailboxName id)
|
||||
, getMessage model.mailboxName id
|
||||
]
|
||||
, Session.DisableRouting
|
||||
|
||||
@@ -73,7 +73,7 @@ update session msg model =
|
||||
|
||||
OpenMessage header ->
|
||||
( model
|
||||
, Route.newUrl session.key (Route.Message header.mailbox header.id)
|
||||
, Route.pushUrl session.key (Route.Message header.mailbox header.id)
|
||||
, Session.none
|
||||
)
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
module Route exposing (Route(..), fromUrl, href, modifyUrl, newUrl)
|
||||
module Route exposing (Route(..), fromUrl, href, pushUrl, replaceUrl)
|
||||
|
||||
import Browser.Navigation as Navigation exposing (Key)
|
||||
import Html exposing (Attribute)
|
||||
import Html.Attributes as Attr
|
||||
import Url exposing (Url)
|
||||
import Url.Builder as Builder
|
||||
import Url.Parser as Parser exposing ((</>), Parser, map, oneOf, s, string, top)
|
||||
|
||||
|
||||
@@ -30,8 +31,8 @@ routes =
|
||||
|
||||
{-| Convert route to a URI.
|
||||
-}
|
||||
routeToString : Route -> String
|
||||
routeToString page =
|
||||
routeToPath : Route -> String
|
||||
routeToPath page =
|
||||
let
|
||||
pieces =
|
||||
case page of
|
||||
@@ -53,26 +54,26 @@ routeToString page =
|
||||
Status ->
|
||||
[ "status" ]
|
||||
in
|
||||
"/" ++ String.join "/" pieces
|
||||
Builder.absolute pieces []
|
||||
|
||||
|
||||
|
||||
-- PUBLIC HELPERS
|
||||
|
||||
|
||||
href : Key -> Route -> Attribute msg
|
||||
href key route =
|
||||
Attr.href (routeToString route)
|
||||
href : Route -> Attribute msg
|
||||
href route =
|
||||
Attr.href (routeToPath route)
|
||||
|
||||
|
||||
modifyUrl : Key -> Route -> Cmd msg
|
||||
modifyUrl key =
|
||||
routeToString >> Navigation.replaceUrl key
|
||||
replaceUrl : Key -> Route -> Cmd msg
|
||||
replaceUrl key =
|
||||
routeToPath >> Navigation.replaceUrl key
|
||||
|
||||
|
||||
newUrl : Key -> Route -> Cmd msg
|
||||
newUrl key =
|
||||
routeToString >> Navigation.pushUrl key
|
||||
pushUrl : Key -> Route -> Cmd msg
|
||||
pushUrl key =
|
||||
routeToPath >> Navigation.pushUrl key
|
||||
|
||||
|
||||
{-| Returns the Route for a given URL.
|
||||
|
||||
@@ -42,10 +42,10 @@ frame controls session page content =
|
||||
[ header []
|
||||
[ ul [ class "navbar", attribute "role" "navigation" ]
|
||||
[ li [ id "navbar-brand" ]
|
||||
[ a [ Route.href session.key Route.Home ] [ text "@ inbucket" ] ]
|
||||
, navbarLink session page Route.Monitor [ text "Monitor" ]
|
||||
, navbarLink session page Route.Status [ text "Status" ]
|
||||
, navbarRecent session page controls
|
||||
[ a [ Route.href Route.Home ] [ text "@ inbucket" ] ]
|
||||
, navbarLink page Route.Monitor [ text "Monitor" ]
|
||||
, navbarLink page Route.Status [ text "Status" ]
|
||||
, navbarRecent page controls
|
||||
, li [ id "navbar-mailbox" ]
|
||||
[ form [ Events.onSubmit (controls.viewMailbox controls.mailboxValue) ]
|
||||
[ input
|
||||
@@ -78,16 +78,16 @@ externalLink url title =
|
||||
a [ href url, target "_blank", rel "noopener" ] [ text title ]
|
||||
|
||||
|
||||
navbarLink : Session -> ActivePage -> Route -> List (Html a) -> Html a
|
||||
navbarLink session page route linkContent =
|
||||
navbarLink : ActivePage -> Route -> List (Html a) -> Html a
|
||||
navbarLink page route linkContent =
|
||||
li [ classList [ ( "navbar-active", isActive page route ) ] ]
|
||||
[ a [ Route.href session.key route ] linkContent ]
|
||||
[ a [ Route.href route ] linkContent ]
|
||||
|
||||
|
||||
{-| Renders list of recent mailboxes, selecting the currently active mailbox.
|
||||
-}
|
||||
navbarRecent : Session -> ActivePage -> FrameControls msg -> Html msg
|
||||
navbarRecent session page controls =
|
||||
navbarRecent : ActivePage -> FrameControls msg -> Html msg
|
||||
navbarRecent page controls =
|
||||
let
|
||||
active =
|
||||
page == Mailbox
|
||||
@@ -109,7 +109,7 @@ navbarRecent session page controls =
|
||||
controls.recentOptions
|
||||
|
||||
recentLink mailbox =
|
||||
a [ Route.href session.key (Route.Mailbox mailbox) ] [ text mailbox ]
|
||||
a [ Route.href (Route.Mailbox mailbox) ] [ text mailbox ]
|
||||
in
|
||||
li
|
||||
[ id "navbar-recent"
|
||||
|
||||
Reference in New Issue
Block a user