From e500394ed975055657fde19d3cd1c106888734b5 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Fri, 29 Oct 2021 16:52:15 +0300 Subject: Implement stuff --- src/Pages/Feed.elm | 57 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 22 deletions(-) (limited to 'src/Pages/Feed.elm') diff --git a/src/Pages/Feed.elm b/src/Pages/Feed.elm index a848200..583c097 100644 --- a/src/Pages/Feed.elm +++ b/src/Pages/Feed.elm @@ -3,10 +3,10 @@ module Pages.Feed exposing (..) import Css exposing (..) import DateFormat.Relative exposing (relativeTime) import Html.Styled exposing (..) -import Html.Styled.Attributes exposing (css) -import Html.Styled.Events exposing (onClick) +import Html.Styled.Attributes exposing (css, placeholder, type_, value) +import Html.Styled.Events exposing (onClick, onInput, onSubmit) import Time exposing (now) -import Types exposing (DisplayableError(..), Model, Msg(..), Post) +import Types exposing (Model, Msg(..), Post) styles = @@ -19,6 +19,7 @@ styles = css [ padding2 (px 15) (px 20) , backgroundColor (hex "#eee") + , marginBottom (px 10) ] , postTitle = css @@ -28,25 +29,18 @@ styles = [ marginRight (px 5) , cursor pointer ] + , composeForm = + css + [ displayFlex + , flexFlow2 row wrap + ] + , composeInput = + css + [ flex (int 1) + ] } -derrorToHtml : DisplayableError -> Html Msg -derrorToHtml derror = - case derror of - DNoError -> - text "" - - DHttpError httpErr -> - text <| Debug.toString httpErr - - -derrorDiv : Model -> Html Msg -derrorDiv model = - div [] - [ derrorToHtml model.displayError ] - - postDiv : Time.Posix -> Post -> Html Msg postDiv now post = div [ styles.post ] @@ -64,7 +58,26 @@ postDiv now post = postsDiv : Model -> Html Msg postsDiv model = - div [] <| List.map (postDiv model.now) model.posts + case model.posts of + Just posts -> + div [] <| List.map (postDiv model.now) posts + + Nothing -> + div [] [ text "Loading posts..." ] + + +composeDiv : Model -> Html Msg +composeDiv model = + form [ styles.composeForm, onSubmit ComposePost ] + [ input + [ styles.composeInput + , placeholder "Type a new post..." + , onInput ComposeInputChanged + , value model.composeInputValue + ] + [] + , button [ type_ "submit" ] [ text "➡️" ] + ] headerSection : Model -> Html msg @@ -77,8 +90,8 @@ headerSection _ = mainSection : Model -> Html Msg mainSection model = main_ [] <| - [ derrorDiv model - , postsDiv model + [ postsDiv model + , composeDiv model ] -- cgit v1.3