2023-01-09 20:00:37 +00:00
|
|
|
module Route exposing (Route(..), fromUrl, toUrl)
|
|
|
|
|
|
|
|
import Url exposing (Url)
|
|
|
|
import Url.Builder
|
2023-01-10 02:22:46 +00:00
|
|
|
import Url.Parser exposing ((</>), Parser, int, map, oneOf, parse, s, top)
|
2023-01-09 20:00:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
type Route
|
2023-01-09 20:04:51 +00:00
|
|
|
= Collection
|
2023-01-09 20:00:37 +00:00
|
|
|
| DeckList
|
2023-01-10 02:22:46 +00:00
|
|
|
| Deck Int
|
2023-01-09 20:00:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
parser : Parser (Route -> a) a
|
|
|
|
parser =
|
|
|
|
oneOf
|
2023-01-09 20:04:51 +00:00
|
|
|
[ map Collection top
|
2023-01-09 20:00:37 +00:00
|
|
|
, map Collection (s "collection")
|
|
|
|
, map DeckList (s "decks")
|
2023-01-10 02:22:46 +00:00
|
|
|
, map Deck (s "decks" </> int)
|
2023-01-09 20:00:37 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
toUrl : Route -> String
|
|
|
|
toUrl route =
|
|
|
|
case route of
|
|
|
|
Collection ->
|
|
|
|
Url.Builder.absolute [ "collection" ] []
|
|
|
|
|
|
|
|
DeckList ->
|
|
|
|
Url.Builder.absolute [ "decks" ] []
|
|
|
|
|
2023-01-10 02:22:46 +00:00
|
|
|
Deck deckId ->
|
|
|
|
Url.Builder.absolute [ "decks", String.fromInt deckId ] []
|
|
|
|
|
2023-01-09 20:00:37 +00:00
|
|
|
|
|
|
|
fromUrl : Url.Url -> Maybe Route
|
|
|
|
fromUrl url =
|
|
|
|
parse parser url
|