1
0
Fork 0

Fix #118: Render a draft char counter. (#119)

This commit is contained in:
Nicolas Perriault 2017-05-02 12:26:17 +02:00 committed by GitHub
parent bf09b87215
commit f064c5d8d6
4 changed files with 24 additions and 4 deletions

View File

@ -35,6 +35,7 @@ defaultDraft =
, spoilerText = Nothing , spoilerText = Nothing
, sensitive = False , sensitive = False
, visibility = "public" , visibility = "public"
, statusLength = 0
, autoState = Autocomplete.empty , autoState = Autocomplete.empty
, autoAtPosition = Nothing , autoAtPosition = Nothing
, autoQuery = "" , autoQuery = ""
@ -275,6 +276,7 @@ updateDraft draftMsg currentUser model =
newDraft = newDraft =
{ draft { draft
| status = status | status = status
, statusLength = String.length status
, autoCursorPosition = selectionStart , autoCursorPosition = selectionStart
, autoAtPosition = atPosition , autoAtPosition = atPosition
, autoQuery = query , autoQuery = query

View File

@ -114,6 +114,7 @@ type alias Draft =
, spoilerText : Maybe String , spoilerText : Maybe String
, sensitive : Bool , sensitive : Bool
, visibility : String , visibility : String
, statusLength : Int
-- Autocomplete values -- Autocomplete values
, autoState : Autocomplete.State , autoState : Autocomplete.State

View File

@ -12,7 +12,6 @@ import Html.Attributes exposing (..)
import Mastodon.Model exposing (..) import Mastodon.Model exposing (..)
import Types exposing (..) import Types exposing (..)
import View.Events exposing (..) import View.Events exposing (..)
import View.Formatter exposing (formatContent)
accountLink : Account -> Html Msg accountLink : Account -> Html Msg

View File

@ -113,9 +113,6 @@ draftReplyToView draft =
draftView : Model -> Html Msg draftView : Model -> Html Msg
draftView ({ draft, currentUser } as model) = draftView ({ draft, currentUser } as model) =
let let
hasSpoiler =
draft.spoilerText /= Nothing
visibilityOptionView ( visibility, description ) = visibilityOptionView ( visibility, description ) =
option [ value visibility ] option [ value visibility ]
[ text <| visibility ++ ": " ++ description ] [ text <| visibility ++ ": " ++ description ]
@ -125,6 +122,17 @@ draftView ({ draft, currentUser } as model) =
viewAutocompleteMenu model.draft viewAutocompleteMenu model.draft
else else
text "" text ""
( hasSpoiler, charCount ) =
case draft.spoilerText of
Just spoilerText ->
( True, (String.length spoilerText) + draft.statusLength )
Nothing ->
( False, draft.statusLength )
limitExceeded =
charCount > 500
in in
div [ class "panel panel-default" ] div [ class "panel panel-default" ]
[ div [ class "panel-heading" ] [ div [ class "panel-heading" ]
@ -250,9 +258,19 @@ draftView ({ draft, currentUser } as model) =
, onClick (DraftEvent ClearDraft) , onClick (DraftEvent ClearDraft)
] ]
[ text "Clear" ] [ text "Clear" ]
, button
[ type_ "button"
, class <|
if limitExceeded then
"btn btn-danger active"
else
"btn btn-default active"
]
[ text <| toString charCount ]
, button , button
[ type_ "submit" [ type_ "submit"
, class "btn btn-primary" , class "btn btn-primary"
, disabled limitExceeded
] ]
[ text "Toot!" ] [ text "Toot!" ]
] ]