2019-08-31 04:07:25 +05:00
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
import { connect } from 'react-redux';
|
2020-04-30 05:27:46 +05:00
|
|
|
import omit from 'lodash/omit';
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2020-04-30 05:27:46 +05:00
|
|
|
import {
|
|
|
|
isAnyFilterActiveForCurrentBoardSelector,
|
|
|
|
makeCardIdsByListIdSelector,
|
|
|
|
makeListByIdSelector,
|
|
|
|
} from '../selectors';
|
2019-08-31 04:07:25 +05:00
|
|
|
import { createCard, deleteList, updateList } from '../actions/entry';
|
|
|
|
import List from '../components/List';
|
|
|
|
|
|
|
|
const makeMapStateToProps = () => {
|
|
|
|
const listByIdSelector = makeListByIdSelector();
|
|
|
|
const cardIdsByListIdSelector = makeCardIdsByListIdSelector();
|
|
|
|
|
|
|
|
return (state, { id, index }) => {
|
|
|
|
const { name, isPersisted } = listByIdSelector(state, id);
|
|
|
|
const cardIds = cardIdsByListIdSelector(state, id);
|
2020-04-30 05:27:46 +05:00
|
|
|
const isAnyFilterActive = isAnyFilterActiveForCurrentBoardSelector(state);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
return {
|
|
|
|
id,
|
|
|
|
index,
|
|
|
|
name,
|
|
|
|
isPersisted,
|
|
|
|
cardIds,
|
2020-04-30 05:27:46 +05:00
|
|
|
isDeletable: !isAnyFilterActive,
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-02-03 18:42:31 +05:00
|
|
|
const mapDispatchToProps = (dispatch, { id }) =>
|
|
|
|
bindActionCreators(
|
|
|
|
{
|
2020-03-25 00:15:47 +05:00
|
|
|
onUpdate: (data) => updateList(id, data),
|
2020-02-03 18:42:31 +05:00
|
|
|
onDelete: () => deleteList(id),
|
2020-03-25 00:15:47 +05:00
|
|
|
onCardCreate: (data) => createCard(id, data),
|
2020-02-03 18:42:31 +05:00
|
|
|
},
|
|
|
|
dispatch,
|
|
|
|
);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2020-04-30 05:27:46 +05:00
|
|
|
const mergeProps = (stateProps, dispatchProps) => ({
|
|
|
|
...omit(stateProps, 'isDeletable'),
|
|
|
|
...(stateProps.isDeletable ? dispatchProps : omit(dispatchProps, 'onDelete')),
|
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(makeMapStateToProps, mapDispatchToProps, mergeProps)(List);
|