This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
Sphere/app/components/builds/BuildList.js
2016-05-05 14:18:07 +01:00

80 lines
2.1 KiB
JavaScript

import React from 'react-native';
import GiftedListView from 'react-native-gifted-listview';
import GlobalStyles from '../../settings/styles';
import { getProjectRecentBuilds } from '../../actions';
import loaderHandler from 'react-native-busy-indicator/LoaderHandler';
import BuildItem from './BuildItem';
import BuildItemEnd from './BuildItemEnd';
import { connect } from 'react-redux';
import _ from 'underscore';
const {
StyleSheet,
View
} = React;
const styles = StyleSheet.create({
listView: {
flex: 1,
flexDirection: 'column',
alignItems: 'stretch',
justifyContent: 'center',
flexWrap: 'wrap',
paddingHorizontal: 5
},
});
export class BuildList extends React.Component {
constructor(props) {
super(props);
this._fetch = this._fetch.bind(this);
this.renderRow = this.renderRow.bind(this);
this.renderLimit = 20;
}
renderRow(build) {
if (build.build_time_millis < 1) {
return null;
}
const statusColour = GlobalStyles.get('CIRCLE_TEST_COLOURS').get(build.status.toUpperCase());
return <BuildItem build={build} project={this.props.project} statusColour={statusColour} />;
}
_fetch(page = 1, callback, options) {
const project = this.props.project;
const actionCallback = function (recentBuilds) {
recentBuilds = _.sortBy(recentBuilds, (b) => b.stop_time).reverse();
callback(recentBuilds, {
allLoaded: recentBuilds.length < this.renderLimit
});
loaderHandler.hideLoader();
}.bind(this);
this.props.getProjectRecentBuilds(
project.username,
project.reponame,
this.renderLimit,
this.renderLimit * (page - 1),
actionCallback
);
}
render() {
return (
<View style={styles.listView}>
<GiftedListView
rowView={this.renderRow}
refreshable={true}
onFetch={this._fetch}
paginationAllLoadedView={() => <BuildItemEnd />}/>
</View>
);
}
};
function mapStateToProps(state) {
return {
recentBuilds: state.recentBuilds,
};
}
export default connect(mapStateToProps, { getProjectRecentBuilds }) (BuildList);