Use strings for the routes

This commit is contained in:
Tessa Kelly 2022-03-11 13:47:03 -08:00
parent 62fc8e3dcb
commit 30117e65cd

View File

@ -83,9 +83,8 @@ view state =
, code = , code =
String.join "" String.join ""
[ "SideNav.view" [ "SideNav.view"
, "\n\t{ isCurrentRoute = (==) " , "\n\t{ isCurrentRoute = (==) " ++ settings.currentRoute
, String.fromInt settings.currentRoute , "\n\t, routeToString = identity"
, "\n\t, routeToString = String.fromInt"
, "\n\t, onSkipNav = SkipToContent" , "\n\t, onSkipNav = SkipToContent"
, "\n\t, css = " ++ Tuple.first settings.css , "\n\t, css = " ++ Tuple.first settings.css
, "\n\t}" , "\n\t}"
@ -98,7 +97,7 @@ view state =
} }
, SideNav.view , SideNav.view
{ isCurrentRoute = (==) settings.currentRoute { isCurrentRoute = (==) settings.currentRoute
, routeToString = String.fromInt , routeToString = identity
, onSkipNav = SkipToContent , onSkipNav = SkipToContent
, css = Tuple.second settings.css , css = Tuple.second settings.css
} }
@ -113,9 +112,9 @@ type alias State =
type alias Settings = type alias Settings =
{ currentRoute : Int { currentRoute : String
, css : ( String, List Css.Style ) , css : ( String, List Css.Style )
, entries : List ( String, SideNav.Entry Int Msg ) , entries : List ( String, SideNav.Entry String Msg )
} }
@ -124,7 +123,7 @@ init : State
init = init =
{ settings = { settings =
Control.record Settings Control.record Settings
|> Control.field "currentRoute" (ControlExtra.int 1) |> Control.field "currentRoute" (Control.string "#some-route")
|> Control.field "css" |> Control.field "css"
(Control.maybe True (Control.maybe True
(Control.choice (Control.choice
@ -144,21 +143,21 @@ init =
) )
|> Control.map (Maybe.withDefault ( "[]", [] )) |> Control.map (Maybe.withDefault ( "[]", [] ))
) )
|> Control.field "entries" (Control.map List.singleton controlEntryType) |> Control.field "entries" (Control.map List.singleton (controlEntryType "#some-route"))
} }
controlEntryType : Control ( String, SideNav.Entry Int Msg ) controlEntryType : String -> Control ( String, SideNav.Entry String Msg )
controlEntryType = controlEntryType href =
Control.choice Control.choice
[ ( "entry", controlEntry ) [ ( "entry", controlEntry href )
, ( "entryWithChildren", controlEntryWithChildren ) , ( "entryWithChildren", controlEntryWithChildren href )
, ( "html", controlHtml ) , ( "html", controlHtml )
] ]
controlEntry : Control ( String, SideNav.Entry Int Msg ) controlEntry : String -> Control ( String, SideNav.Entry String Msg )
controlEntry = controlEntry href =
Control.record Control.record
(\title attributes -> (\title attributes ->
( "SideNav.entry " ( "SideNav.entry "
@ -170,11 +169,11 @@ controlEntry =
) )
) )
|> Control.field "title" (Control.string "Entry Category") |> Control.field "title" (Control.string "Entry Category")
|> Control.field "attributes" controlEntryAttributes |> Control.field "attributes" (controlEntryAttributes href)
controlEntryWithChildren : Control ( String, SideNav.Entry Int Msg ) controlEntryWithChildren : String -> Control ( String, SideNav.Entry String Msg )
controlEntryWithChildren = controlEntryWithChildren href =
Control.record Control.record
(\title attributes children -> (\title attributes children ->
( "SideNav.entryWithChildren " ( "SideNav.entryWithChildren "
@ -191,12 +190,16 @@ controlEntryWithChildren =
) )
) )
|> Control.field "title" (Control.string "Entry Category") |> Control.field "title" (Control.string "Entry Category")
|> Control.field "attributes" controlEntryAttributes |> Control.field "attributes" (controlEntryAttributes href)
|> -- TODO: support sub-categories |> Control.field "children"
Control.field "children" (Control.value []) (Control.lazy
(\() ->
Control.map List.singleton (controlEntryType (href ++ "-child"))
)
)
controlHtml : Control ( String, SideNav.Entry Int Msg ) controlHtml : Control ( String, SideNav.Entry String Msg )
controlHtml = controlHtml =
Control.map Control.map
(\html -> (\html ->
@ -211,17 +214,12 @@ controlHtml =
(Control.value []) (Control.value [])
controlEntryAttributes : Control (List ( String, SideNav.Attribute Int Msg )) controlEntryAttributes : String -> Control (List ( String, SideNav.Attribute String Msg ))
controlEntryAttributes = controlEntryAttributes href =
ControlExtra.list ControlExtra.list
|> ControlExtra.listItem "href" |> ControlExtra.listItem "href"
(Control.map (Control.map (\v -> ( "SideNav.href " ++ v, SideNav.href v ))
(\int -> (Control.string href)
( "SideNav.href " ++ String.fromInt int
, SideNav.href int
)
)
(ControlExtra.int 1)
) )
|> CommonControls.css { moduleName = "SideNav", use = SideNav.css } |> CommonControls.css { moduleName = "SideNav", use = SideNav.css }
|> CommonControls.iconNotCheckedByDefault "SideNav" SideNav.icon |> CommonControls.iconNotCheckedByDefault "SideNav" SideNav.icon