From 378510834852363d69e5a9bebf833db7c4df3b5d Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Thu, 6 May 2021 09:14:15 -0400 Subject: [PATCH] Promoted and added curators should go at the end of the list --- src/redux/infinite-list.js | 7 ++++--- src/views/studio/lib/studio-member-actions.js | 4 ++-- test/unit/redux/infinite-list.test.js | 13 ++++++++----- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/redux/infinite-list.js b/src/redux/infinite-list.js index b09e10b12..24fba1e17 100644 --- a/src/redux/infinite-list.js +++ b/src/redux/infinite-list.js @@ -76,10 +76,11 @@ const InfiniteList = key => { ...state, items: state.items.filter((_, i) => i !== action.index) }; - case `${key}_PREPEND`: + case `${key}_CREATE`: return { ...state, - items: [action.item].concat(state.items) + items: action.atEnd ? state.items.concat([action.item]) : + [action.item].concat(state.items) }; case `${key}_ERROR`: return { @@ -94,7 +95,7 @@ const InfiniteList = key => { }; const actions = { - create: item => ({type: `${key}_PREPEND`, item}), + create: (item, atEnd = false) => ({type: `${key}_CREATE`, item, atEnd}), remove: index => ({type: `${key}_REMOVE`, index}), replace: (index, item) => ({type: `${key}_REPLACE`, index, item}), error: error => ({type: `${key}_ERROR`, error}), diff --git a/src/views/studio/lib/studio-member-actions.js b/src/views/studio/lib/studio-member-actions.js index e286f7f9c..93f8f9e48 100644 --- a/src/views/studio/lib/studio-member-actions.js +++ b/src/views/studio/lib/studio-member-actions.js @@ -139,7 +139,7 @@ const promoteCurator = username => ((dispatch, getState) => new Promise((resolve const index = curatorList.findIndex(v => v.username === username); const curatorItem = curatorList[index]; if (index !== -1) dispatch(curators.actions.remove(index)); - dispatch(managers.actions.create(curatorItem)); + dispatch(managers.actions.create(curatorItem, true)); return resolve(); }); })); @@ -163,7 +163,7 @@ const acceptInvitation = () => ((dispatch, getState) => new Promise((resolve, re if (userError) return reject(userError); // Note: this assumes that the user items from the curator endpoint // are the same structure as the single user data returned from /users/:username - dispatch(curators.actions.create(userBody)); + dispatch(curators.actions.create(userBody, true)); dispatch(setRoles({invited: false, curator: true})); return resolve(); }); diff --git a/test/unit/redux/infinite-list.test.js b/test/unit/redux/infinite-list.test.js index 9e9995a3d..5a91521c8 100644 --- a/test/unit/redux/infinite-list.test.js +++ b/test/unit/redux/infinite-list.test.js @@ -93,15 +93,18 @@ describe('Infinite List redux module', () => { }); describe('CREATE', () => { - let action; - beforeEach(() => { - action = module.actions.create(7); - }); - test('prepends the given item', () => { + test('prepends the given item by default', () => { + const action = module.actions.create(7); initialState.items = [8, 9, 10, 11]; const newState = module.reducer(initialState, action); expect(newState.items).toEqual([7, 8, 9, 10, 11]); }); + test('appends the given item if given `atEnd` arg', () => { + const action = module.actions.create(7, true); + initialState.items = [8, 9, 10, 11]; + const newState = module.reducer(initialState, action); + expect(newState.items).toEqual([8, 9, 10, 11, 7]); + }); }); describe('ERROR', () => {