diff --git a/client/src/App.js b/client/src/App.js index 29ff278..05b023d 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -6,18 +6,29 @@ import { Route, Redirect } from "react-router-dom"; +import { connect } from 'react-redux' import Header from './components/Header'; import Commits from './components/Commits'; import Pulls from './components/Pulls'; +import Loading from './components/Loading' import configureStore from './redux/store'; +import { loadBuilders } from './redux/actions' +import { LOAD_STATE } from './redux/constants' + + const store = configureStore(); -export default function App() { - return ( - - -
-
+class App extends React.PureComponent { + // things which are needed regardles the current view + componentDidMount() { + this.props.dispatch(loadBuilders()) + } + + render() { + return ( + +
+ {this.props.canRender ? @@ -26,7 +37,22 @@ export default function App() { -
+ : } + ) + } +} + +function mapStateToProps(state) { + return ({canRender: state.isLoading.buildersDataState === LOAD_STATE.LOADED}) +} + +const WrappedApp = connect(mapStateToProps)(App) + +export default function outerApp() { + return ( + + + ); diff --git a/client/src/components/Branches.js b/client/src/components/Branches.js index 3eb654f..751a384 100644 --- a/client/src/components/Branches.js +++ b/client/src/components/Branches.js @@ -7,11 +7,7 @@ import { DropdownMenu, DropdownItem } from 'reactstrap'; -import { - loadBranches, - loadCommits, - loadBuilders -} from '../redux/actions'; +import { loadBranches, loadCommits } from '../redux/actions'; class Branches extends React.Component { constructor(props) { @@ -21,7 +17,6 @@ class Branches extends React.Component { }; } componentDidMount() { - this.props.loadBuilders(); this.props.loadBranches(); } @@ -76,8 +71,7 @@ const mapStateToProps = ({ branches }) => ({ const mapDispatchToProps = dispatch => ({ loadCommits: (branch, next) => dispatch(loadCommits(branch, next)), - loadBranches: () => dispatch(loadBranches()), - loadBuilders: () => dispatch(loadBuilders()) + loadBranches: () => dispatch(loadBranches()) }); export default connect( diff --git a/client/src/components/Commits.js b/client/src/components/Commits.js index e573041..8a63138 100644 --- a/client/src/components/Commits.js +++ b/client/src/components/Commits.js @@ -6,17 +6,15 @@ import Branches from './Branches'; import './styles/Commit.css'; import CommitsCard from './CommitsCard'; import Loading from './Loading'; +import Pagination from './Pagination' +import { LOAD_STATE } from '../redux/constants' + class Commits extends React.PureComponent { componentDidMount() { - this.props.loadCommits(this.props.branch); - this.props.loadBuilds(); - } - - componentDidUpdate(prevProps) { - if (this.props.branch !== prevProps.branch) { - this.props.loadCommits(this.props.branch) - this.props.loadBuilds() + if (this.props.firstLoad) { + this.props.loadCommits(this.props.branch, 1); // TODO: remove the hack + this.props.loadBuilds(); } } @@ -35,7 +33,7 @@ class Commits extends React.PureComponent { }; render() { - const {branch, page} = this.props; + const { branch, currentPage } = this.props return (
@@ -46,7 +44,7 @@ class Commits extends React.PureComponent {
- {this.props.isLoading.load ? ( + {this.props.isLoading ? ( @@ -60,38 +58,10 @@ class Commits extends React.PureComponent { Err:{this.props.error} ) : ( -
-