11import React , { Component , PropTypes } from "react" ;
22import ReactCSSTransitionGroup from "react-addons-css-transition-group" ;
33import Organization from "./Organization" ;
4-
5- import GuideStore from "../../stores/GuideStore" ;
64import GuideActions from "../../actions/GuideActions" ;
75
86export 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