about summary refs log tree commit diff
path: root/app/assets/javascripts/components/reducers/accounts.jsx
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-01-19 10:54:18 +0100
committerEugen Rochko <eugen@zeonfederated.com>2017-01-19 10:54:18 +0100
commit46be4631ae046c45edc3cc8e01c8fc4144ff6444 (patch)
treec94b389b24384188ede137d7a72a8aaa16b2ec6e /app/assets/javascripts/components/reducers/accounts.jsx
parentf051c2e8131616018486cfb9f4a80a120ca71f6e (diff)
Fix #222 - Update followers count when following/unfollowing
Also, since the root component connects to the stream that updates home/notification columns,
there is pretty much no case for refreshing those columns beyond initial load. So, move the
loading of those columns into the root component, to prevent unneccessary reloads when switching tabs
on mobile or resizing desktop window between mobile/desktop layouts
Diffstat (limited to 'app/assets/javascripts/components/reducers/accounts.jsx')
-rw-r--r--app/assets/javascripts/components/reducers/accounts.jsx8
1 files changed, 7 insertions, 1 deletions
diff --git a/app/assets/javascripts/components/reducers/accounts.jsx b/app/assets/javascripts/components/reducers/accounts.jsx
index 73dee9078..409dfd663 100644
--- a/app/assets/javascripts/components/reducers/accounts.jsx
+++ b/app/assets/javascripts/components/reducers/accounts.jsx
@@ -6,7 +6,9 @@ import {
   FOLLOWING_EXPAND_SUCCESS,
   ACCOUNT_TIMELINE_FETCH_SUCCESS,
   ACCOUNT_TIMELINE_EXPAND_SUCCESS,
-  FOLLOW_REQUESTS_FETCH_SUCCESS
+  FOLLOW_REQUESTS_FETCH_SUCCESS,
+  ACCOUNT_FOLLOW_SUCCESS,
+  ACCOUNT_UNFOLLOW_SUCCESS
 } from '../actions/accounts';
 import { COMPOSE_SUGGESTIONS_READY } from '../actions/compose';
 import {
@@ -105,6 +107,10 @@ export default function accounts(state = initialState, action) {
   case TIMELINE_UPDATE:
   case STATUS_FETCH_SUCCESS:
     return normalizeAccountFromStatus(state, action.status);
+  case ACCOUNT_FOLLOW_SUCCESS:
+    return state.updateIn([action.relationship.id, 'followers_count'], num => num + 1);
+  case ACCOUNT_UNFOLLOW_SUCCESS:
+    return state.updateIn([action.relationship.id, 'followers_count'], num => Math.max(0, num - 1));
   default:
     return state;
   }