Redux build list
This commit is contained in:
parent
255aac00a9
commit
d1e52d3b81
4 changed files with 48 additions and 7 deletions
|
@ -25,3 +25,18 @@ export function getProjects(callback) {
|
||||||
{ callback }
|
{ callback }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const GET_PROJECT_RECENT_BUILDS = makeAsyncActionSet('GET_PROJECT_RECENT_BUILDS');
|
||||||
|
export function getProjectRecentBuilds(user, repo, limit, offset, callback) {
|
||||||
|
return buildAsyncAction(
|
||||||
|
GET_PROJECT_RECENT_BUILDS,
|
||||||
|
endpoints.get('PROJECT_RECENTS').param({ user, repo }).query({ limit, offset }),
|
||||||
|
methods.GET,
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
callback,
|
||||||
|
ident: `${user}/${repo}`
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import React from 'react-native';
|
import React from 'react-native';
|
||||||
import GiftedListView from 'react-native-gifted-listview';
|
import GiftedListView from 'react-native-gifted-listview';
|
||||||
import GlobalStyles from '../../settings/styles';
|
import GlobalStyles from '../../settings/styles';
|
||||||
|
import { getProjectRecentBuilds } from '../../actions';
|
||||||
import loaderHandler from 'react-native-busy-indicator/LoaderHandler';
|
import loaderHandler from 'react-native-busy-indicator/LoaderHandler';
|
||||||
import BuildItem from './BuildItem';
|
import BuildItem from './BuildItem';
|
||||||
import BuildItemEnd from './BuildItemEnd';
|
import BuildItemEnd from './BuildItemEnd';
|
||||||
import { getProjectRecentBuilds } from '../../api/CircleCI';
|
import { connect } from 'react-redux';
|
||||||
import _ from 'underscore';
|
import _ from 'underscore';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
@ -23,7 +24,7 @@ const styles = StyleSheet.create({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default class BuildList extends React.Component {
|
export class BuildList extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this._fetch = this._fetch.bind(this);
|
this._fetch = this._fetch.bind(this);
|
||||||
|
@ -41,14 +42,20 @@ export default class BuildList extends React.Component {
|
||||||
|
|
||||||
_fetch(page = 1, callback, options) {
|
_fetch(page = 1, callback, options) {
|
||||||
const project = this.props.project;
|
const project = this.props.project;
|
||||||
getProjectRecentBuilds(project.username, project.reponame, this.renderLimit, this.renderLimit * (page - 1))
|
const actionCallback = function (recentBuilds) {
|
||||||
.then((recentBuilds) => {
|
|
||||||
recentBuilds = _.sortBy(recentBuilds, (b) => b.stop_time).reverse();
|
recentBuilds = _.sortBy(recentBuilds, (b) => b.stop_time).reverse();
|
||||||
loaderHandler.hideLoader();
|
|
||||||
callback(recentBuilds, {
|
callback(recentBuilds, {
|
||||||
allLoaded: recentBuilds.length < this.renderLimit
|
allLoaded: recentBuilds.length < this.renderLimit
|
||||||
});
|
});
|
||||||
});
|
loaderHandler.hideLoader();
|
||||||
|
}.bind(this);
|
||||||
|
this.props.getProjectRecentBuilds(
|
||||||
|
project.username,
|
||||||
|
project.reponame,
|
||||||
|
this.renderLimit,
|
||||||
|
this.renderLimit * (page - 1),
|
||||||
|
actionCallback
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -63,3 +70,11 @@ export default class BuildList extends React.Component {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function mapStateToProps(state) {
|
||||||
|
return {
|
||||||
|
recentBuilds: state.recentBuilds,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, { getProjectRecentBuilds }) (BuildList);
|
||||||
|
|
|
@ -3,9 +3,11 @@ import * as storage from 'redux-storage';
|
||||||
|
|
||||||
import user from './user';
|
import user from './user';
|
||||||
import allProjects from './allProjects';
|
import allProjects from './allProjects';
|
||||||
|
import recentBuilds from './recentBuilds';
|
||||||
|
|
||||||
|
|
||||||
export default storage.reducer(combineReducers({
|
export default storage.reducer(combineReducers({
|
||||||
user,
|
user,
|
||||||
allProjects
|
allProjects,
|
||||||
|
recentBuilds
|
||||||
}));
|
}));
|
||||||
|
|
9
app/reducers/recentBuilds.js
Normal file
9
app/reducers/recentBuilds.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import * as actions from '../actions';
|
||||||
|
import { Map } from 'immutable';
|
||||||
|
|
||||||
|
export default function recentBuilds(state = Map(), action) {
|
||||||
|
if (action.type === actions.GET_PROJECT_RECENT_BUILDS.SUCCESS) {
|
||||||
|
return state.set(action.meta.ident, action.payload); // Not ideal!
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
};
|
Reference in a new issue