Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue: Form fields are not updated while traveling in time with the … #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Page/Article.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Page.Article exposing (view, update, Model, Msg, init)
-}

import Html exposing (..)
import Html.Attributes exposing (class, href, id, placeholder, attribute, disabled)
import Html.Attributes exposing (class, href, id, placeholder, attribute, disabled, value)
import Html.Events exposing (onInput, onClick, onSubmit)
import Request.Article
import Request.Article.Comments
Expand Down Expand Up @@ -103,7 +103,7 @@ view session model =
]
, div [ class "row" ]
[ div [ class "col-xs-12 col-md-8 offset-md-2" ] <|
viewAddComment postingDisabled session.user
viewAddComment postingDisabled model.commentText session.user
:: List.map (viewComment session.user) model.comments
]
]
Expand Down Expand Up @@ -133,8 +133,8 @@ viewBanner errors article author maybeUser =
]


viewAddComment : Bool -> Maybe User -> Html Msg
viewAddComment postingDisabled maybeUser =
viewAddComment : Bool -> String -> Maybe User -> Html Msg
viewAddComment postingDisabled commentText maybeUser =
case maybeUser of
Nothing ->
p []
Expand All @@ -151,6 +151,7 @@ viewAddComment postingDisabled maybeUser =
[ class "form-control"
, placeholder "Write a comment..."
, attribute "rows" "3"
, value commentText
, onInput SetCommentText
]
[]
Expand Down Expand Up @@ -321,6 +322,7 @@ update session msg model =
{ model
| commentInFlight = False
, comments = comment :: model.comments
, commentText = ""
}
=> Cmd.none

Expand Down
11 changes: 9 additions & 2 deletions src/Page/Article/Editor.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Page.Article.Editor exposing (view, update, Model, Msg, initNew, initEdit)

import Html exposing (..)
import Html.Attributes exposing (class, href, id, placeholder, attribute, disabled, type_, defaultValue)
import Html.Attributes exposing (class, href, id, placeholder, attribute, disabled, type_, defaultValue, value)
import Html.Events exposing (onSubmit, onInput)
import Request.Article
import Views.Page as Page
Expand All @@ -27,6 +27,7 @@ type alias Model =
, body : String
, description : String
, tags : List String
, unparsedTags : String
}


Expand All @@ -38,6 +39,7 @@ initNew =
, body = ""
, description = ""
, tags = []
, unparsedTags = ""
}


Expand All @@ -59,6 +61,7 @@ initEdit session slug =
, body = Article.bodyToMarkdownString article.body
, description = article.description
, tags = article.tags
, unparsedTags = (String.join " " article.tags)
}
)

Expand Down Expand Up @@ -100,25 +103,29 @@ viewForm model =
, placeholder "Article Title"
, onInput SetTitle
, defaultValue model.title
, value model.title
]
[]
, Form.input
[ placeholder "What's this article about?"
, onInput SetDescription
, defaultValue model.description
, value model.description
]
[]
, Form.textarea
[ placeholder "Write your article (in markdown)"
, attribute "rows" "8"
, onInput SetBody
, defaultValue model.body
, value model.body
]
[]
, Form.input
[ placeholder "Enter tags"
, onInput SetTags
, defaultValue (String.join " " model.tags)
, value model.unparsedTags
]
[]
, button [ class "btn btn-lg pull-xs-right btn-primary" ]
Expand Down Expand Up @@ -170,7 +177,7 @@ update user msg model =
{ model | description = description } => Cmd.none

SetTags tags ->
{ model | tags = tagsFromString tags } => Cmd.none
{ model | tags = tagsFromString tags, unparsedTags = tags } => Cmd.none

SetBody body ->
{ model | body = body } => Cmd.none
Expand Down
8 changes: 5 additions & 3 deletions src/Page/Login.elm
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,28 @@ view session model =
[ text "Need an account?" ]
]
, Form.viewErrors model.errors
, viewForm
, viewForm model
]
]
]
]


viewForm : Html Msg
viewForm =
viewForm : Model -> Html Msg
viewForm model =
Html.form [ onSubmit SubmitForm ]
[ Form.input
[ class "form-control-lg"
, placeholder "Email"
, onInput SetEmail
, value model.email
]
[]
, Form.password
[ class "form-control-lg"
, placeholder "Password"
, onInput SetPassword
, value model.password
]
[]
, button [ class "btn btn-lg btn-primary pull-xs-right" ]
Expand Down
9 changes: 6 additions & 3 deletions src/Page/Register.elm
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,35 @@ view session model =
[ text "Have an account?" ]
]
, Form.viewErrors model.errors
, viewForm
, viewForm model
]
]
]
]


viewForm : Html Msg
viewForm =
viewForm : Model -> Html Msg
viewForm model =
Html.form [ onSubmit SubmitForm ]
[ Form.input
[ class "form-control-lg"
, placeholder "Username"
, onInput SetUsername
, value model.username
]
[]
, Form.input
[ class "form-control-lg"
, placeholder "Email"
, onInput SetEmail
, value model.email
]
[]
, Form.password
[ class "form-control-lg"
, placeholder "Password"
, onInput SetPassword
, value model.password
]
[]
, button [ class "btn btn-lg btn-primary pull-xs-right" ]
Expand Down