Skip to content

Commit cd4e153

Browse files
authored
Various formatting updates (#2)
1 parent 2682fd3 commit cd4e153

File tree

1 file changed

+54
-54
lines changed

1 file changed

+54
-54
lines changed

shared/Common.hs

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
-----------------------------------------------------------------------------
1212
module Common where
1313
-----------------------------------------------------------------------------
14-
import Control.Monad.State
1514
import Data.Bool
1615
import Data.Proxy
1716
import Servant.API
1817
import Servant.Links
1918
-----------------------------------------------------------------------------
2019
import Miso
2120
import Miso.String
21+
import Miso.Lens
2222
import qualified Miso.Style as CSS
2323
-----------------------------------------------------------------------------
2424
{- | We can pretty much share everything
@@ -29,10 +29,16 @@ import qualified Miso.Style as CSS
2929
-----------------------------------------------------------------------------
3030
data Model
3131
= Model
32-
{ uri :: URI
33-
, navMenuOpen :: Bool
32+
{ _uri :: URI
33+
, _navMenuOpen :: Bool
3434
} deriving (Show, Eq)
3535
-----------------------------------------------------------------------------
36+
uri :: Lens Model URI
37+
uri = lens _uri $ \record field -> record { _uri = field }
38+
-----------------------------------------------------------------------------
39+
navMenuOpen :: Lens Model Bool
40+
navMenuOpen = lens _navMenuOpen $ \record field -> record { _navMenuOpen = field }
41+
-----------------------------------------------------------------------------
3642
data Action
3743
= ChangeURI URI
3844
| HandleURI URI
@@ -55,16 +61,11 @@ type Routes a =
5561
-----------------------------------------------------------------------------
5662
type ClientRoutes = Routes (View Model Action)
5763
-----------------------------------------------------------------------------
58-
type ServerRoutes = Routes (Get '[HTML] Page)
59-
-----------------------------------------------------------------------------
6064
type HaskellMisoComponent = App Model Action
6165
-----------------------------------------------------------------------------
6266
uriHome, uriExamples, uriDocs, uriCommunity, uri404 :: URI
63-
uriExamples
64-
:<|> uriDocs
65-
:<|> uriCommunity
66-
:<|> uriHome
67-
:<|> uri404 = allLinks' linkURI (Proxy @ClientRoutes)
67+
uriExamples :<|> uriDocs :<|> uriCommunity :<|> uriHome :<|> uri404 =
68+
allLinks' linkURI (Proxy @ClientRoutes)
6869
-----------------------------------------------------------------------------
6970
newtype Page = Page HaskellMisoComponent
7071
-----------------------------------------------------------------------------
@@ -85,32 +86,31 @@ secs :: Int -> Int
8586
secs = (*1000000)
8687
-----------------------------------------------------------------------------
8788
haskellMisoComponent :: URI -> HaskellMisoComponent
88-
haskellMisoComponent uri = (app uri)
89+
haskellMisoComponent uri_ = (haskellMiso uri_)
8990
{ subs = [ uriSub HandleURI ]
9091
}
9192
-----------------------------------------------------------------------------
92-
app :: URI -> App Model Action
93-
app currentUri = component emptyModel updateModel viewModel
93+
haskellMiso :: URI -> App Model Action
94+
haskellMiso currentUri = component emptyModel updateModel viewModel
9495
where
9596
emptyModel = Model currentUri False
9697
viewModel m =
97-
case route (Proxy :: Proxy ClientRoutes) clientHandlers uri m of
98+
case route (Proxy :: Proxy ClientRoutes) clientHandlers _uri m of
9899
Left _ -> the404 m
99100
Right view_ -> view_
100101
-----------------------------------------------------------------------------
101102
updateModel :: Action -> Transition Model Action
102103
updateModel = \case
103104
HandleURI u ->
104-
modify $ \m -> m { uri = u }
105+
uri .= u
105106
ChangeURI u -> do
106-
modify $ \m -> m { navMenuOpen = False }
107+
navMenuOpen .= False
107108
io_ (pushURI u)
108-
ToggleNavMenu -> do
109-
m@Model{..} <- get
110-
put m { navMenuOpen = not navMenuOpen }
109+
ToggleNavMenu ->
110+
navMenuOpen %= not
111111
-----------------------------------------------------------------------------
112112
-- | Views
113-
community :: Model -> View model Action
113+
community :: Model -> View Model Action
114114
community = template $
115115
div_
116116
[ class_ "animated fadeIn"
@@ -165,7 +165,7 @@ community = template $
165165
]
166166
]
167167
-----------------------------------------------------------------------------
168-
docs :: Model -> View model Action
168+
docs :: Model -> View Model Action
169169
docs = template $
170170
div_
171171
[ class_ "animated fadeIn" ]
@@ -203,9 +203,9 @@ docs = template $
203203
]
204204
-----------------------------------------------------------------------------
205205
misoSrc :: MisoString
206-
misoSrc = pack "miso.png"
206+
misoSrc = "miso.png"
207207
-----------------------------------------------------------------------------
208-
examples :: Model -> View model Action
208+
examples :: Model -> View Model Action
209209
examples = template $
210210
div_
211211
[ class_ "animated fadeIn" ]
@@ -263,7 +263,7 @@ examples = template $
263263
]
264264
]
265265
-----------------------------------------------------------------------------
266-
home :: Model -> View model Action
266+
home :: Model -> View Model Action
267267
home = template $
268268
div_
269269
[ class_ "animated fadeIn" ]
@@ -298,25 +298,25 @@ home = template $
298298
]
299299
]
300300
-----------------------------------------------------------------------------
301-
template :: View model Action -> Model -> View model Action
302-
template content Model{..} =
301+
template :: View Model Action -> Model -> View Model Action
302+
template content m =
303303
div_
304304
[]
305305
[ a_
306306
[ class_ "github-fork-ribbon left-top fixed"
307307
, href_ "http://github.com/dmjio/miso"
308-
, textProp "data-ribbon" ("Fork me on GitHub" :: MisoString)
308+
, data_ "ribbon" "Fork me on GitHub"
309309
, target_ "blank"
310310
, rel_ "noopener"
311311
, title_ "Fork me on GitHub"
312312
]
313313
[ "Fork me on GitHub" ]
314-
, hero content uri navMenuOpen
314+
, hero content (m ^. uri) (m ^. navMenuOpen)
315315
, middle
316316
, footer
317317
]
318318
-----------------------------------------------------------------------------
319-
middle :: View model action
319+
middle :: View Model action
320320
middle =
321321
section_
322322
[ class_ "hero" ]
@@ -425,7 +425,7 @@ middle =
425425
]
426426
]
427427

