Skip to content

Instantly share code, notes, and snippets.

@gerred
Last active September 11, 2016 07:22
Show Gist options
  • Save gerred/2f963d5865c571be495559c69f42b1f4 to your computer and use it in GitHub Desktop.
Save gerred/2f963d5865c571be495559c69f42b1f4 to your computer and use it in GitHub Desktop.
insane skullduggery
view : Model -> Html Msg
view model =
Material.Scheme.topWithScheme Color.BlueGrey Color.LightBlue <|
Layout.render Mdl
model.mdl
[ Layout.selectedTab model.selectedTab
, Layout.onSelectTab SelectTab
, Layout.fixedHeader
, Layout.fixedDrawer
]
{ header = header model
, drawer = drawer model
, tabs =
( tabs model
, []
)
, main = body model
}
type Location
= Login
| Dashboard
| Tools (Maybe ToolsRoute.Location)
type alias Model =
Maybe Location
tabs2Location : Model -> Int -> Maybe Location
tabs2Location model k =
case model of
Just (Tools a) ->
Just (Tools (nth k <| List.map (\x -> x.route) ToolsRoute.tabs))
_ ->
model
urlFor : Location -> String
urlFor loc =
let
url =
case loc of
Login ->
"/"
Dashboard ->
"/dashboard"
Tools (Just k) ->
"/tools" ++ ToolsRoute.urlFor k
Tools Nothing ->
"/tools"
in
"#" ++ url
type Location
= Dashboard
| Browser
urlFor : Location -> String
urlFor loc =
let
url =
case loc of
Dashboard ->
"/"
Browser ->
"/browser"
in
url
type alias Tool =
{ title : String
, url : String
, route : Location
}
tabs : List Tool
tabs =
[ { title = "Dashboard", url = "dashboard", route = Dashboard }
, { title = "Tools", url = "browser", route = Browser }
]
nth : Int -> List a -> Maybe a
nth k xs =
List.drop k xs |> List.head
NavigateTo maybeLocation ->
case maybeLocation of
Nothing ->
model ! []
Just location ->
model ! [ Navigation.newUrl (Route.urlFor location) ]
SelectTab k ->
let
newRoute =
tabs2Location model.route k
in
case newRoute of
Nothing ->
model ! []
Just location ->
{ model | selectedTab = k, route = newRoute }
! [ Navigation.newUrl (Route.urlFor location)
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment