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-09-22 20:58:35 +0200
committerEugen Rochko <eugen@zeonfederated.com>2016-09-22 20:58:35 +0200
commit2a84271e85564928c4b5e241d7d3bde69fef40ed (patch)
treec5db43d46ba3eb056e2dd786887503f5c3c23be5 /app/assets/javascripts/components/reducers
parent4a670780f0fda6891f1332e7a00c4b8f925634ed (diff)
Infinite scroll for account timelines
Diffstat (limited to 'app/assets/javascripts/components/reducers')
-rw-r--r--app/assets/javascripts/components/reducers/notifications.jsx4
-rw-r--r--app/assets/javascripts/components/reducers/timelines.jsx16
2 files changed, 18 insertions, 2 deletions
diff --git a/app/assets/javascripts/components/reducers/notifications.jsx b/app/assets/javascripts/components/reducers/notifications.jsx
index 47641557d..995947b2d 100644
--- a/app/assets/javascripts/components/reducers/notifications.jsx
+++ b/app/assets/javascripts/components/reducers/notifications.jsx
@@ -10,7 +10,8 @@ import {
   ACCOUNT_FETCH_FAIL,
   ACCOUNT_FOLLOW_FAIL,
   ACCOUNT_UNFOLLOW_FAIL,
-  ACCOUNT_TIMELINE_FETCH_FAIL
+  ACCOUNT_TIMELINE_FETCH_FAIL,
+  ACCOUNT_TIMELINE_EXPAND_FAIL
 }                                                   from '../actions/accounts';
 import { STATUS_FETCH_FAIL }                        from '../actions/statuses';
 import Immutable                                    from 'immutable';
@@ -48,6 +49,7 @@ export default function notifications(state = initialState, action) {
     case ACCOUNT_FOLLOW_FAIL:
     case ACCOUNT_UNFOLLOW_FAIL:
     case ACCOUNT_TIMELINE_FETCH_FAIL:
+    case ACCOUNT_TIMELINE_EXPAND_FAIL:
     case STATUS_FETCH_FAIL:
       return notificationFromError(state, action.error);
     case NOTIFICATION_DISMISS:
diff --git a/app/assets/javascripts/components/reducers/timelines.jsx b/app/assets/javascripts/components/reducers/timelines.jsx
index e3de9e9b2..8dd9c3b1f 100644
--- a/app/assets/javascripts/components/reducers/timelines.jsx
+++ b/app/assets/javascripts/components/reducers/timelines.jsx
@@ -13,7 +13,8 @@ import {
   ACCOUNT_FETCH_SUCCESS,
   ACCOUNT_FOLLOW_SUCCESS,
   ACCOUNT_UNFOLLOW_SUCCESS,
-  ACCOUNT_TIMELINE_FETCH_SUCCESS
+  ACCOUNT_TIMELINE_FETCH_SUCCESS,
+  ACCOUNT_TIMELINE_EXPAND_SUCCESS
 }                                from '../actions/accounts';
 import { STATUS_FETCH_SUCCESS }  from '../actions/statuses';
 import { FOLLOW_SUBMIT_SUCCESS } from '../actions/follow';
@@ -110,6 +111,17 @@ function normalizeAccountTimeline(state, accountId, statuses) {
   return state;
 };
 
+function appendNormalizedAccountTimeline(state, accountId, statuses) {
+  let moreIds = Immutable.List();
+
+  statuses.forEach((status, i) => {
+    state   = normalizeStatus(state, status);
+    moreIds = moreIds.set(i, status.get('id'));
+  });
+
+  return state.updateIn(['accounts_timelines', accountId], Immutable.List(), list => list.push(...moreIds));
+};
+
 function updateTimeline(state, timeline, status) {
   state = normalizeStatus(state, status);
   state = state.update(timeline, list => list.unshift(status.get('id')));
@@ -176,6 +188,8 @@ export default function timelines(state = initialState, action) {
       return normalizeContext(state, Immutable.fromJS(action.status), Immutable.fromJS(action.context.ancestors), Immutable.fromJS(action.context.descendants));
     case ACCOUNT_TIMELINE_FETCH_SUCCESS:
       return normalizeAccountTimeline(state, action.id, Immutable.fromJS(action.statuses));
+    case ACCOUNT_TIMELINE_EXPAND_SUCCESS:
+      return appendNormalizedAccountTimeline(state, action.id, Immutable.fromJS(action.statuses));
     default:
       return state;
   }