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
69
70
71
72
73
|
module Main exposing (..)
import Browser exposing (Document)
import Browser.Navigation exposing (Key)
import Html.Styled exposing (..)
import Types exposing (DisplayableError(..), Model, Msg(..))
import Url exposing (Url)
main : Program () Model Msg
main =
Browser.application
{ init = init
, view = view
, update = update
, subscriptions = \_ -> Sub.none
, onUrlRequest = \_ -> NoOp
, onUrlChange = \_ -> NoOp
}
-- INIT
init : () -> Url -> Key -> ( Model, Cmd Msg )
init _ _ _ =
( { posts =
[ { id = "123"
, content = "foobar"
, author =
{ id = "456"
, name = "George Technoman"
}
}
]
, displayError = NoError
}
, Cmd.none
)
-- UPDATE
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
NoOp ->
( model, Cmd.none )
FetchPostsSuccess posts ->
( { model | posts = posts }, Cmd.none )
FetchPostsFailure error ->
( { model | displayError = error }, Cmd.none )
-- VIEW
view : Model -> Document Msg
view model =
{ title = "Shoob book"
, body = [ body model ] |> List.map toUnstyled
}
body : Model -> Html Msg
body model =
main_ [] (List.map (\post -> div [] [ text post.id ]) model.posts)
|