about summary refs log tree commit diff
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-12-07 14:12:55 +0100
committerClaire <claire.github-309c@sitedethib.com>2022-12-09 16:50:53 +0100
commit3ea445bb5c856143e758dcb78d89750af91a0f90 (patch)
tree954da9801a3568c5edab20031c7e0bd1d691814d
parente877bb47b87a1704e222ea3ceb22f15619bbe775 (diff)
[Glitch] Fix potential duplicate statuses in Explore tab
Port c8a1faa86b2eb2e0350b384fe66431bec663fdae to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
-rw-r--r--app/javascript/flavours/glitch/reducers/status_lists.js30
1 files changed, 16 insertions, 14 deletions
diff --git a/app/javascript/flavours/glitch/reducers/status_lists.js b/app/javascript/flavours/glitch/reducers/status_lists.js
index ada0484f4..7ac0dab47 100644
--- a/app/javascript/flavours/glitch/reducers/status_lists.js
+++ b/app/javascript/flavours/glitch/reducers/status_lists.js
@@ -25,7 +25,7 @@ import {
   TRENDS_STATUSES_EXPAND_SUCCESS,
   TRENDS_STATUSES_EXPAND_FAIL,
 } from 'flavours/glitch/actions/trends';
-import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
+import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet } from 'immutable';
 import {
   FAVOURITE_SUCCESS,
   UNFAVOURITE_SUCCESS,
@@ -43,22 +43,22 @@ const initialState = ImmutableMap({
   favourites: ImmutableMap({
     next: null,
     loaded: false,
-    items: ImmutableList(),
+    items: ImmutableOrderedSet(),
   }),
   bookmarks: ImmutableMap({
     next: null,
     loaded: false,
-    items: ImmutableList(),
+    items: ImmutableOrderedSet(),
   }),
   pins: ImmutableMap({
     next: null,
     loaded: false,
-    items: ImmutableList(),
+    items: ImmutableOrderedSet(),
   }),
   trending: ImmutableMap({
     next: null,
     loaded: false,
-    items: ImmutableList(),
+    items: ImmutableOrderedSet(),
   }),
 });
 
@@ -67,7 +67,7 @@ const normalizeList = (state, listType, statuses, next) => {
     map.set('next', next);
     map.set('loaded', true);
     map.set('isLoading', false);
-    map.set('items', ImmutableList(statuses.map(item => item.id)));
+    map.set('items', ImmutableOrderedSet(statuses.map(item => item.id)));
   }));
 };
 
@@ -75,20 +75,22 @@ const appendToList = (state, listType, statuses, next) => {
   return state.update(listType, listMap => listMap.withMutations(map => {
     map.set('next', next);
     map.set('isLoading', false);
-    map.set('items', map.get('items').concat(statuses.map(item => item.id)));
+    map.set('items', map.get('items').union(statuses.map(item => item.id)));
   }));
 };
 
 const prependOneToList = (state, listType, status) => {
-  return state.update(listType, listMap => listMap.withMutations(map => {
-    map.set('items', map.get('items').unshift(status.get('id')));
-  }));
+  return state.updateIn([listType, 'items'], (list) => {
+    if (list.includes(status.get('id'))) {
+      return list;
+    } else {
+      return ImmutableOrderedSet([status.get('id')]).union(list);
+    }
+  });
 };
 
 const removeOneFromList = (state, listType, status) => {
-  return state.update(listType, listMap => listMap.withMutations(map => {
-    map.set('items', map.get('items').filter(item => item !== status.get('id')));
-  }));
+  return state.updateIn([listType, 'items'], (list) => list.delete(status.get('id')));
 };
 
 export default function statusLists(state = initialState, action) {
@@ -139,7 +141,7 @@ export default function statusLists(state = initialState, action) {
     return removeOneFromList(state, 'pins', action.status);
   case ACCOUNT_BLOCK_SUCCESS:
   case ACCOUNT_MUTE_SUCCESS:
-    return state.updateIn(['trending', 'items'], ImmutableList(), list => list.filterNot(statusId => action.statuses.getIn([statusId, 'account']) === action.relationship.id));
+    return state.updateIn(['trending', 'items'], ImmutableOrderedSet(), list => list.filterNot(statusId => action.statuses.getIn([statusId, 'account']) === action.relationship.id));
   default:
     return state;
   }