diff --git a/client/src/components/HomePage/HomePage.jsx b/client/src/components/HomePage/HomePage.jsx index 621881b..4a425cd 100644 --- a/client/src/components/HomePage/HomePage.jsx +++ b/client/src/components/HomePage/HomePage.jsx @@ -3,6 +3,8 @@ import { Page } from '../Page'; import { BoardCard } from './BoardCard'; import { connect } from 'react-redux'; import { fetchBoards } from '../../store/actions/boards'; +import { fetchProjects } from '../../store/actions/projects'; +import { selectBoardByUserProjects } from '../../store/selectors/boards'; export class HomePage extends React.Component { render() { @@ -65,12 +67,13 @@ export class HomePage extends React.Component { componentDidMount() { this.props.dispatch(fetchBoards()); + this.props.dispatch(fetchProjects()); } } export const ConnectedHomePage = connect(function(state) { return { - boards: state.boards.byID, + boards: selectBoardByUserProjects(state.boards.byID, state.projects.byName) }; })(HomePage); \ No newline at end of file diff --git a/client/src/store/selectors/boards.js b/client/src/store/selectors/boards.js new file mode 100644 index 0000000..1348b93 --- /dev/null +++ b/client/src/store/selectors/boards.js @@ -0,0 +1,11 @@ +export function selectBoardByUserProjects(boardsByID, projectsByName) { + const userProjects = Object.keys(projectsByName); + return Object.keys(boardsByID).reduce((filteredBoardsByID, boardID) => { + const board = boardsByID[boardID]; + const hasProject = board.projects.some(p => userProjects.indexOf(p) !== -1); + if (hasProject) { + filteredBoardsByID[boardID] = board; + } + return filteredBoardsByID; + }, {}); +} \ No newline at end of file