diff --git a/src/Model.elm b/src/Model.elm index 8f52da7..c8fbc48 100644 --- a/src/Model.elm +++ b/src/Model.elm @@ -35,6 +35,7 @@ defaultDraft = , spoilerText = Nothing , sensitive = False , visibility = "public" + , statusLength = 0 , autoState = Autocomplete.empty , autoAtPosition = Nothing , autoQuery = "" @@ -275,6 +276,7 @@ updateDraft draftMsg currentUser model = newDraft = { draft | status = status + , statusLength = String.length status , autoCursorPosition = selectionStart , autoAtPosition = atPosition , autoQuery = query diff --git a/src/Types.elm b/src/Types.elm index 7acf477..6d6d10f 100644 --- a/src/Types.elm +++ b/src/Types.elm @@ -114,6 +114,7 @@ type alias Draft = , spoilerText : Maybe String , sensitive : Bool , visibility : String + , statusLength : Int -- Autocomplete values , autoState : Autocomplete.State diff --git a/src/View/Common.elm b/src/View/Common.elm index e347163..9ac6482 100644 --- a/src/View/Common.elm +++ b/src/View/Common.elm @@ -12,7 +12,6 @@ import Html.Attributes exposing (..) import Mastodon.Model exposing (..) import Types exposing (..) import View.Events exposing (..) -import View.Formatter exposing (formatContent) accountLink : Account -> Html Msg diff --git a/src/View/Draft.elm b/src/View/Draft.elm index 5e42ae2..7a8772d 100644 --- a/src/View/Draft.elm +++ b/src/View/Draft.elm @@ -113,9 +113,6 @@ draftReplyToView draft = draftView : Model -> Html Msg draftView ({ draft, currentUser } as model) = let - hasSpoiler = - draft.spoilerText /= Nothing - visibilityOptionView ( visibility, description ) = option [ value visibility ] [ text <| visibility ++ ": " ++ description ] @@ -125,6 +122,17 @@ draftView ({ draft, currentUser } as model) = viewAutocompleteMenu model.draft else text "" + + ( hasSpoiler, charCount ) = + case draft.spoilerText of + Just spoilerText -> + ( True, (String.length spoilerText) + draft.statusLength ) + + Nothing -> + ( False, draft.statusLength ) + + limitExceeded = + charCount > 500 in div [ class "panel panel-default" ] [ div [ class "panel-heading" ] @@ -250,9 +258,19 @@ draftView ({ draft, currentUser } as model) = , onClick (DraftEvent ClearDraft) ] [ text "Clear" ] + , button + [ type_ "button" + , class <| + if limitExceeded then + "btn btn-danger active" + else + "btn btn-default active" + ] + [ text <| toString charCount ] , button [ type_ "submit" , class "btn btn-primary" + , disabled limitExceeded ] [ text "Toot!" ] ]