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

ui: Cleanup routing

This commit is contained in:
James Hillyerd
2018-11-23 14:16:18 -08:00
parent 0f9585a52b
commit ba8e2de475
5 changed files with 28 additions and 27 deletions

View File

@@ -127,7 +127,7 @@ update msg model =
SetRoute route -> SetRoute route ->
-- Updates broser URL to requested 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) -> UpdateSession (Ok persistent) ->
let let
@@ -150,7 +150,7 @@ update msg model =
ViewMailbox name -> ViewMailbox name ->
( { model | mailboxName = "" } ( { model | mailboxName = "" }
, Route.newUrl model.session.key (Route.Mailbox name) , Route.pushUrl model.session.key (Route.Mailbox name)
, Session.none , Session.none
) )

View File

@@ -146,7 +146,7 @@ update session msg model =
( updateSelected model id ( updateSelected model id
, Cmd.batch , Cmd.batch
[ -- Update browser location. [ -- 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 , getMessage model.mailboxName id
] ]
, Session.DisableRouting , Session.DisableRouting

View File

@@ -73,7 +73,7 @@ update session msg model =
OpenMessage header -> OpenMessage header ->
( model ( model
, Route.newUrl session.key (Route.Message header.mailbox header.id) , Route.pushUrl session.key (Route.Message header.mailbox header.id)
, Session.none , Session.none
) )

View File

@@ -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 Browser.Navigation as Navigation exposing (Key)
import Html exposing (Attribute) import Html exposing (Attribute)
import Html.Attributes as Attr import Html.Attributes as Attr
import Url exposing (Url) import Url exposing (Url)
import Url.Builder as Builder
import Url.Parser as Parser exposing ((</>), Parser, map, oneOf, s, string, top) import Url.Parser as Parser exposing ((</>), Parser, map, oneOf, s, string, top)
@@ -30,8 +31,8 @@ routes =
{-| Convert route to a URI. {-| Convert route to a URI.
-} -}
routeToString : Route -> String routeToPath : Route -> String
routeToString page = routeToPath page =
let let
pieces = pieces =
case page of case page of
@@ -53,26 +54,26 @@ routeToString page =
Status -> Status ->
[ "status" ] [ "status" ]
in in
"/" ++ String.join "/" pieces Builder.absolute pieces []
-- PUBLIC HELPERS -- PUBLIC HELPERS
href : Key -> Route -> Attribute msg href : Route -> Attribute msg
href key route = href route =
Attr.href (routeToString route) Attr.href (routeToPath route)
modifyUrl : Key -> Route -> Cmd msg replaceUrl : Key -> Route -> Cmd msg
modifyUrl key = replaceUrl key =
routeToString >> Navigation.replaceUrl key routeToPath >> Navigation.replaceUrl key
newUrl : Key -> Route -> Cmd msg pushUrl : Key -> Route -> Cmd msg
newUrl key = pushUrl key =
routeToString >> Navigation.pushUrl key routeToPath >> Navigation.pushUrl key
{-| Returns the Route for a given URL. {-| Returns the Route for a given URL.

View File

@@ -42,10 +42,10 @@ frame controls session page content =
[ header [] [ header []
[ ul [ class "navbar", attribute "role" "navigation" ] [ ul [ class "navbar", attribute "role" "navigation" ]
[ li [ id "navbar-brand" ] [ li [ id "navbar-brand" ]
[ a [ Route.href session.key Route.Home ] [ text "@ inbucket" ] ] [ a [ Route.href Route.Home ] [ text "@ inbucket" ] ]
, navbarLink session page Route.Monitor [ text "Monitor" ] , navbarLink page Route.Monitor [ text "Monitor" ]
, navbarLink session page Route.Status [ text "Status" ] , navbarLink page Route.Status [ text "Status" ]
, navbarRecent session page controls , navbarRecent page controls
, li [ id "navbar-mailbox" ] , li [ id "navbar-mailbox" ]
[ form [ Events.onSubmit (controls.viewMailbox controls.mailboxValue) ] [ form [ Events.onSubmit (controls.viewMailbox controls.mailboxValue) ]
[ input [ input
@@ -78,16 +78,16 @@ externalLink url title =
a [ href url, target "_blank", rel "noopener" ] [ text title ] a [ href url, target "_blank", rel "noopener" ] [ text title ]
navbarLink : Session -> ActivePage -> Route -> List (Html a) -> Html a navbarLink : ActivePage -> Route -> List (Html a) -> Html a
navbarLink session page route linkContent = navbarLink page route linkContent =
li [ classList [ ( "navbar-active", isActive page route ) ] ] 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. {-| Renders list of recent mailboxes, selecting the currently active mailbox.
-} -}
navbarRecent : Session -> ActivePage -> FrameControls msg -> Html msg navbarRecent : ActivePage -> FrameControls msg -> Html msg
navbarRecent session page controls = navbarRecent page controls =
let let
active = active =
page == Mailbox page == Mailbox
@@ -109,7 +109,7 @@ navbarRecent session page controls =
controls.recentOptions controls.recentOptions
recentLink mailbox = recentLink mailbox =
a [ Route.href session.key (Route.Mailbox mailbox) ] [ text mailbox ] a [ Route.href (Route.Mailbox mailbox) ] [ text mailbox ]
in in
li li
[ id "navbar-recent" [ id "navbar-recent"