diff options
Diffstat (limited to 'src/client/Page.elm')
-rw-r--r-- | src/client/Page.elm | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/client/Page.elm b/src/client/Page.elm new file mode 100644 index 0000000..39232e0 --- /dev/null +++ b/src/client/Page.elm @@ -0,0 +1,43 @@ +module Page exposing + ( Page(..) + , toHash + , fromLocation + ) + +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" + +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 = + UrlParser.oneOf + [ UrlParser.map Income (s "income") + , UrlParser.map Categories (s "categories") + , UrlParser.map Statistics (s "statistics") + ] |