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/ProjectList.js

81 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-02-21 12:05:14 +00:00
import React from 'react-native';
import GiftedListView from 'react-native-gifted-listview';
2016-02-21 12:05:14 +00:00
import ProjectItem from './ProjectItem';
2016-05-05 13:34:10 +01:00
import { connect } from 'react-redux';
import { getProjects } from '../../actions';
import loaderHandler from 'react-native-busy-indicator/LoaderHandler';
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
StyleSheet,
View
2016-02-21 12:05:14 +00:00
} = React;
2016-02-23 23:12:32 +00:00
const styles = StyleSheet.create({
listView: {
2016-02-21 12:05:14 +00:00
flex: 1,
2016-02-23 23:12:32 +00:00
flexDirection: 'column',
alignItems: 'stretch',
2016-02-21 12:05:14 +00:00
justifyContent: 'center',
flexWrap: 'wrap',
2016-02-24 18:00:13 +00:00
paddingHorizontal: 5
2016-02-21 12:05:14 +00:00
},
});
2016-05-05 13:34:10 +01:00
export class ProjectList extends React.Component {
2016-02-21 12:05:14 +00:00
constructor(props) {
super(props);
this.renderRow = this.renderRow.bind(this);
this._fetch = this._fetch.bind(this);
}
2016-02-23 23:12:32 +00:00
_sortByDate(projects) {
return projects.sort(function (a, b) {
const keyA = a.username + '/' + a.reponame;
const keyB = b.reponame + '/' + b.username;
if (keyA < keyB) { return -1; }
if (keyA > keyB) { return 1; }
return 0;
}.bind(this));
}
2016-02-21 12:05:14 +00:00
renderRow(project) {
2016-05-05 13:34:10 +01:00
return <ProjectItem project={project} userDetails={this.props.userDetails} nav={this.props.nav} />;
}
_fetch(page, callback, options) {
2016-05-05 13:34:10 +01:00
const actionCallback = function (data) {
this._sortByDate(data);
callback(data);
loaderHandler.hideLoader();
2016-05-05 13:34:10 +01:00
}.bind(this);
this.props.getProjects(actionCallback);
2016-02-21 12:05:14 +00:00
}
render() {
2016-05-05 13:34:10 +01:00
if (!this.props.token) {
return null; // If there's no token, we can't do anything, so wait
}
2016-02-21 12:05:14 +00:00
return (
<View style={styles.listView}>
<GiftedListView
rowView={this.renderRow}
refreshable={true}
pagination={false}
onFetch={this._fetch} />
</View>
2016-02-21 12:05:14 +00:00
);
}
};
2016-05-05 13:34:10 +01:00
function mapStateToProps(state) {
return {
userDetails: state.user.toJS(),
projects: state.allProjects.toJS(),
token: state.user.get('token')
};
}
export default connect(mapStateToProps, { getProjects }) (ProjectList);