aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/app/Route.hs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-06-04 14:36:26 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-06-04 14:46:41 +0200
commited753b04104b27a9b258f174a501e2ae058b41ee (patch)
treeddddddddbe2e92e13140926eea7193f093383754 /frontend/app/Route.hs
parent03b019ca96ceb83113a5ea34f4b48b039c56f02d (diff)
refactor pages
Diffstat (limited to 'frontend/app/Route.hs')
-rw-r--r--frontend/app/Route.hs30
1 files changed, 30 insertions, 0 deletions
diff --git a/frontend/app/Route.hs b/frontend/app/Route.hs
new file mode 100644
index 0000000..36e1462
--- /dev/null
+++ b/frontend/app/Route.hs
@@ -0,0 +1,30 @@
+module Route
+ ( Route (..),
+ parseURI,
+ )
+where
+
+import Data.Attoparsec.Text qualified as P
+import Data.Default
+import Data.Text qualified as T
+import Miso
+
+data Route
+ = Home
+ | ListCollection String
+ deriving (Show, Eq)
+
+instance Default Route where
+ def = Home
+
+parseURI :: URI -> Route
+parseURI uri =
+ either (const def) id $
+ P.parseOnly
+ ( P.choice
+ [ ListCollection <$> (P.string "#collection/" *> P.many1 P.anyChar),
+ pure Home
+ ]
+ <* P.endOfInput
+ )
+ (T.pack uri.uriFragment)