about summary refs log tree commit diff
path: root/app/javascript/mastodon/containers/account_container.js
diff options
context:
space:
mode:
authorYamagishi Kazutoshi <ykzts@desire.sh>2017-07-19 00:14:43 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-07-18 17:14:43 +0200
commit3267e4a7851b57bef7d16da4b7c66764f63d4416 (patch)
tree94eb3408ff12b80392f9a680ccfce8fa2e32be56 /app/javascript/mastodon/containers/account_container.js
parent89b988cab5e4729bd80400a2b25ec2b790ebd18d (diff)
Add unfollow modal (optional) (#4246)
* Add unfollow modal

* unfollowing someone

* remove unnecessary prop
Diffstat (limited to 'app/javascript/mastodon/containers/account_container.js')
-rw-r--r--app/javascript/mastodon/containers/account_container.js24
1 files changed, 21 insertions, 3 deletions
diff --git a/app/javascript/mastodon/containers/account_container.js b/app/javascript/mastodon/containers/account_container.js
index 1426bcaa4..ca1efd0e5 100644
--- a/app/javascript/mastodon/containers/account_container.js
+++ b/app/javascript/mastodon/containers/account_container.js
@@ -1,4 +1,6 @@
+import React from 'react';
 import { connect } from 'react-redux';
+import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
 import { makeGetAccount } from '../selectors';
 import Account from '../components/account';
 import {
@@ -9,6 +11,11 @@ import {
   muteAccount,
   unmuteAccount,
 } from '../actions/accounts';
+import { openModal } from '../actions/modal';
+
+const messages = defineMessages({
+  unfollowConfirm: { id: 'confirmations.unfollow.confirm', defaultMessage: 'Unfollow' },
+});
 
 const makeMapStateToProps = () => {
   const getAccount = makeGetAccount();
@@ -16,15 +23,25 @@ const makeMapStateToProps = () => {
   const mapStateToProps = (state, props) => ({
     account: getAccount(state, props.id),
     me: state.getIn(['meta', 'me']),
+    unfollowModal: state.getIn(['meta', 'unfollow_modal']),
   });
 
   return mapStateToProps;
 };
 
-const mapDispatchToProps = (dispatch) => ({
+const mapDispatchToProps = (dispatch, { intl }) => ({
+
   onFollow (account) {
     if (account.getIn(['relationship', 'following'])) {
-      dispatch(unfollowAccount(account.get('id')));
+      if (this.unfollowModal) {
+        dispatch(openModal('CONFIRM', {
+          message: <FormattedMessage id='confirmations.unfollow.message' defaultMessage='Are you sure you want to unfollow {name}?' values={{ name: <strong>@{account.get('acct')}</strong> }} />,
+          confirm: intl.formatMessage(messages.unfollowConfirm),
+          onConfirm: () => dispatch(unfollowAccount(account.get('id'))),
+        }));
+      } else {
+        dispatch(unfollowAccount(account.get('id')));
+      }
     } else {
       dispatch(followAccount(account.get('id')));
     }
@@ -45,6 +62,7 @@ const mapDispatchToProps = (dispatch) => ({
       dispatch(muteAccount(account.get('id')));
     }
   },
+
 });
 
-export default connect(makeMapStateToProps, mapDispatchToProps)(Account);
+export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Account));