mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-03-27 05:11:42 -04:00
Promoted and added curators should go at the end of the list
This commit is contained in:
parent
be088b9513
commit
3785108348
3 changed files with 14 additions and 10 deletions
|
@ -76,10 +76,11 @@ const InfiniteList = key => {
|
||||||
...state,
|
...state,
|
||||||
items: state.items.filter((_, i) => i !== action.index)
|
items: state.items.filter((_, i) => i !== action.index)
|
||||||
};
|
};
|
||||||
case `${key}_PREPEND`:
|
case `${key}_CREATE`:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
items: [action.item].concat(state.items)
|
items: action.atEnd ? state.items.concat([action.item]) :
|
||||||
|
[action.item].concat(state.items)
|
||||||
};
|
};
|
||||||
case `${key}_ERROR`:
|
case `${key}_ERROR`:
|
||||||
return {
|
return {
|
||||||
|
@ -94,7 +95,7 @@ const InfiniteList = key => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
create: item => ({type: `${key}_PREPEND`, item}),
|
create: (item, atEnd = false) => ({type: `${key}_CREATE`, item, atEnd}),
|
||||||
remove: index => ({type: `${key}_REMOVE`, index}),
|
remove: index => ({type: `${key}_REMOVE`, index}),
|
||||||
replace: (index, item) => ({type: `${key}_REPLACE`, index, item}),
|
replace: (index, item) => ({type: `${key}_REPLACE`, index, item}),
|
||||||
error: error => ({type: `${key}_ERROR`, error}),
|
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 index = curatorList.findIndex(v => v.username === username);
|
||||||
const curatorItem = curatorList[index];
|
const curatorItem = curatorList[index];
|
||||||
if (index !== -1) dispatch(curators.actions.remove(index));
|
if (index !== -1) dispatch(curators.actions.remove(index));
|
||||||
dispatch(managers.actions.create(curatorItem));
|
dispatch(managers.actions.create(curatorItem, true));
|
||||||
return resolve();
|
return resolve();
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
@ -163,7 +163,7 @@ const acceptInvitation = () => ((dispatch, getState) => new Promise((resolve, re
|
||||||
if (userError) return reject(userError);
|
if (userError) return reject(userError);
|
||||||
// Note: this assumes that the user items from the curator endpoint
|
// Note: this assumes that the user items from the curator endpoint
|
||||||
// are the same structure as the single user data returned from /users/:username
|
// 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}));
|
dispatch(setRoles({invited: false, curator: true}));
|
||||||
return resolve();
|
return resolve();
|
||||||
});
|
});
|
||||||
|
|
|
@ -93,15 +93,18 @@ describe('Infinite List redux module', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('CREATE', () => {
|
describe('CREATE', () => {
|
||||||
let action;
|
test('prepends the given item by default', () => {
|
||||||
beforeEach(() => {
|
const action = module.actions.create(7);
|
||||||
action = module.actions.create(7);
|
|
||||||
});
|
|
||||||
test('prepends the given item', () => {
|
|
||||||
initialState.items = [8, 9, 10, 11];
|
initialState.items = [8, 9, 10, 11];
|
||||||
const newState = module.reducer(initialState, action);
|
const newState = module.reducer(initialState, action);
|
||||||
expect(newState.items).toEqual([7, 8, 9, 10, 11]);
|
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', () => {
|
describe('ERROR', () => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue