Skip to content

Commit

Permalink
Merge pull request #80 from wevote/add_redirects
Browse files Browse the repository at this point in the history
Add redirects for empty ballot and empty following list
  • Loading branch information
pertrai1 committed Feb 22, 2016
2 parents 3e87913 + c832974 commit 299a885
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/js/routes/Ballot/Ballot.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ export default class Ballot extends Component {
}

componentDidMount () {
BallotStore.initialize( (ballot_list) => this.setState({ballot_list}) )
BallotStore.initialize( function(ballot_list){
if (ballot_list.length === 0){
this.props.history.push('settings/location');
} else {
this.setState({ballot_list});
}
}.bind(this));
}

render () {
Expand Down
8 changes: 7 additions & 1 deletion src/js/routes/More/OpinionsFollowed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ export default class OpinionsFollowed extends Component {
}

componentDidMount () {
VoterGuideStore.initializeGuidesFollowed( voter_guide_followed_list => this.setState({ voter_guide_followed_list }));
VoterGuideStore.initializeGuidesFollowed( function(voter_guide_followed_list) {
if (voter_guide_followed_list !== undefined && voter_guide_followed_list.length > 0){
this.setState({ voter_guide_followed_list });
} else {
this.props.history.push('/opinions');
}
}.bind(this));
}

render() {
Expand Down
6 changes: 6 additions & 0 deletions src/js/stores/BallotStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@ const BallotStore = createStore({
}
});

//check for no results, then return empty array rather than creating promises from queue
if (res.ballot_item_list.length === 0 ){
callback(getOrderedBallotItems());
return;
}

// this function polls requests for complete status.
new Promise( (resolve) => {
var counted = [];
Expand Down
13 changes: 8 additions & 5 deletions src/js/stores/VoterGuideStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ function retrieveVoterGuidesFollowedList () {
.withCredentials()
.query({ voter_device_id: cookies.getItem("voter_device_id") })
.end( function (err, res) {
if (err || !res.body.success)
reject(err || res.body.status);
if (err || !res.body.success){
reject(res.body);
// reject(err || res.body.status);
console.log("Reached out to retrieveVoterGuidesFollowedList");
resolve(res.body);
} else {
resolve(res.body);
}
})
);
}
Expand Down Expand Up @@ -224,7 +227,7 @@ const VoterGuideStore = createStore({
.then(addVoterGuidesToFollowToVoterGuideStore) // Uses data retrieved with retrieveVoterGuidesToFollowList
.then(retrieveOrganizations)
.then(data => callback(getItems()))
.catch(err => console.error(err));
.catch(err => callback(err));
},

/**
Expand Down Expand Up @@ -252,7 +255,7 @@ const VoterGuideStore = createStore({
.then(retrieveOrganizationsFollowedList)
.then(addOrganizationsFollowedToStore) // Uses data from retrieveOrganizationsFollowedList
.then(data => callback(getFollowedItems()))
.catch(err => console.error(err));
.catch(err => callback(err));
},

/**
Expand Down

0 comments on commit 299a885

Please sign in to comment.