aboutsummaryrefslogtreecommitdiff
path: root/src/client/Page.elm
diff options
context:
space:
mode:
authorJoris2017-03-26 21:10:42 +0200
committerJoris2017-03-26 21:10:42 +0200
commit1e47a7754ca38bd1a6c74765d8378caf68ce4619 (patch)
treed0d9238479dc2529a1b558bbbcde346e7e8c2935 /src/client/Page.elm
parentc0ac16a713c4e53cf6af8e72a6d5f6b8ac5d6456 (diff)
downloadbudget-1e47a7754ca38bd1a6c74765d8378caf68ce4619.tar.gz
budget-1e47a7754ca38bd1a6c74765d8378caf68ce4619.tar.bz2
budget-1e47a7754ca38bd1a6c74765d8378caf68ce4619.zip
Separate client and server watch
Diffstat (limited to 'src/client/Page.elm')
-rw-r--r--src/client/Page.elm43
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")
+ ]