about summary refs log tree commit diff
path: root/app/assets/javascripts/components/reducers
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-10-27 21:59:56 +0200
committerEugen Rochko <eugen@zeonfederated.com>2016-10-27 21:59:56 +0200
commit1c84d505c8cb926710d059725c5a2d966dd4736b (patch)
treec4ff6e08948a6432ce8f966c4ba8b5d7e11adb28 /app/assets/javascripts/components/reducers
parent909d0d5e88b046f8bb69c893c54944bb2aad12cf (diff)
Adding following/followers lists to the UI
Diffstat (limited to 'app/assets/javascripts/components/reducers')
-rw-r--r--app/assets/javascripts/components/reducers/index.jsx4
-rw-r--r--app/assets/javascripts/components/reducers/suggestions.jsx13
-rw-r--r--app/assets/javascripts/components/reducers/timelines.jsx12
-rw-r--r--app/assets/javascripts/components/reducers/user_lists.jsx21
4 files changed, 46 insertions, 4 deletions
diff --git a/app/assets/javascripts/components/reducers/index.jsx b/app/assets/javascripts/components/reducers/index.jsx
index e9256b8ec..62d6839d7 100644
--- a/app/assets/javascripts/components/reducers/index.jsx
+++ b/app/assets/javascripts/components/reducers/index.jsx
@@ -6,6 +6,8 @@ import follow                from './follow';
 import notifications         from './notifications';
 import { loadingBarReducer } from 'react-redux-loading-bar';
 import modal                 from './modal';
+import user_lists            from './user_lists';
+import suggestions           from './suggestions';
 
 export default combineReducers({
   timelines,
@@ -15,4 +17,6 @@ export default combineReducers({
   notifications,
   loadingBar: loadingBarReducer,
   modal,
+  user_lists,
+  suggestions
 });
diff --git a/app/assets/javascripts/components/reducers/suggestions.jsx b/app/assets/javascripts/components/reducers/suggestions.jsx
new file mode 100644
index 000000000..9d2b7d96a
--- /dev/null
+++ b/app/assets/javascripts/components/reducers/suggestions.jsx
@@ -0,0 +1,13 @@
+import { SUGGESTIONS_FETCH_SUCCESS } from '../actions/suggestions';
+import Immutable                     from 'immutable';
+
+const initialState = Immutable.List();
+
+export default function suggestions(state = initialState, action) {
+  switch(action.type) {
+    case SUGGESTIONS_FETCH_SUCCESS:
+      return Immutable.List(action.accounts.map(item => item.id));
+    default:
+      return state;
+  }
+}
diff --git a/app/assets/javascripts/components/reducers/timelines.jsx b/app/assets/javascripts/components/reducers/timelines.jsx
index 331cbf59c..59a1fbaa7 100644
--- a/app/assets/javascripts/components/reducers/timelines.jsx
+++ b/app/assets/javascripts/components/reducers/timelines.jsx
@@ -18,7 +18,9 @@ import {
   ACCOUNT_BLOCK_SUCCESS,
   ACCOUNT_UNBLOCK_SUCCESS,
   ACCOUNT_TIMELINE_FETCH_SUCCESS,
-  ACCOUNT_TIMELINE_EXPAND_SUCCESS
+  ACCOUNT_TIMELINE_EXPAND_SUCCESS,
+  FOLLOWERS_FETCH_SUCCESS,
+  FOLLOWING_FETCH_SUCCESS
 }                                from '../actions/accounts';
 import {
   STATUS_FETCH_SUCCESS,
@@ -206,12 +208,12 @@ function normalizeContext(state, status, ancestors, descendants) {
   });
 };
 
-function normalizeSuggestions(state, accounts) {
+function normalizeAccounts(state, accounts) {
   accounts.forEach(account => {
     state = state.setIn(['accounts', account.get('id')], account);
   });
 
-  return state.set('suggestions', accounts.map(account => account.get('id')));
+  return state;
 };
 
 export default function timelines(state = initialState, action) {
@@ -247,7 +249,9 @@ export default function timelines(state = initialState, action) {
     case ACCOUNT_TIMELINE_EXPAND_SUCCESS:
       return appendNormalizedAccountTimeline(state, action.id, Immutable.fromJS(action.statuses));
     case SUGGESTIONS_FETCH_SUCCESS:
-      return normalizeSuggestions(state, Immutable.fromJS(action.suggestions));
+    case FOLLOWERS_FETCH_SUCCESS:
+    case FOLLOWING_FETCH_SUCCESS:
+      return normalizeAccounts(state, Immutable.fromJS(action.accounts));
     default:
       return state;
   }
diff --git a/app/assets/javascripts/components/reducers/user_lists.jsx b/app/assets/javascripts/components/reducers/user_lists.jsx
new file mode 100644
index 000000000..ee4b84296
--- /dev/null
+++ b/app/assets/javascripts/components/reducers/user_lists.jsx
@@ -0,0 +1,21 @@
+import {
+  FOLLOWERS_FETCH_SUCCESS,
+  FOLLOWING_FETCH_SUCCESS
+}                          from '../actions/accounts';
+import Immutable           from 'immutable';
+
+const initialState = Immutable.Map({
+  followers: Immutable.Map(),
+  following: Immutable.Map()
+});
+
+export default function userLists(state = initialState, action) {
+  switch(action.type) {
+    case FOLLOWERS_FETCH_SUCCESS:
+      return state.setIn(['followers', action.id], Immutable.List(action.accounts.map(item => item.id)));
+    case FOLLOWING_FETCH_SUCCESS:
+      return state.setIn(['following', action.id], Immutable.List(action.accounts.map(item => item.id)));
+    default:
+      return state;
+  }
+};