diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | elm.json | 29 | ||||
| -rw-r--r-- | src/Main.elm | 73 | ||||
| -rw-r--r-- | src/Types.elm | 31 |
4 files changed, 135 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6bdb3f8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.git/ +elm-stuff/ diff --git a/elm.json b/elm.json new file mode 100644 index 0000000..2ce8eb3 --- /dev/null +++ b/elm.json @@ -0,0 +1,29 @@ +{ + "type": "application", + "source-directories": [ + "src" + ], + "elm-version": "0.19.1", + "dependencies": { + "direct": { + "elm/browser": "1.0.2", + "elm/core": "1.0.5", + "elm/html": "1.0.0", + "elm/http": "2.0.0", + "elm/json": "1.1.3", + "elm/url": "1.0.0", + "rtfeldman/elm-css": "17.0.1" + }, + "indirect": { + "elm/bytes": "1.0.8", + "elm/file": "1.0.5", + "elm/time": "1.0.0", + "elm/virtual-dom": "1.0.2", + "rtfeldman/elm-hex": "1.0.0" + } + }, + "test-dependencies": { + "direct": {}, + "indirect": {} + } +} diff --git a/src/Main.elm b/src/Main.elm new file mode 100644 index 0000000..54352d6 --- /dev/null +++ b/src/Main.elm @@ -0,0 +1,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) diff --git a/src/Types.elm b/src/Types.elm new file mode 100644 index 0000000..de1cccf --- /dev/null +++ b/src/Types.elm @@ -0,0 +1,31 @@ +module Types exposing (..) + + +type alias Model = + { posts : List Post + , displayError : DisplayableError + } + + +type Msg + = NoOp + | FetchPostsSuccess (List Post) + | FetchPostsFailure DisplayableError + + +type DisplayableError + = Error String + | NoError + + +type alias Author = + { id : String + , name : String + } + + +type alias Post = + { id : String + , content : String + , author : Author + } |
