about summary refs log tree commit diff
path: root/app/assets/javascripts/components/reducers/timelines.jsx
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-02-21 00:10:49 +0100
committerEugen Rochko <eugen@zeonfederated.com>2017-02-21 00:10:49 +0100
commit5997bb47a8a97de6cf3b69f81ef86376019f8f31 (patch)
tree679411d0d1b05f618aa6dd2a4246429a7536ac7e /app/assets/javascripts/components/reducers/timelines.jsx
parentf338cc6c949515a536849522c0e33eb2790d40fa (diff)
Fix #38 - Unread indicator when new content appears above the fold
Diffstat (limited to 'app/assets/javascripts/components/reducers/timelines.jsx')
-rw-r--r--app/assets/javascripts/components/reducers/timelines.jsx18
1 files changed, 17 insertions, 1 deletions
diff --git a/app/assets/javascripts/components/reducers/timelines.jsx b/app/assets/javascripts/components/reducers/timelines.jsx
index 2dbced7ae..ffb49be78 100644
--- a/app/assets/javascripts/components/reducers/timelines.jsx
+++ b/app/assets/javascripts/components/reducers/timelines.jsx
@@ -36,6 +36,7 @@ const initialState = Immutable.Map({
     isLoading: false,
     loaded: false,
     top: true,
+    unread: 0,
     items: Immutable.List()
   }),
 
@@ -45,6 +46,7 @@ const initialState = Immutable.Map({
     isLoading: false,
     loaded: false,
     top: true,
+    unread: 0,
     items: Immutable.List()
   }),
 
@@ -55,6 +57,7 @@ const initialState = Immutable.Map({
     isLoading: false,
     loaded: false,
     top: true,
+    unread: 0,
     items: Immutable.List()
   }),
 
@@ -65,6 +68,7 @@ const initialState = Immutable.Map({
     id: null,
     loaded: false,
     top: true,
+    unread: 0,
     items: Immutable.List()
   }),
 
@@ -155,6 +159,10 @@ const updateTimeline = (state, timeline, status, references) => {
 
   state = normalizeStatus(state, status);
 
+  if (!top) {
+    state = state.updateIn([timeline, 'unread'], unread => unread + 1);
+  }
+
   state = state.updateIn([timeline, 'items'], Immutable.List(), list => {
     if (top && list.size > 40) {
       list = list.take(20);
@@ -249,6 +257,14 @@ const resetTimeline = (state, timeline, id) => {
   return state;
 };
 
+const updateTop = (state, timeline, top) => {
+  if (top) {
+    state = state.setIn([timeline, 'unread'], 0);
+  }
+
+  return state.setIn([timeline, 'top'], top);
+};
+
 export default function timelines(state = initialState, action) {
   switch(action.type) {
   case TIMELINE_REFRESH_REQUEST:
@@ -280,7 +296,7 @@ export default function timelines(state = initialState, action) {
   case ACCOUNT_BLOCK_SUCCESS:
     return filterTimelines(state, action.relationship, action.statuses);
   case TIMELINE_SCROLL_TOP:
-    return state.setIn([action.timeline, 'top'], action.top);
+    return updateTop(state, action.timeline, action.top);
   default:
     return state;
   }