diff options
author | Joris | 2017-03-24 09:21:04 +0000 |
---|---|---|
committer | Joris | 2017-03-24 09:21:04 +0000 |
commit | cfca18262c1ff48dcb683ddab7d03cf8e55573ff (patch) | |
tree | 8a438430cee7411259fc395d8f3898488e85d750 /src/client/elm/Page.elm | |
parent | 293eb8295162bf0a038f488237db9c9d1316c04d (diff) |
Features/categories
Diffstat (limited to 'src/client/elm/Page.elm')
-rw-r--r-- | src/client/elm/Page.elm | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/client/elm/Page.elm b/src/client/elm/Page.elm index 7cfbbc7..39232e0 100644 --- a/src/client/elm/Page.elm +++ b/src/client/elm/Page.elm @@ -1,32 +1,43 @@ module Page exposing ( Page(..) , toHash - , fromHash + , fromLocation ) -import Navigation -import UrlParser exposing (..) +import Navigation exposing (Location) +import UrlParser exposing (Parser, (</>), s) import String type Page = Home | Income + | Categories | Statistics + | NotFound toHash : Page -> String toHash page = case page of Home -> "#" Income -> "#income" + Categories -> "#categories" Statistics -> "#statistics" + NotFound -> "#notFound" -fromHash : Navigation.Location -> Result String Page -fromHash location = UrlParser.parse identity pageParser (String.dropLeft 1 location.hash) +fromLocation : Location -> Page +fromLocation location = + if location.hash == "" + then + Home + else + case UrlParser.parseHash pageParser location of + Just page -> page + Nothing -> NotFound pageParser : Parser (Page -> a) a pageParser = - oneOf - [ format Home (s "") - , format Income (s "income") - , format Statistics (s "statistics") + UrlParser.oneOf + [ UrlParser.map Income (s "income") + , UrlParser.map Categories (s "categories") + , UrlParser.map Statistics (s "statistics") ] |