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/projects/ProjectItem.js

85 lines
2.1 KiB
JavaScript
Raw Normal View History

2016-02-21 12:05:14 +00:00
import React from 'react-native';
2016-02-23 23:12:32 +00:00
import GlobalStyles from '../../settings/styles';
import { getProjectRecentBuilds } from '../../api/CircleCI';
2016-02-21 12:05:14 +00:00
2016-02-23 23:12:32 +00:00
const {
2016-02-21 12:05:14 +00:00
View,
Text,
2016-02-23 23:12:32 +00:00
StyleSheet
2016-02-21 12:05:14 +00:00
} = React;
2016-02-23 23:12:32 +00:00
const styles = StyleSheet.create({
container: {
flex: 1,
height: 70,
alignItems: 'stretch',
backgroundColor: GlobalStyles.get('CIRCLE_ITEM_BG'),
borderBottomColor: GlobalStyles.get('CIRCLE_ITEM_BORDER'),
borderBottomWidth: 1,
marginBottom: 5,
flexDirection: 'row'
},
cell: {
paddingHorizontal: 4,
paddingVertical: 2
},
imageCell: {
width: 45,
},
repoName: {
fontSize: 14,
fontWeight: '500'
}
});
2016-02-21 12:05:14 +00:00
export default class ProjectItem extends React.Component {
2016-02-23 23:12:32 +00:00
constructor() {
super();
this.state = {
recentBuild: false
};
this._displayMoreInfo = this._displayMoreInfo.bind(this);
}
componentDidMount() {
getProjectRecentBuilds(this.props.project.username, this.props.project.reponame).then(function (recentBuild) {
this.setState({ recentBuild: recentBuild[0] });
}.bind(this));
}
_displayMoreInfo(mostRecentBuild) {
let seconds = Math.floor(mostRecentBuild.build_time_millis / 1000);
const minutes = Math.floor(seconds / 60);
seconds = seconds - (minutes * 60);
const format = minutes + ':' + seconds;
return (
<Text>{ format }</Text>
);
}
2016-02-21 12:05:14 +00:00
render() {
2016-02-23 23:12:32 +00:00
console.log(this.props.userDetails);
const project = this.props.project;
const mostRecentBuild = this.state.recentBuild;
const statusColour = mostRecentBuild.failed ? '#ED5C5C' : '#42C88A';
let username;
if (this.props.userDetails && this.props.userDetails.login !== project.username) {
username = project.username;
} else {
username = 'me';
}
const buildDetails = mostRecentBuild ? this._displayMoreInfo(mostRecentBuild) : null;
2016-02-21 12:05:14 +00:00
return (
2016-02-23 23:12:32 +00:00
<View style={styles.container}>
<View style={[styles.imageCell, {backgroundColor: statusColour}]}>
</View>
<View style={styles.cell}>
<Text style={styles.repoName}>{username}/{project.reponame}</Text>
{ buildDetails }
</View>
</View>
2016-02-21 12:05:14 +00:00
);
}
};