This commit is contained in:
orion 2023-10-06 18:40:38 -05:00
parent 430bab5282
commit d1d6a0d739
Signed by: orion
GPG Key ID: 6D4165AE4C928719

View File

@ -65,18 +65,25 @@ export const App = () => {
```haskell
type Item = {id :: String, title :: String, description :: String}
data State = StateEmpty | StateErrored Error | StateGotItems (Array Item)
data Action = Init
data State
= StateEmpty
| StateErrored Error
| StateGotItems (Array Item)
renderItem item = div [] [ p [] [text item.title]
, span [className "small"] [text item.description]
]
data Action = ActionInit
renderItem item =
div [] [ p [] [text item.title]
, span
[className "small"]
[text item.description]
]
renderApp StateEmpty = p [] [text "Loading..."]
renderApp (StateErrored e) = p [className "error"] [text (message e)]
renderApp (StateGotItems items) = map renderItem items
action Init = do
action ActionInit = do
response <- fetch (URL "/api/item") {method: Get}
jsonString <- text response
itemsOrError <- readJSON jsonString
@ -87,10 +94,11 @@ action Init = do
app = mkComponent
{ initialState: StateEmpty
, render: renderApp
, eval: mkEval ( defaultEval { handleAction = action
, initialize: Just Init
}
)
, eval:
mkEval ( defaultEval { handleAction = action
, initialize: Just ActionInit
}
)
}
```