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

ui: Initial Elm UI import

Merged from https://github.com/jhillyerd/inbucket-elm

Uses https://github.com/halfzebra/create-elm-app
This commit is contained in:
James Hillyerd
2018-06-02 12:44:15 -07:00
parent 8b5a05eb40
commit c5b5321be3
24 changed files with 3027 additions and 1 deletions

84
ui/src/Route.elm Normal file
View File

@@ -0,0 +1,84 @@
module Route exposing (Route(..), fromLocation, href, modifyUrl, newUrl)
import Html exposing (Attribute)
import Html.Attributes as Attr
import Navigation exposing (Location)
import UrlParser as Url exposing ((</>), Parser, parseHash, s, string)
type Route
= Unknown String
| Home
| Mailbox String
| Message String String
| Monitor
| Status
matcher : Parser (Route -> a) a
matcher =
Url.oneOf
[ Url.map Home (s "")
, Url.map Message (s "m" </> string </> string)
, Url.map Mailbox (s "m" </> string)
, Url.map Monitor (s "monitor")
, Url.map Status (s "status")
]
routeToString : Route -> String
routeToString page =
let
pieces =
case page of
Unknown _ ->
[]
Home ->
[]
Mailbox name ->
[ "m", name ]
Message mailbox id ->
[ "m", mailbox, id ]
Monitor ->
[ "monitor" ]
Status ->
[ "status" ]
in
"/#/" ++ String.join "/" pieces
-- PUBLIC HELPERS
href : Route -> Attribute msg
href route =
Attr.href (routeToString route)
modifyUrl : Route -> Cmd msg
modifyUrl =
routeToString >> Navigation.modifyUrl
newUrl : Route -> Cmd msg
newUrl =
routeToString >> Navigation.newUrl
fromLocation : Location -> Route
fromLocation location =
if String.isEmpty location.hash then
Home
else
case parseHash matcher location of
Nothing ->
Unknown location.hash
Just route ->
route