Skip to content

Commit a1e337d

Browse files
committed
Merge pull request #138 from lisamcho/my_opinions
My opinions: stop following and ignore feature + refactoring
2 parents 71a95d6 + 6887519 commit a1e337d

11 files changed

Lines changed: 186 additions & 1374 deletions

File tree

src/js/actions/.BallotActions.js

Lines changed: 0 additions & 84 deletions
This file was deleted.

src/js/actions/GuideActions.js

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
1-
import AppDispatcher from "../dispatcher/AppDispatcher";
2-
import GuideConstants from "../constants/GuideConstants";
3-
4-
const GuideActions = {
5-
/**
6-
* @param {String} id to ignore
7-
*/
8-
ignore: function (id) {
9-
AppDispatcher.dispatch({
10-
actionType: GuideConstants.ORG_IGNORE, id
11-
});
12-
},
13-
14-
/**
15-
* @param {String} id to follow
16-
*/
17-
follow: function (id) {
18-
AppDispatcher.dispatch({
19-
actionType: GuideConstants.ORG_FOLLOW, id
20-
});
21-
}
22-
};
23-
24-
export default GuideActions;
1+
var Dispatcher = require("../dispatcher/Dispatcher");
2+
3+
var GuideActions = (function (_Dispatcher) {
4+
function _GuideActions () { }
5+
6+
_GuideActions.prototype.ignore = function ignore (we_vote_id) {
7+
_Dispatcher.loadEndpoint("organizationFollowIgnore", { organization_we_vote_id: we_vote_id} );
8+
};
9+
10+
_GuideActions.prototype.follow = function follow (we_vote_id) {
11+
_Dispatcher.loadEndpoint("organizationFollow", { organization_we_vote_id: we_vote_id} );
12+
};
13+
14+
_GuideActions.prototype.stopFollowing = function stopFollowing (we_vote_id) {
15+
_Dispatcher.loadEndpoint("organizationStopFollowing", { organization_we_vote_id: we_vote_id} );
16+
};
17+
18+
_GuideActions.prototype.retrieveGuidesToFollow = function retrieveGuidesToFollow (election_id){
19+
_Dispatcher.loadEndpoint("voterGuidesToFollowRetrieve", { google_civic_election_id: election_id });
20+
};
21+
22+
_GuideActions.prototype.retrieveGuidesFollowed = function retrieveGuidesFollowed (){
23+
_Dispatcher.loadEndpoint("voterGuidesFollowedRetrieve");
24+
};
25+
26+
return new _GuideActions();
27+
}(Dispatcher));
28+
29+
module.exports = GuideActions;

src/js/components/FollowOrIgnore.jsx

Lines changed: 8 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,26 @@
11
"use strict";
2-
32
import React, { Component, PropTypes } from "react";
43
import { Button, ButtonToolbar } from "react-bootstrap";
5-
import VoterGuideStore from "../stores/VoterGuideStore";
4+
import GuideActions from "../actions/GuideActions";
65

76
export default class FollowOrIgnore extends Component {
87
static propTypes = {
9-
organization_we_vote_id: PropTypes.string,
10-
action: PropTypes.object.isRequired,
11-
action_text: PropTypes.string,
12-
OrganizationFollowed: PropTypes.string
8+
organization_we_vote_id: PropTypes.string.isRequired,
139
};
1410

15-
constructor(props) {
16-
super(props);
17-
18-
this.state = {
19-
OrganizationFollowed: this.props.OrganizationFollowed,
20-
};
21-
}
22-
23-
toggleFollow (evt) {
24-
evt.stopPropagation();
25-
if (this.state.OrganizationFollowed == "Yes")
26-
this.props.action.stopFollowingOrg(this.props.organization_we_vote_id);
27-
else
28-
this.props.action.followOrg(this.props.organization_we_vote_id);
29-
}
30-
31-
ignoreOrgLocal (evt) {
32-
evt.stopPropagation();
33-
this.props.action.ignoreOrg(this.props.organization_we_vote_id);
34-
}
11+
render () {
12+
var ignoreFunc = GuideActions.ignore.bind(this, this.props.organization_we_vote_id);
13+
var stopFollowingFunc = GuideActions.stopFollowing.bind(this, this.props.organization_we_vote_id);
3514

36-
componentDidMount () {
37-
this.changeListener = this._onChange.bind(this);
38-
VoterGuideStore.addChangeListener(this.changeListener);
39-
}
40-
41-
componentWillUnmount() {
42-
VoterGuideStore.removeChangeListener(this.changeListener);
43-
}
44-
45-
_onChange () {
46-
VoterGuideStore.getVoterGuideByWeVoteId(
47-
this.props.we_vote_id, voter_guide => this.setState({
48-
OrganizationFollowed: voter_guide.OrganizationFollowed,
49-
})
50-
);
51-
}
52-
53-
render() {
5415
var floatRight = {
5516
float: "right"
5617
};
57-
var action_text;
58-
if (this.props.action_text) {
59-
action_text = this.props.action_text;
60-
} else {
61-
if (this.state.OrganizationFollowed == "Yes") {
62-
action_text = "Followed";
63-
} else {
64-
action_text = "Follow";
65-
}
66-
}
67-
var ignore_code;
68-
if (this.state.OrganizationFollowed != "Yes") {
69-
ignore_code = <Button bsStyle="danger" bsSize="small" onClick={this.ignoreOrgLocal.bind(this)}>Ignore</Button>
70-
}
71-
18+
7219
return (
7320
<span style={floatRight}>
7421
<ButtonToolbar>
75-
<Button bsStyle="info" bsSize="small" onClick={this.toggleFollow.bind(this)}>{action_text}</Button>
76-
{ignore_code}
22+
<Button bsStyle="info" bsSize="small" onClick={stopFollowingFunc}>Following</Button>
23+
<Button bsStyle="danger" bsSize="small" onClick={ignoreFunc}>Ignore</Button>
7724
</ButtonToolbar>
7825
</span>
7926
);

src/js/components/VoterGuide/GuideList.jsx

Lines changed: 13 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React, { Component, PropTypes } from "react";
22
import ReactCSSTransitionGroup from "react-addons-css-transition-group";
33
import Organization from "./Organization";
4-
5-
import GuideStore from "../../stores/GuideStore";
64
import GuideActions from "../../actions/GuideActions";
75

86
export default class GuideList extends Component {
@@ -11,88 +9,33 @@ export default class GuideList extends Component {
119
organizations: PropTypes.array
1210
};
1311

14-
constructor (props) {
15-
super(props);
16-
17-
var { organizations: orgs } = this.props;
18-
19-
/**
20-
* this is being done because of issue #85...
21-
* https://github.com/wevote/WeVoteServer/issues/85
22-
23-
* READ:
24-
* -- GuideStore is naturally unique per item key
25-
* -- so... store data and then convert it to an array
26-
27-
* SEE BELOW:
28-
* GuideStore.addOrganization
29-
* then ->
30-
* GuideStore.toArray()
31-
32-
* this is inefficient but it needs to be done to create unique
33-
* organizations in the list because the backend is not unique.
34-
*/
35-
36-
orgs.forEach(GuideStore.addOrganization);
37-
this.state = { orgList: GuideStore.toArray() };
38-
39-
}
40-
41-
componentDidMount () {
42-
GuideStore.addChangeListener(this.storeChange.bind(this));
43-
}
44-
45-
componentWillUnmount () {
46-
GuideStore.removeChangeListener(this.storeChange.bind(this));
47-
}
48-
49-
storeChange () {
50-
this.setState({ orgList: GuideStore.toArray() });
51-
}
52-
5312
/**
54-
* when a user clicks ignore, make the org disappear
55-
* @param {Integer} i index in array of the item clicked
13+
* when a user clicks ignore or follow, make the org disappear
5614
*/
57-
handleIgnore (i) {
58-
59-
var {
60-
organization_we_vote_id: id
61-
} = this.state.orgList.slice().splice(i, 1)[0];
62-
15+
handleIgnore (id) {
6316
GuideActions.ignore(id);
64-
6517
}
6618

67-
handleFollow (i) {
68-
var {
69-
organization_we_vote_id: id
70-
} = this.state.orgList.slice().splice(i, 1)[0];
71-
19+
handleFollow (id) {
7220
GuideActions.follow(id);
7321
}
7422

7523
render () {
7624

77-
let orgs = this.state.orgList.map( (org, i) => {
78-
79-
var {
80-
organization_we_vote_id: id,
81-
voter_guide_display_name: displayName,
82-
voter_guide_image_url: imageUrl,
83-
twitter_followers_count: followers
84-
} = org;
85-
86-
// Key can be id once issue #85 is resolved on server
87-
// https://github.com/wevote/WeVoteServer/issues/85
88-
const key = id + "-" + i;
25+
let orgs = this.props.organizations.map( (org, i) => {
8926

9027
const organization =
91-
<Organization id={id} key={key} displayName={displayName} followers={followers} imageUrl={imageUrl} >
92-
<button className="btn btn-primary follow" onClick={this.handleFollow.bind(this, i)}>
28+
<Organization id={org.organization_we_vote_id}
29+
key={org.organization_we_vote_id}
30+
displayName={org.voter_guide_display_name}
31+
followers={org.twitter_followers_count}
32+
imageUrl={org.voter_guide_image_url} >
33+
<button className="btn btn-primary follow"
34+
onClick={this.handleFollow.bind(this, org.organization_we_vote_id)}>
9335
Follow
9436
</button>
95-
<button className="btn btn-default ignore" onClick={this.handleIgnore.bind(this, i)}>
37+
<button className="btn btn-default ignore"
38+
onClick={this.handleIgnore.bind(this, org.organization_we_vote_id)}>
9639
Ignore
9740
</button>
9841
</Organization>;

0 commit comments

Comments
 (0)