about summary refs log tree commit diff
path: root/app/assets/javascripts/components/features
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-09-23 20:23:26 +0200
committerEugen Rochko <eugen@zeonfederated.com>2016-09-23 20:23:26 +0200
commit3f9708edc4cd799afb68000adc35036dd8b8faa5 (patch)
treeaf7e97a0095c562810577acf68933b461e126794 /app/assets/javascripts/components/features
parentc6d893a71dede65dd88a0dfac81178c8e81e27d2 (diff)
Change output of api/accounts/:id/follow and unfollow to return relationship
Track relationship in redux state. Display follow/unfollow and following-back
information on account view (unstyled)
Diffstat (limited to 'app/assets/javascripts/components/features')
-rw-r--r--app/assets/javascripts/components/features/account/components/action_bar.jsx48
-rw-r--r--app/assets/javascripts/components/features/account/components/header.jsx5
-rw-r--r--app/assets/javascripts/components/features/account/index.jsx18
3 files changed, 59 insertions, 12 deletions
diff --git a/app/assets/javascripts/components/features/account/components/action_bar.jsx b/app/assets/javascripts/components/features/account/components/action_bar.jsx
new file mode 100644
index 000000000..a6eb01d61
--- /dev/null
+++ b/app/assets/javascripts/components/features/account/components/action_bar.jsx
@@ -0,0 +1,48 @@
+import PureRenderMixin    from 'react-addons-pure-render-mixin';
+import ImmutablePropTypes from 'react-immutable-proptypes';
+import Button             from '../../../components/button';
+
+const ActionBar = React.createClass({
+
+  propTypes: {
+    account: ImmutablePropTypes.map.isRequired,
+    me: React.PropTypes.number.isRequired,
+    onFollow: React.PropTypes.func.isRequired,
+    onUnfollow: React.PropTypes.func.isRequired
+  },
+
+  mixins: [PureRenderMixin],
+
+  render () {
+    const { account, me } = this.props;
+    
+    let followBack   = '';
+    let actionButton = '';
+
+    if (account.get('id') === me) {
+      actionButton = 'This is you!';
+    } else {
+      if (account.getIn(['relationship', 'following'])) {
+        actionButton = <Button text='Unfollow' onClick={this.props.onUnfollow} />
+      } else {
+        actionButton = <Button text='Follow' onClick={this.props.onFollow} />
+      }
+
+      if (account.getIn(['relationship', 'followed_by'])) {
+        followBack = 'follows you';
+      }
+    }
+
+    return (
+      <div>
+        {actionButton}
+        {account.get('followers_count')} followers
+        {account.get('following_count')} following
+        {followBack}
+      </div>
+    );
+  },
+
+});
+
+export default ActionBar;
diff --git a/app/assets/javascripts/components/features/account/components/header.jsx b/app/assets/javascripts/components/features/account/components/header.jsx
index 20ed7512b..8a4a629ce 100644
--- a/app/assets/javascripts/components/features/account/components/header.jsx
+++ b/app/assets/javascripts/components/features/account/components/header.jsx
@@ -1,13 +1,10 @@
 import PureRenderMixin    from 'react-addons-pure-render-mixin';
 import ImmutablePropTypes from 'react-immutable-proptypes';
-import Button             from '../../../components/button';
 
 const Header = React.createClass({
 
   propTypes: {
-    account: ImmutablePropTypes.map.isRequired,
-    onFollow: React.PropTypes.func.isRequired,
-    onUnfollow: React.PropTypes.func.isRequired
+    account: ImmutablePropTypes.map.isRequired
   },
 
   mixins: [PureRenderMixin],
diff --git a/app/assets/javascripts/components/features/account/index.jsx b/app/assets/javascripts/components/features/account/index.jsx
index 46d0e5954..5b09594cc 100644
--- a/app/assets/javascripts/components/features/account/index.jsx
+++ b/app/assets/javascripts/components/features/account/index.jsx
@@ -11,13 +11,13 @@ import {
 import { replyCompose }      from '../../actions/compose';
 import { favourite, reblog } from '../../actions/interactions';
 import Header                from './components/header';
-import { selectStatus }      from '../../reducers/timelines';
+import {
+  selectStatus,
+  selectAccount
+}                            from '../../reducers/timelines';
 import StatusList            from '../../components/status_list';
 import Immutable             from 'immutable';
-
-function selectAccount(state, id) {
-  return state.getIn(['timelines', 'accounts', id], null);
-};
+import ActionBar             from './components/action_bar';
 
 function selectStatuses(state, accountId) {
   return state.getIn(['timelines', 'accounts_timelines', accountId], Immutable.List()).map(id => selectStatus(state, id)).filterNot(status => status === null);
@@ -25,7 +25,8 @@ function selectStatuses(state, accountId) {
 
 const mapStateToProps = (state, props) => ({
   account: selectAccount(state, Number(props.params.accountId)),
-  statuses: selectStatuses(state, Number(props.params.accountId))
+  statuses: selectStatuses(state, Number(props.params.accountId)),
+  me: state.getIn(['timelines', 'me'])
 });
 
 const Account = React.createClass({
@@ -76,7 +77,7 @@ const Account = React.createClass({
   },
 
   render () {
-    const { account, statuses } = this.props;
+    const { account, statuses, me } = this.props;
 
     if (account === null) {
       return <div>Loading {this.props.params.accountId}...</div>;
@@ -84,7 +85,8 @@ const Account = React.createClass({
 
     return (
       <div style={{ display: 'flex', flexDirection: 'column', 'flex': '0 0 auto', height: '100%' }}>
-        <Header account={account} onFollow={this.handleFollow} onUnfollow={this.handleUnfollow} />
+        <Header account={account} />
+        <ActionBar account={account} me={me} onFollow={this.handleFollow} onUnfollow={this.handleUnfollow} />
         <StatusList statuses={statuses} onScrollToBottom={this.handleScrollToBottom} onReply={this.handleReply} onReblog={this.handleReblog} onFavourite={this.handleFavourite} />
       </div>
     );