You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
798 B
JavaScript
41 lines
798 B
JavaScript
import _ from 'lodash';
|
|
|
|
export default function reducer(state = {
|
|
rows: [],
|
|
items: {},
|
|
}, action) {
|
|
switch (action.type) {
|
|
case 'SCRATCHPAD_RECORDS_LOAD_SUBMISSIONS_FULFILLED': {
|
|
const { rdocs } = action.payload;
|
|
return {
|
|
...state,
|
|
rows: _.map(rdocs, '_id'),
|
|
items: _.keyBy(rdocs, '_id'),
|
|
};
|
|
}
|
|
case 'SCRATCHPAD_RECORDS_PUSH': {
|
|
const { rdoc } = action.payload;
|
|
const rows = [...state.rows];
|
|
if (!rows.includes(rdoc._id)) {
|
|
return {
|
|
...state,
|
|
rows: [rdoc._id, ...state.rows],
|
|
items: {
|
|
...state.items,
|
|
[rdoc._id]: rdoc,
|
|
},
|
|
};
|
|
}
|
|
return {
|
|
...state,
|
|
items: {
|
|
...state.items,
|
|
[rdoc._id]: rdoc,
|
|
},
|
|
};
|
|
}
|
|
default:
|
|
return state;
|
|
}
|
|
}
|