Promoted and added curators should go at the end of the list

This commit is contained in:
Paul Kaplan 2021-05-06 09:14:15 -04:00
parent be088b9513
commit 3785108348
3 changed files with 14 additions and 10 deletions

View file

@ -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}),

View file

@ -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();
});

View file

@ -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', () => {