aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Page.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm/Page.elm')
-rw-r--r--src/client/elm/Page.elm32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/client/elm/Page.elm b/src/client/elm/Page.elm
new file mode 100644
index 0000000..7cfbbc7
--- /dev/null
+++ b/src/client/elm/Page.elm
@@ -0,0 +1,32 @@
+module Page exposing
+ ( Page(..)
+ , toHash
+ , fromHash
+ )
+
+import Navigation
+import UrlParser exposing (..)
+import String
+
+type Page =
+ Home
+ | Income
+ | Statistics
+
+toHash : Page -> String
+toHash page =
+ case page of
+ Home -> "#"
+ Income -> "#income"
+ Statistics -> "#statistics"
+
+fromHash : Navigation.Location -> Result String Page
+fromHash location = UrlParser.parse identity pageParser (String.dropLeft 1 location.hash)
+
+pageParser : Parser (Page -> a) a
+pageParser =
+ oneOf
+ [ format Home (s "")
+ , format Income (s "income")
+ , format Statistics (s "statistics")
+ ]