gengitkan/client/src/components/HomePage/HomePage.tsx

84 lines
2.3 KiB
TypeScript
Raw Normal View History

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';
2020-04-30 13:02:56 +02:00
import { connect, DispatchProp } from 'react-redux';
2019-12-01 22:12:13 +01:00
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
2020-04-30 13:02:56 +02:00
export interface HomePageProps extends DispatchProp {
boards: any[]
}
export class HomePage extends React.Component<HomePageProps> {
2019-11-28 14:12:48 +01:00
render() {
return (
<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;
}, [])
2020-04-30 13:02:56 +02:00
.map((row: any, rowIndex: number) => {
const tiles = row.map((board: any) => {
2019-12-01 22:12:13 +01:00
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
}
}
2020-04-30 13:02:56 +02:00
export const ConnectedHomePage = connect(function(state: any) {
2019-12-01 22:12:13 +01:00
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);