-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.purs
More file actions
68 lines (59 loc) · 1.94 KB
/
Main.purs
File metadata and controls
68 lines (59 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
module Main where
import Prelude
import Concur.Core (Widget)
import Concur.React (HTML)
import Concur.React.DOM as D
import Concur.React.Props as P
import Concur.React.Router (linkTo, route, switch, withBrowserRouter, redirect)
import Concur.React.Router.FFI (toString)
import Concur.React.Router.Types (RoutePattern(..), RouteHandlerArgs)
import Concur.React.Run (runWidgetInDom)
import Effect (Effect)
main :: Effect Unit
main = runWidgetInDom "root" rootWidget
-- Compose pagesets together
rootWidget :: forall a. Widget HTML a
rootWidget = withBrowserRouter [] $ D.div'
[ pagesetWithUsers *> pagesetWithoutUsers
, links
]
showArgs :: forall a. RouteHandlerArgs -> Widget HTML a
showArgs x = D.text (toString x)
links :: forall a. Widget HTML a
links = D.div'
[ D.hr'
, D.div' [linkTo "/about" [] [D.text "Go to ABOUT page"]]
, D.div' [linkTo "/users" [] [D.text "Go to USERS page"]]
, D.hr'
, D.div' [D.text "Current Route information -"]
, D.div' [route CatchAll showArgs]
]
-- Pagesets
pagesetWithUsers :: Widget HTML Unit
pagesetWithUsers = switch []
[ route (Exact "/about") \args -> D.div'
[ D.h1' [D.text "The About page"]
, do
void $ D.button [P.onClick] [D.text "Click ME"]
void $ D.button [P.onClick] [D.text "If you click the button one more time, the users page will disappear!"]
]
, route (Exact "/users") \args -> D.h1' [D.text "Users page"]
, route CatchAll \args -> notFound
]
pagesetWithoutUsers :: forall a. Widget HTML a
pagesetWithoutUsers = switch []
[ route (Exact "/about") \args -> D.div'
[ D.h1' [D.text "About page."]
, D.div'
[D.text "Now you've done it! There is no more /users page! Dynamic route configuration!"]
]
, route CatchAll \args -> notFound
]
notFound :: forall a. Widget HTML a
notFound = D.h1'
[ D.text "404 page"
, D.div'
[ D.button [P.onClick] [D.text "Redirect 404 to ABOUT"] >>= \_ ->
redirect { to: "/about", push: false }
]
]