Confirm when unregistering an account.

This commit is contained in:
Nicolas Perriault 2017-05-12 22:41:11 +02:00
parent 92b9e53b8f
commit 8681a926dc
No known key found for this signature in database
GPG Key ID: DA5E4C83904F7A2A
6 changed files with 66 additions and 1 deletions

View File

@ -31,5 +31,6 @@ init { registration, clients } location =
, currentView = LocalTimelineView , currentView = LocalTimelineView
, currentUser = Nothing , currentUser = Nothing
, notificationFilter = NotificationAll , notificationFilter = NotificationAll
, confirm = Nothing
} }
! [ Command.initCommands registration (List.head clients) (Util.extractAuthCode location) ] ! [ Command.initCommands registration (List.head clients) (Util.extractAuthCode location) ]

View File

@ -74,10 +74,13 @@ type WebSocketMsg
type Msg type Msg
= AddFavorite Int = AddFavorite Int
| AskConfirm String Msg Msg
| ClearError Int | ClearError Int
| CloseAccount | CloseAccount
| CloseAccountSelector | CloseAccountSelector
| CloseThread | CloseThread
| ConfirmCancelled Msg
| Confirmed Msg
| DeleteStatus Int | DeleteStatus Int
| DraftEvent DraftMsg | DraftEvent DraftMsg
| FilterNotifications NotificationFilter | FilterNotifications NotificationFilter
@ -108,6 +111,13 @@ type Msg
| WebSocketEvent WebSocketMsg | WebSocketEvent WebSocketMsg
type alias Confirm =
{ message : String
, onConfirm : Msg
, onCancel : Msg
}
type CurrentView type CurrentView
= -- Basically, what we should be displaying in the fourth column = -- Basically, what we should be displaying in the fourth column
AccountFollowersView Account (Timeline Account) AccountFollowersView Account (Timeline Account)
@ -201,6 +211,7 @@ type alias Model =
, currentUser : Maybe Account , currentUser : Maybe Account
, currentView : CurrentView , currentView : CurrentView
, notificationFilter : NotificationFilter , notificationFilter : NotificationFilter
, confirm : Maybe Confirm
} }

View File

@ -45,6 +45,15 @@ update msg model =
ClearError index -> ClearError index ->
{ model | errors = removeAt index model.errors } ! [] { 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 -> SwitchClient client ->
let let
newClients = newClients =

View File

@ -49,7 +49,16 @@ accountIdentityView currentUser client =
] ]
, button , button
[ class "btn btn-danger" [ 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" ] [ text "Logout" ]
, if isCurrentUser then , if isCurrentUser then

View File

@ -155,4 +155,10 @@ view model =
Nothing -> Nothing ->
text "" text ""
, case model.confirm of
Nothing ->
text ""
Just confirm ->
Common.confirmView confirm
] ]

View File

@ -7,10 +7,12 @@ module View.Common
, icon , icon
, justifiedButtonGroup , justifiedButtonGroup
, loadMoreBtn , loadMoreBtn
, confirmView
) )
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Mastodon.Http exposing (Links) import Mastodon.Http exposing (Links)
import Mastodon.Model exposing (..) import Mastodon.Model exposing (..)
import Types exposing (..) import Types exposing (..)
@ -105,3 +107,30 @@ loadMoreBtn { id, links, loading } =
Nothing -> Nothing ->
text "" 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" ]
]
]
]
]
]