Filter visible boards by user projects

This commit is contained in:
wpetit 2019-12-05 13:57:00 +01:00
parent d374999d88
commit 1f3f4bdeed
2 changed files with 15 additions and 1 deletions

View File

@ -3,6 +3,8 @@ import { Page } from '../Page';
import { BoardCard } from './BoardCard'; import { BoardCard } from './BoardCard';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { fetchBoards } from '../../store/actions/boards'; import { fetchBoards } from '../../store/actions/boards';
import { fetchProjects } from '../../store/actions/projects';
import { selectBoardByUserProjects } from '../../store/selectors/boards';
export class HomePage extends React.Component { export class HomePage extends React.Component {
render() { render() {
@ -65,12 +67,13 @@ export class HomePage extends React.Component {
componentDidMount() { componentDidMount() {
this.props.dispatch(fetchBoards()); this.props.dispatch(fetchBoards());
this.props.dispatch(fetchProjects());
} }
} }
export const ConnectedHomePage = connect(function(state) { export const ConnectedHomePage = connect(function(state) {
return { return {
boards: state.boards.byID, boards: selectBoardByUserProjects(state.boards.byID, state.projects.byName)
}; };
})(HomePage); })(HomePage);

View File

@ -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;
}, {});
}