Skip to content
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
19 changes: 14 additions & 5 deletions src/Page/Article/Editor.elm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type alias Model =
, body : String
, description : String
, tags : List String
, isSaving : Bool
}


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


Expand All @@ -59,6 +61,7 @@ initEdit session slug =
, body = Article.bodyToMarkdownString article.body
, description = article.description
, tags = article.tags
, isSaving = False
}
)

Expand Down Expand Up @@ -121,7 +124,7 @@ viewForm model =
, defaultValue (String.join " " model.tags)
]
[]
, button [ class "btn btn-lg pull-xs-right btn-primary" ]
, button [ class "btn btn-lg pull-xs-right btn-primary", disabled model.isSaving ]
[ text saveButtonText ]
]
]
Expand Down Expand Up @@ -152,13 +155,13 @@ update user msg model =
user.token
|> Request.Article.create model
|> Http.send CreateCompleted
|> pair { model | errors = [] }
|> pair { model | errors = [], isSaving = True }

Just slug ->
user.token
|> Request.Article.update slug model
|> Http.send EditCompleted
|> pair { model | errors = [] }
|> pair { model | errors = [], isSaving = True }

errors ->
{ model | errors = errors } => Cmd.none
Expand All @@ -181,7 +184,10 @@ update user msg model =
|> pair model

CreateCompleted (Err error) ->
{ model | errors = model.errors ++ [ Form => "Server error while attempting to publish article" ] }
{ model
| errors = model.errors ++ [ Form => "Server error while attempting to publish article" ]
, isSaving = False
}
=> Cmd.none

EditCompleted (Ok article) ->
Expand All @@ -190,7 +196,10 @@ update user msg model =
|> pair model

EditCompleted (Err error) ->
{ model | errors = model.errors ++ [ Form => "Server error while attempting to save article" ] }
{ model
| errors = model.errors ++ [ Form => "Server error while attempting to save article" ]
, isSaving = False
}
=> Cmd.none


Expand Down
49 changes: 30 additions & 19 deletions src/Page/Login.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Data.User exposing (User)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Html.Keyed as Keyed
import Http
import Json.Decode as Decode exposing (Decoder, decodeString, field, string)
import Json.Decode.Pipeline exposing (decode, optional)
Expand Down Expand Up @@ -61,22 +62,32 @@ view session model =

viewForm : Html Msg
viewForm =
Html.form [ onSubmit SubmitForm ]
[ Form.input
[ class "form-control-lg"
, placeholder "Email"
, onInput SetEmail
]
[]
, Form.password
[ class "form-control-lg"
, placeholder "Password"
, onInput SetPassword
let
keyedForm =
Keyed.node "form"
in
keyedForm [ onSubmit SubmitForm ]
[ ( "login-form-email"
, Form.input
[ class "form-control-lg"
, placeholder "Email"
, onInput SetEmail
]
[]
)
, ( "login-form-password"
, Form.password
[ class "form-control-lg"
, placeholder "Password"
, onInput SetPassword
]
[]
)
, ( "login-form-sign-in"
, button [ class "btn btn-lg btn-primary pull-xs-right" ]
[ text "Sign in" ]
)
]
[]
, button [ class "btn btn-lg btn-primary pull-xs-right" ]
[ text "Sign in" ]
]



Expand Down Expand Up @@ -132,9 +143,9 @@ update msg model =
_ ->
[ "unable to perform login" ]
in
{ model | errors = List.map (\errorMessage -> Form => errorMessage) errorMessages }
=> Cmd.none
=> NoOp
{ model | errors = List.map (\errorMessage -> Form => errorMessage) errorMessages }
=> Cmd.none
=> NoOp

LoginCompleted (Ok user) ->
model
Expand Down Expand Up @@ -200,4 +211,4 @@ optionalError fieldName =
errorToString errorMessage =
String.join " " [ fieldName, errorMessage ]
in
optional fieldName (Decode.list (Decode.map errorToString string)) []
optional fieldName (Decode.list (Decode.map errorToString string)) []