Commit 37851083 authored by Paul Kaplan's avatar Paul Kaplan

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

parent be088b95
......@@ -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}),
......
......@@ -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();
});
......
......@@ -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', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment