From 8681a926dc7c21ec4dc53f6815461a89a7dd8b06 Mon Sep 17 00:00:00 2001 From: Nicolas Perriault Date: Fri, 12 May 2017 22:41:11 +0200 Subject: [PATCH] Confirm when unregistering an account. --- src/Init.elm | 1 + src/Types.elm | 11 +++++++++++ src/Update/Main.elm | 9 +++++++++ src/View/AccountSelector.elm | 11 ++++++++++- src/View/App.elm | 6 ++++++ src/View/Common.elm | 29 +++++++++++++++++++++++++++++ 6 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/Init.elm b/src/Init.elm index bcee29c..cf3fa2c 100644 --- a/src/Init.elm +++ b/src/Init.elm @@ -31,5 +31,6 @@ init { registration, clients } location = , currentView = LocalTimelineView , currentUser = Nothing , notificationFilter = NotificationAll + , confirm = Nothing } ! [ Command.initCommands registration (List.head clients) (Util.extractAuthCode location) ] diff --git a/src/Types.elm b/src/Types.elm index 9de0946..424f9ef 100644 --- a/src/Types.elm +++ b/src/Types.elm @@ -74,10 +74,13 @@ type WebSocketMsg type Msg = AddFavorite Int + | AskConfirm String Msg Msg | ClearError Int | CloseAccount | CloseAccountSelector | CloseThread + | ConfirmCancelled Msg + | Confirmed Msg | DeleteStatus Int | DraftEvent DraftMsg | FilterNotifications NotificationFilter @@ -108,6 +111,13 @@ type Msg | WebSocketEvent WebSocketMsg +type alias Confirm = + { message : String + , onConfirm : Msg + , onCancel : Msg + } + + type CurrentView = -- Basically, what we should be displaying in the fourth column AccountFollowersView Account (Timeline Account) @@ -201,6 +211,7 @@ type alias Model = , currentUser : Maybe Account , currentView : CurrentView , notificationFilter : NotificationFilter + , confirm : Maybe Confirm } diff --git a/src/Update/Main.elm b/src/Update/Main.elm index e30fd80..b6ac43f 100644 --- a/src/Update/Main.elm +++ b/src/Update/Main.elm @@ -45,6 +45,15 @@ update msg model = ClearError index -> { model | errors = removeAt index model.errors } ! [] + AskConfirm message onClick onCancel -> + { model | confirm = Just <| Confirm message onClick onCancel } ! [] + + ConfirmCancelled onCancel -> + update onCancel { model | confirm = Nothing } + + Confirmed onConfirm -> + update onConfirm { model | confirm = Nothing } + SwitchClient client -> let newClients = diff --git a/src/View/AccountSelector.elm b/src/View/AccountSelector.elm index 88e15f8..6ea1edb 100644 --- a/src/View/AccountSelector.elm +++ b/src/View/AccountSelector.elm @@ -49,7 +49,16 @@ accountIdentityView currentUser client = ] , button [ class "btn btn-danger" - , onClick <| LogoutClient client + , onClick <| + AskConfirm + """ + Are you sure you want to unregister this account + with Tooty? Note that you'll probably want to + revoke the application in the official Web client + on the related instance. + """ + (LogoutClient client) + NoOp ] [ text "Logout" ] , if isCurrentUser then diff --git a/src/View/App.elm b/src/View/App.elm index a5ae38e..ddcbbb4 100644 --- a/src/View/App.elm +++ b/src/View/App.elm @@ -155,4 +155,10 @@ view model = Nothing -> text "" + , case model.confirm of + Nothing -> + text "" + + Just confirm -> + Common.confirmView confirm ] diff --git a/src/View/Common.elm b/src/View/Common.elm index fe7867e..37a13e3 100644 --- a/src/View/Common.elm +++ b/src/View/Common.elm @@ -7,10 +7,12 @@ module View.Common , icon , justifiedButtonGroup , loadMoreBtn + , confirmView ) import Html exposing (..) import Html.Attributes exposing (..) +import Html.Events exposing (..) import Mastodon.Http exposing (Links) import Mastodon.Model exposing (..) import Types exposing (..) @@ -105,3 +107,30 @@ loadMoreBtn { id, links, loading } = Nothing -> text "" + + +confirmView : Confirm -> Html Msg +confirmView { message, onConfirm, onCancel } = + div [] + [ div [ class "modal-backdrop" ] [] + , div + [ class "modal fade in", style [ ( "display", "block" ) ], tabindex -1 ] + [ div + [ class "modal-dialog" ] + [ div + [ class "modal-content" ] + [ div [ class "modal-header" ] [ h4 [] [ text "Confirmation required" ] ] + , div [ class "modal-body" ] [ p [] [ text message ] ] + , div + [ class "modal-footer" ] + [ button + [ type_ "button", class "btn btn-default", onClick (ConfirmCancelled onCancel) ] + [ text "Cancel" ] + , button + [ type_ "button", class "btn btn-primary", onClick (Confirmed onConfirm) ] + [ text "OK" ] + ] + ] + ] + ] + ]