about summary refs log tree commit diff
path: root/app/assets/javascripts/components/reducers/user_lists.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/components/reducers/user_lists.jsx')
-rw-r--r--app/assets/javascripts/components/reducers/user_lists.jsx25
1 files changed, 22 insertions, 3 deletions
diff --git a/app/assets/javascripts/components/reducers/user_lists.jsx b/app/assets/javascripts/components/reducers/user_lists.jsx
index 4c201f927..de5c85bba 100644
--- a/app/assets/javascripts/components/reducers/user_lists.jsx
+++ b/app/assets/javascripts/components/reducers/user_lists.jsx
@@ -1,6 +1,8 @@
 import {
   FOLLOWERS_FETCH_SUCCESS,
-  FOLLOWING_FETCH_SUCCESS
+  FOLLOWERS_EXPAND_SUCCESS,
+  FOLLOWING_FETCH_SUCCESS,
+  FOLLOWING_EXPAND_SUCCESS
 } from '../actions/accounts';
 import { SUGGESTIONS_FETCH_SUCCESS } from '../actions/suggestions';
 import {
@@ -17,12 +19,29 @@ const initialState = Immutable.Map({
   favourited_by: Immutable.Map()
 });
 
+const normalizeList = (state, type, id, accounts, prev) => {
+  return state.setIn([type, id], Immutable.Map({
+    prev,
+    items: Immutable.List(accounts.map(item => item.id))
+  }));
+};
+
+const appendToList = (state, type, id, accounts, prev) => {
+  return state.updateIn([type, id], map => {
+    return map.set('prev', prev).update('items', list => list.push(...accounts.map(item => item.id)));
+  });
+};
+
 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)));
+      return normalizeList(state, 'followers', action.id, action.accounts, action.prev);
+    case FOLLOWERS_EXPAND_SUCCESS:
+      return appendToList(state, 'followers', action.id, action.accounts, action.prev);
     case FOLLOWING_FETCH_SUCCESS:
-      return state.setIn(['following', action.id], Immutable.List(action.accounts.map(item => item.id)));
+      return normalizeList(state, 'following', action.id, action.accounts, action.prev);
+    case FOLLOWING_EXPAND_SUCCESS:
+      return appendToList(state, 'following', action.id, action.accounts, action.prev);
     case SUGGESTIONS_FETCH_SUCCESS:
       return state.set('suggestions', Immutable.List(action.accounts.map(item => item.id)));
     case REBLOGS_FETCH_SUCCESS: