Skip to content

Commit

Permalink
Add page for valid address with no google civic election number
Browse files Browse the repository at this point in the history
  • Loading branch information
lisamburns committed Feb 23, 2016
1 parent b6adddd commit f191e53
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/js/Root.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Location from "./routes/Settings/Location";
import BallotIndex from "./routes/Ballot/BallotIndex";
import Ballot from "./routes/Ballot/Ballot";
import Candidate from "./routes/Ballot/Candidate";
import EmptyBallot from "./routes/Ballot/EmptyBallot";

/* Ballot Off-shoot Pages */
import Opinions from "./routes/Opinions";
Expand Down Expand Up @@ -83,6 +84,8 @@ const routes = (firstVisit, voter) =>
<IndexRoute component={Ballot} />
<Route path="/candidate/:we_vote_id" component={Candidate} />
</Route>

<Route path="ballot/empty" component={EmptyBallot} />
{/*
<Route path="org/:id" component={Organization}/>
<Route path="measure/:id" component={Measure} />
Expand Down
1 change: 1 addition & 0 deletions src/js/routes/Ballot/Candidate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class Candidate extends Component {

componentDidMount(){
this.changeListener = this._onChange.bind(this);
BallotStore.initialize(function(){console.log("Initialized ballot in background")});
BallotStore.addChangeListener(this.changeListener);
var candidate = BallotStore.getOrFetchCandidateByWeVoteId(this.props.params.we_vote_id);
if (candidate) {
Expand Down
27 changes: 27 additions & 0 deletions src/js/routes/Ballot/EmptyBallot.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { Component, PropTypes } from 'react';
import { Link } from 'react-router';

export default class EmptyBallot extends Component {
static propTypes = {
};

constructor (props) {
super(props);
}

render () {
return (
<div>
<div className="container-fluid well gutter-top--small fluff-full1">
<h3 className="text-center">
Sorry
</h3>
<span className="small">
Our data providers don't have ballot data for your address yet.
Please check back 1-2 weeks before your election day
</span>
</div>
</div>
);
}
}
15 changes: 10 additions & 5 deletions src/js/routes/Settings/Location.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from "react";
import { Button, ButtonToolbar } from "react-bootstrap";
import HeaderBackNavigation from "../../components/Navigation/HeaderBackNavigation";
import VoterStore from "../../stores/VoterStore";
import BallotStore from "../../stores/BallotStore";

export default class Location extends Component {
constructor (props) {
Expand All @@ -23,10 +24,14 @@ export default class Location extends Component {

saveLocation () {
var { location } = this.state;
VoterStore.saveLocation( location, (err) => {
if (err) return console.error(err);

window.location.href = "/ballot";
VoterStore.saveLocation( location, (res) => {

This comment has been minimized.

Copy link
@fi0rini

fi0rini Feb 23, 2016

Contributor

this is the preferred method, to alter the view instead of reloading the page but the dispatcher is not wired to support this functionality.

This comment has been minimized.

Copy link
@lisamburns

lisamburns Feb 23, 2016

Author Contributor

@nf071590 Sorry can you explain more. What is the preferred method?

if (res){
this.props.history.push('/ballot');
} else {
BallotStore.initialize(function(){}); // reinitialize ballot in case old ballot items from old addresses are stored.
this.props.history.push('/ballot/empty');
}
}, (err) =>{

});
}
Expand All @@ -52,7 +57,7 @@ export default class Location extends Component {
name="address"
value={location}
className="form-control"
defaultValue="Oakland, CA"
defaultValue="Oakland, CA"
/>

<div className="gutter-top--small">
Expand Down
12 changes: 9 additions & 3 deletions src/js/stores/VoterStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,22 @@ const VoterStore = createStore({
saveLocation: function (location, callback) {
if (typeof location !== "string") throw new Error("missing location to save");
if (callback instanceof Function === false) throw new Error("missing callback function");
var that = this;

$ajax({
type: "GET",
data: { text_for_map_search: location },
endpoint: "voterAddressSave",
success: (res) => {
var { text_for_map_search: savedLocation } = res;

_setLocation(savedLocation);

This comment has been minimized.

Copy link
@fi0rini

fi0rini Feb 23, 2016

Contributor

is location still being stored in the store?

This comment has been minimized.

Copy link
@lisamburns

lisamburns Feb 23, 2016

Author Contributor

@nf071590 No it's not, good point. I don't know why I deleted that, and directly called set Cookie (without updating the store). Actually it introduces a bug where when you update the address, navigate away from the My Location page, and then go back to it, it does not get updated. Do you want to create a pull request to put back in? Sorry it looks like this already merged before code review.

callback(null, savedLocation);
cookies.setItem('location', savedLocation);

if (res.success){ // Successfully saved address and found Google Civic Election ID
callback(true, savedLocation);

This comment has been minimized.

Copy link
@fi0rini

fi0rini Feb 23, 2016

Contributor

Why is true being passed to the callback function? callback has signature (error, location) indicating that callback(true, location) is an error

This comment has been minimized.

Copy link
@lisamburns

lisamburns Feb 23, 2016

Author Contributor

The callback function in the component needs to know whether to continue as planned and reload the ballot or whether to redirect to the message page that says there's no ballot for that address. This isn't the greatest implementation, I think we should have some sort of messages framework in place, but to add to TODOS. What do you think?

} else if (res.status.indexOf("GOOGLE_CIVIC_API_ERROR") != -1){ // Saved Address but couldn't find election ID
console.log("No election for the address");
callback(false, savedLocation);
}
},
error: (err) => callback(err, null)
});
Expand Down

0 comments on commit f191e53

Please sign in to comment.