Refactor to make customizing the title per route possible

This commit is contained in:
Tessa Kelly 2022-03-30 11:20:41 -07:00
parent 455ffb3796
commit d0cff1a4f6

View File

@ -169,37 +169,43 @@ subscriptions model =
view : Model -> Document Msg view : Model -> Document Msg
view model = view model =
{ title = "Style Guide"
, body =
[ view_ model |> Html.toUnstyled
, Sprite.attach |> Html.map never |> Html.toUnstyled
]
}
view_ : Model -> Html Msg
view_ model =
let let
findExampleByName name = findExampleByName name =
Dict.values model.moduleStates Dict.values model.moduleStates
|> List.filter (\m -> m.name == name) |> List.filter (\m -> m.name == name)
|> List.head |> List.head
toBody view_ =
List.map Html.toUnstyled
[ view_
, Html.map never Sprite.attach
]
in in
case model.route of case model.route of
Routes.Doodad doodad -> Routes.Doodad doodad ->
case findExampleByName doodad of case findExampleByName doodad of
Just example -> Just example ->
viewExample model example { title = "Style Guide"
|> Html.map (UpdateModuleStates example.name) , body =
viewExample model example
|> Html.map (UpdateModuleStates example.name)
|> toBody
}
Nothing -> Nothing ->
notFound { title = "Style Guide"
, body = toBody notFound
}
Routes.Category category -> Routes.Category category ->
viewCategory model category { title = "Style Guide"
, body = toBody (viewCategory model category)
}
Routes.All -> Routes.All ->
viewAll model { title = "Style Guide"
, body = toBody (viewAll model)
}
viewExample : Model -> Example a msg -> Html msg viewExample : Model -> Example a msg -> Html msg