2019-11-28 14:12:48 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { Page } from '../Page';
|
2019-12-01 22:12:13 +01:00
|
|
|
import { BoardCard } from './BoardCard';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { fetchBoards } from '../../store/actions/boards';
|
2019-12-05 13:57:00 +01:00
|
|
|
import { fetchProjects } from '../../store/actions/projects';
|
|
|
|
import { selectBoardByUserProjects } from '../../store/selectors/boards';
|
2019-11-28 14:12:48 +01:00
|
|
|
|
|
|
|
export class HomePage extends React.Component {
|
|
|
|
render() {
|
|
|
|
return (
|
2019-12-05 22:46:07 +01:00
|
|
|
<Page title="GenGitKan - Accueil">
|
2019-12-01 22:12:13 +01:00
|
|
|
<div className="container is-fluid">
|
2019-12-05 22:37:09 +01:00
|
|
|
<div className="level has-margin-top-normal">
|
2019-12-01 22:12:13 +01:00
|
|
|
<div className="level-left"></div>
|
|
|
|
<div className="level-right">
|
|
|
|
<div className="buttons">
|
|
|
|
<a className="button is-primary" href="#/boards/new">
|
|
|
|
<span className="icon">
|
|
|
|
<i className="fas fa-plus"></i>
|
|
|
|
</span>
|
|
|
|
<span>Nouveau tableau</span>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{ this.renderBoards() }
|
|
|
|
</div>
|
2019-11-28 14:12:48 +01:00
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
}
|
2019-12-01 22:12:13 +01:00
|
|
|
|
|
|
|
renderBoards() {
|
|
|
|
const { boards } = this.props;
|
|
|
|
const rows = Object.values(boards)
|
|
|
|
.reduce((boardRows, board, index) => {
|
|
|
|
if (index % 3 === 0) {
|
|
|
|
boardRows.push([]);
|
|
|
|
}
|
|
|
|
boardRows[boardRows.length-1].push(board);
|
|
|
|
return boardRows;
|
|
|
|
}, [])
|
|
|
|
.map((row, rowIndex) => {
|
|
|
|
const tiles = row.map((board) => {
|
|
|
|
return (
|
|
|
|
<div key={`board-${board.id}`} className={`tile is-parent is-4`}>
|
|
|
|
<div className="tile is-child">
|
|
|
|
<BoardCard board={board} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
return (
|
|
|
|
<div key={`boards-row-${rowIndex}`} className="tile">
|
|
|
|
{tiles}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="tile is-ancestor is-vertical">
|
|
|
|
{ rows }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.props.dispatch(fetchBoards());
|
2019-12-05 13:57:00 +01:00
|
|
|
this.props.dispatch(fetchProjects());
|
2019-12-01 22:12:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export const ConnectedHomePage = connect(function(state) {
|
|
|
|
return {
|
2019-12-05 13:57:00 +01:00
|
|
|
boards: selectBoardByUserProjects(state.boards.byID, state.projects.byName)
|
2019-12-01 22:12:13 +01:00
|
|
|
};
|
|
|
|
})(HomePage);
|