From d0b6988a1a49ae0966e887e892508f2afc12bc6a Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Fri, 29 Oct 2021 11:15:12 +0300 Subject: Initial commit --- src/Main.elm | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/Main.elm (limited to 'src/Main.elm') 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) -- cgit v1.3