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-11-13 20:42:54 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-11-13 20:42:54 +0100
commitdbfe1e4be6fb46c7374275a2465f4386798516cd (patch)
treeb597058c68aceed0c3487b39ba5c75cd64c6ee71 /app/assets/javascripts/components/reducers
parent49b789695368e201eb90d504f48adaa16522bd7b (diff)
Infinite scroll for followers/following lists
Diffstat (limited to 'app/assets/javascripts/components/reducers')
-rw-r--r--app/assets/javascripts/components/reducers/accounts.jsx4
-rw-r--r--app/assets/javascripts/components/reducers/user_lists.jsx25
2 files changed, 26 insertions, 3 deletions
diff --git a/app/assets/javascripts/components/reducers/accounts.jsx b/app/assets/javascripts/components/reducers/accounts.jsx
index c380a88f0..c0ea961b7 100644
--- a/app/assets/javascripts/components/reducers/accounts.jsx
+++ b/app/assets/javascripts/components/reducers/accounts.jsx
@@ -2,7 +2,9 @@ import {
   ACCOUNT_SET_SELF,
   ACCOUNT_FETCH_SUCCESS,
   FOLLOWERS_FETCH_SUCCESS,
+  FOLLOWERS_EXPAND_SUCCESS,
   FOLLOWING_FETCH_SUCCESS,
+  FOLLOWING_EXPAND_SUCCESS,
   ACCOUNT_TIMELINE_FETCH_SUCCESS,
   ACCOUNT_TIMELINE_EXPAND_SUCCESS
 } from '../actions/accounts';
@@ -65,7 +67,9 @@ export default function accounts(state = initialState, action) {
       return normalizeAccount(state, action.account);
     case SUGGESTIONS_FETCH_SUCCESS:
     case FOLLOWERS_FETCH_SUCCESS:
+    case FOLLOWERS_EXPAND_SUCCESS:
     case FOLLOWING_FETCH_SUCCESS:
+    case FOLLOWING_EXPAND_SUCCESS:
     case REBLOGS_FETCH_SUCCESS:
     case FAVOURITES_FETCH_SUCCESS:
     case COMPOSE_SUGGESTIONS_READY:
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: