35 lines
723 B
Haskell
35 lines
723 B
Haskell
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
|
|
| EditValue String String
|
|
deriving (Show, Eq)
|
|
|
|
instance Default Route where
|
|
def = Home
|
|
|
|
parseURI :: URI -> Route
|
|
parseURI uri =
|
|
either (const def) id $
|
|
P.parseOnly
|
|
( P.choice
|
|
[ EditValue
|
|
<$> (P.string "#collection/" *> P.manyTill P.anyChar (P.string "/"))
|
|
<*> (P.many1 P.anyChar),
|
|
ListCollection <$> (P.string "#collection/" *> P.many1 P.anyChar),
|
|
pure Home
|
|
]
|
|
<* P.endOfInput
|
|
)
|
|
(T.pack uri.uriFragment)
|