428-
cols :: View model action
428+
cols :: View Model action
429429
cols =
430430
section_
431431
[]
@@ -467,7 +467,7 @@ cols =
467467
]
468468
]
469469
-----------------------------------------------------------------------------
470-
the404 :: Model -> View model Action
470+
the404 :: Model -> View Model Action
471471
the404 = template $
472472
div_
473473
[]
@@ -496,33 +496,33 @@ the404 = template $
496496
]
497497
-----------------------------------------------------------------------------
498498
-- | Github stars
499-
starMiso :: View model action
499+
starMiso :: View Model action
500500
starMiso =
501501
a_
502-
[ class_ (pack "github-button")
503-
, href_ (pack "https://github.com/dmjio/miso")
504-
, textProp (pack "data-icon") "octicon-star"
505-
, textProp (pack "data-size") "large"
506-
, textProp (pack "data-show-count") "true"
507-
, textProp (pack "aria-label") "Star dmjio/miso on GitHub"
502+
[ class_ "github-button"
503+
, href_ "https://github.com/dmjio/miso"
504+
, data_ "icon" "octicon-star"
505+
, data_ "size" "large"
506+
, data_ "show-count" "true"
507+
, aria_ "label" "Star dmjio/miso on GitHub"
508508
]
509509
[ "Star"
510510
]
511511
-----------------------------------------------------------------------------
512-
forkMiso :: View model action
512+
forkMiso :: View Model action
513513
forkMiso =
514514
a_
515-
[ class_ (pack "github-button")
516-
, href_ (pack "https://github.com/dmjio/miso/fork")
517-
, textProp (pack "data-icon") "octicon-repo-forked"
518-
, textProp (pack "data-size") "large"
519-
, textProp (pack "data-show-count") "true"
520-
, textProp (pack "aria-label") "Fork dmjio/miso on GitHub"
515+
[ class_ "github-button"
516+
, href_ "https://github.com/dmjio/miso/fork"
517+
, data_ "icon" "octicon-repo-forked"
518+
, data_ "size" "large"
519+
, data_ "show-count" "true"
520+
, aria_ "label" "Fork dmjio/miso on GitHub"
521521
]
522522
[ "Fork" ]
523523
-----------------------------------------------------------------------------
524524
-- | Hero
525-
hero :: View model Action -> URI -> Bool -> View model Action
525+
hero :: View Model Action -> URI -> Bool -> View Model Action
526526
hero content uri' navMenuOpen' =
527527
section_
528528
[ class_ "hero is-medium is-primary is-bold has-text-centered" ]
@@ -626,7 +626,7 @@ onPreventClick action =
626626
(\() -> const action)
627627
-----------------------------------------------------------------------------
628628
-- | Footer
629-
footer :: View model action
629+
footer :: View Model action
630630
footer =
631631
footer_
632632
[ class_ "footer" ]
@@ -687,7 +687,7 @@ footer =
687687
]
688688
]
689689
-----------------------------------------------------------------------------
690-
newNav :: Bool -> View model Action
690+
newNav :: Bool -> View Model Action
691691
newNav navMenuOpen' =
692692
div_
693693
[ class_ "container" ]
@@ -734,8 +734,8 @@ newNav navMenuOpen' =
734734
]
735735
]
736736
, div_
737-
[ class_ $ "navbar-burger burger " <> bool mempty "is-active" navMenuOpen'
738-
, textProp (pack "data-target") (pack "navMenuIndex")
737+
[ class_ ("navbar-burger burger " <> bool mempty "is-active" navMenuOpen')
738+
, data_ "target" "navMenuIndex"
739739
, onClick ToggleNavMenu
740740
]
741741
[ span_ [] []
@@ -836,7 +836,7 @@ newNav navMenuOpen' =
836836
, div_
837837
[ id_ "blogDropdown"
838838
, class_ "navbar-dropdown is-boxed"
839-
, textProp (pack "data-style_") (pack "width: 18rem;")
839+
, data_ "style_" "width: 18rem;"
840840
]
841841
[ a_
842842
[ class_ "navbar-item"
@@ -1014,9 +1014,9 @@ newNav navMenuOpen' =
10141014
[ a_
10151015
[ id_ "twitter"
10161016
, class_ "button"
1017-
, textProp (pack "data-social-network_") (pack "Twitter")
1018-
, textProp (pack "data-social-action_") (pack "tweet")
1019-
, textProp (pack "data-social-target") (pack "http://bulma.io")
1017+
, data_ "social-network_" "Twitter"
1018+
, data_ "social-action_" "tweet"
1019+
, data_ "social-target" "http://bulma.io"
10201020
, target_ "_blank"
10211021
, href_ "https://twitter.com/intent/tweet?text=Miso: a tasty Haskell front-end web and mobile framework&url=https://haskell-miso.org&via=dmjio"
10221022
]

0 commit comments

Comments
 (0)