From b035879b0acccb18d379099dd2c740685ccf2839 Mon Sep 17 00:00:00 2001 From: Nicolas Perriault Date: Wed, 3 May 2017 17:10:03 +0200 Subject: [PATCH] Improve visibility selector. (#126) --- src/View/Draft.elm | 55 +++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/src/View/Draft.elm b/src/View/Draft.elm index 381907e..818c5c1 100644 --- a/src/View/Draft.elm +++ b/src/View/Draft.elm @@ -1,7 +1,6 @@ module View.Draft exposing (draftView) import Autocomplete -import Dict import Html exposing (..) import Html.Attributes exposing (..) import Html.Events exposing (..) @@ -21,14 +20,13 @@ type alias CurrentUser = Account -visibilities : Dict.Dict String String +visibilities : List ( String, String, String ) visibilities = - Dict.fromList - [ ( "public", "post to public timelines" ) - , ( "unlisted", "do not show in public timelines" ) - , ( "private", "post to followers only" ) - , ( "direct", "post to mentioned users only" ) - ] + [ ( "unlisted", "do not show in public timelines", "eye-close" ) + , ( "private", "post to followers only", "user" ) + , ( "direct", "post to mentioned users only", "lock" ) + , ( "public", "post to public timelines", "globe" ) + ] viewAutocompleteMenu : Draft -> Html Msg @@ -110,13 +108,32 @@ draftReplyToView draft = text "" +visibilitySelector : Draft -> Html Msg +visibilitySelector { visibility } = + let + btnClass v = + if v == visibility then + "btn btn-sm btn-primary active" + else + "btn btn-sm btn-default" + in + visibilities + |> List.map + (\( v, t, i ) -> + a + [ href "" + , class <| btnClass v + , onClickWithPreventAndStop <| DraftEvent (UpdateVisibility v) + , title t + ] + [ Common.icon i, text " ", text v ] + ) + |> Common.justifiedButtonGroup + + draftView : Model -> Html Msg draftView ({ draft, currentUser } as model) = let - visibilityOptionView ( visibility, description ) = - option [ value visibility ] - [ text <| visibility ++ ": " ++ description ] - autoMenu = if draft.showAutoMenu then viewAutocompleteMenu model.draft @@ -227,19 +244,7 @@ draftView ({ draft, currentUser } as model) = [] , autoMenu ] - , div [ class "form-group" ] - [ label [ for "visibility" ] [ text "Visibility" ] - , select - [ id "visibility" - , class "form-control" - , onInput <| DraftEvent << UpdateVisibility - , required True - , value draft.visibility - ] - <| - List.map visibilityOptionView <| - Dict.toList visibilities - ] + , visibilitySelector draft , div [ class "form-group checkbox" ] [ label [] [ input