Skip to content

Commit 5be9fa0

Browse files
committed
Flake bump, update code to use Response.
1 parent 4dde81e commit 5be9fa0

File tree

3 files changed

+42
-38
lines changed

3 files changed

+42
-38
lines changed

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ flags: +template-haskell
99
source-repository-package
1010
type: git
1111
location: https://github.com/dmjio/miso
12-
tag: cd98dc522027b150397a51d95055892dfa5a624e
12+
tag: a94999efb822bbba7cf83d08f760dcad6f0fd932

flake.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Main.hs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import GHC.Generics
2323
----------------------------------------------------------------------------
2424
import Miso hiding (defaultOptions)
2525
import Miso.String
26+
import qualified Miso.Html.Event as E
27+
import qualified Miso.Html.Element as H
28+
import qualified Miso.Html.Property as P
2629
import Miso.Lens
2730
import qualified Miso.CSS as CSS
2831
----------------------------------------------------------------------------
@@ -46,9 +49,8 @@ info = lens _info $ \r x -> r { _info = x }
4649
-- | Action
4750
data Action
4851
= FetchGitHub
49-
| SetGitHub GitHub
50-
| ErrorHandler MisoString
51-
deriving (Show, Eq)
52+
| SetGitHub (Response GitHub)
53+
| ErrorHandler (Response MisoString)
5254
----------------------------------------------------------------------------
5355
app :: App Model Action
5456
app = (component emptyModel updateModel viewModel)
@@ -64,56 +66,58 @@ emptyModel :: Model
6466
emptyModel = Model Nothing
6567
----------------------------------------------------------------------------
6668
updateModel :: Action -> Transition Model Action
67-
updateModel FetchGitHub =
68-
getJSON "https://api.github.com" [] SetGitHub ErrorHandler
69-
updateModel (SetGitHub apiInfo) =
70-
info ?= apiInfo
71-
updateModel (ErrorHandler msg) =
72-
io_ (consoleError msg)
69+
updateModel = \case
70+
FetchGitHub ->
71+
getJSON "https://api.github.com/k" [] SetGitHub ErrorHandler
72+
SetGitHub Response {..} ->
73+
info ?= body
74+
ErrorHandler Response {..} ->
75+
io_ (consoleError body)
7376
----------------------------------------------------------------------------
7477
-- | View function, with routing
7578
viewModel :: Model -> View Model Action
76-
viewModel m = div_
79+
viewModel m =
80+
H.div_
7781
[ CSS.style_
7882
[ CSS.textAlign "center"
7983
, CSS.margin "200px"
8084
]
8185
]
82-
[ h1_
83-
[ class_ $ pack "title"
86+
[ H.h1_
87+
[ P.class_ $ pack "title"
8488
]
8589
[ "🍜 Miso Fetch API"
8690
]
8791
, optionalAttrs
88-
button_
89-
[ onClick FetchGitHub
90-
, class_ (pack "button is-large is-outlined")
92+
H.button_
93+
[ E.onClick FetchGitHub
94+
, P.class_ (pack "button is-large is-outlined")
9195
]
9296
(isJust (m ^. info))
93-
[ disabled_
97+
[ P.disabled_
9498
]
9599
[ "Fetch JSON from https://api.github.com"
96100
]
97101
, case m ^. info of
98102
Nothing ->
99-
div_
103+
H.div_
100104
[]
101105
[ "No data"
102106
]
103107
Just GitHub {..} ->
104-
table_
105-
[ class_ "table is-striped" ]
106-
[ thead_
108+
H.table_
109+
[ P.class_ "table is-striped" ]
110+
[ H.thead_
107111
[]
108-
[ tr_
112+
[ H.tr_
109113
[]
110-
[ th_
114+
[ H.th_
111115
[]
112116
[ text "URLs"
113117
]
114118
]
115119
]
116-
, tbody_
120+
, H.tbody_
117121
[]
118122
[ tr currentUserUrl
119123
, tr emojisUrl
@@ -128,7 +132,7 @@ viewModel m = div_
128132
]
129133
where
130134
tr :: MisoString -> View Model action
131-
tr x = tr_ [] [ td_ [] [ text x ] ]
135+
tr x = H.tr_ [] [ H.td_ [] [ text x ] ]
132136
----------------------------------------------------------------------------
133137
-- | Structure to capture the JSON returned from https://api.github.com
134138
data GitHub

0 commit comments

Comments
 (0)