From 9b1520ffbcd789243d3803c5953963ddd7c4364b Mon Sep 17 00:00:00 2001 From: Nicolas Perriault Date: Fri, 21 Apr 2017 14:03:39 +0200 Subject: [PATCH] Handle post visibility. (#14) --- src/Model.elm | 4 ++++ src/View.elm | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/Model.elm b/src/Model.elm index 46ed545..4856406 100644 --- a/src/Model.elm +++ b/src/Model.elm @@ -17,6 +17,7 @@ type DraftMsg | UpdateSensitive Bool | UpdateSpoiler String | UpdateStatus String + | UpdateVisibility String type Msg @@ -189,6 +190,9 @@ updateDraft draftMsg draft = UpdateStatus status -> { draft | status = status } + UpdateVisibility visibility -> + { draft | visibility = visibility } + update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = diff --git a/src/View.elm b/src/View.elm index e047723..3308016 100644 --- a/src/View.elm +++ b/src/View.elm @@ -1,5 +1,6 @@ module View exposing (view) +import Dict import Html exposing (..) import Html.Attributes exposing (..) import Html.Events exposing (..) @@ -9,6 +10,16 @@ import Mastodon import Model exposing (Model, DraftMsg(..), Msg(..)) +visibilities : Dict.Dict 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" ) + ] + + replace : String -> String -> String -> String replace from to str = String.split from str |> String.join to @@ -101,6 +112,10 @@ draftView { draft } = Just _ -> True + + visibilityOptionView ( visibility, description ) = + option [ value visibility ] + [ text <| visibility ++ ": " ++ description ] in div [ class "col-md-3" ] [ div [ class "panel panel-default" ] @@ -148,7 +163,7 @@ draftView { draft } = , rows 8 , placeholder <| if hasSpoiler then - "This text with be hidden by default, as you have enabled a spoiler." + "This text will be hidden by default, as you have enabled a spoiler." else "Once upon a time..." , onInput <| DraftEvent << UpdateStatus @@ -157,6 +172,19 @@ draftView { draft } = ] [] ] + , 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 + ] , div [ class "form-group checkbox" ] [ label [] [ input @@ -165,7 +193,7 @@ draftView { draft } = , checked draft.sensitive ] [] - , text " NSFW" + , text " This post is NSFW" ] ] , p [ class "text-right" ] @@ -209,7 +237,10 @@ authView model = ] [] , p [ class "help-block" ] - [ text "You'll be redirected to that server to authenticate yourself. We don't have access to your password." ] + [ text <| + "You'll be redirected to that server to authenticate yourself. " + ++ "We don't have access to your password." + ] ] , button [ class "btn btn-primary", type_ "submit" ] [ text "Sign into Tooty" ]