/
OrganizationVoterGuideCandidateItem.jsx
255 lines (232 loc) · 10.5 KB
/
OrganizationVoterGuideCandidateItem.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
import React, { Component } from "react";
import PropTypes from "prop-types";
import { Link } from "react-router";
import BookmarkToggle from "../Bookmarks/BookmarkToggle";
import CandidateStore from "../../stores/CandidateStore";
import { historyPush } from "../../utils/cordovaUtils";
import ImageHandler from "../ImageHandler";
import ItemSupportOpposeRaccoon from "../Widgets/ItemSupportOpposeRaccoon";
import { renderLog } from "../../utils/logging";
import OfficeNameText from "../Widgets/OfficeNameText";
import ParsedTwitterDescription from "../Twitter/ParsedTwitterDescription";
import SupportStore from "../../stores/SupportStore";
import VoterGuideStore from "../../stores/VoterGuideStore";
import { abbreviateNumber, numberWithCommas } from "../../utils/textFormat";
// This is related to /js/components/Ballot/CandidateItem.jsx
export default class OrganizationVoterGuideCandidateItem extends Component {
static propTypes = {
ballot_item_display_name: PropTypes.string.isRequired,
candidate_photo_url_large: PropTypes.string.isRequired,
candidate_photo_url_medium: PropTypes.string,
contest_office_name: PropTypes.string,
showLargeImage: PropTypes.bool,
commentButtonHide: PropTypes.bool,
hideOpinionsToFollow: PropTypes.bool,
hidePositionStatement: PropTypes.bool,
organization_we_vote_id: PropTypes.string.isRequired,
party: PropTypes.string,
position_list: PropTypes.array,
showPositionsInYourNetworkBreakdown: PropTypes.bool,
showPositionStatementActionBar: PropTypes.bool,
twitter_description: PropTypes.string,
twitter_followers_count: PropTypes.number,
twitter_handle: PropTypes.string,
we_vote_id: PropTypes.string.isRequired, // This is the candidate_we_vote_id
link_to_ballot_item_page: PropTypes.bool,
};
constructor (props) {
super(props);
this.state = {
candidate_we_vote_id: "",
hide_position_statement: this.props.hidePositionStatement,
maximum_organization_display: 5,
office_we_vote_id: "",
organization_we_vote_id: "",
transitioning: false,
};
this.getCandidateLink = this.getCandidateLink.bind(this);
this.getOfficeLink = this.getOfficeLink.bind(this);
this.goToCandidateLink = this.goToCandidateLink.bind(this);
this.goToOfficeLink = this.goToOfficeLink.bind(this);
}
componentDidMount () {
this.voterGuideStoreListener = VoterGuideStore.addListener(this.onVoterGuideStoreChange.bind(this));
this.onVoterGuideStoreChange();
this.supportStoreListener = SupportStore.addListener(this.onSupportStoreChange.bind(this));
let supportProps = SupportStore.get(this.props.we_vote_id);
if (supportProps !== undefined) {
this.setState({
supportProps: supportProps,
transitioning: false,
});
}
// console.log("OrganizationVoterGuideCandidateItem, this.props:", this.props);
if (this.props.we_vote_id) {
// If here we want to get the candidate so we can get the office_we_vote_id
let candidate = CandidateStore.getCandidate(this.props.we_vote_id);
this.setState({
candidate_we_vote_id: this.props.we_vote_id,
office_we_vote_id: candidate.office_we_vote_id,
});
}
if (this.props.organization_we_vote_id) {
this.setState({
organization_we_vote_id: this.props.organization_we_vote_id,
});
}
}
componentWillUnmount () {
this.voterGuideStoreListener.remove();
this.supportStoreListener.remove();
}
onVoterGuideStoreChange (){
// We just want to trigger a re-render
this.setState({ transitioning: false });
}
onSupportStoreChange () {
var supportProps = SupportStore.get(this.state.candidate_we_vote_id);
if (supportProps !== undefined) {
this.setState({ supportProps: supportProps, transitioning: false });
}
}
togglePositionStatement () {
this.setState({ hide_position_statement: !this.state.hide_position_statement });
}
getCandidateLink () {
// If here, we assume the voter is on the Office page
return "/candidate/" + this.state.candidate_we_vote_id + "/bto/" + this.state.organization_we_vote_id;
}
getOfficeLink () {
return "/office/" + this.state.office_we_vote_id + "/btvg/" + this.state.organization_we_vote_id;
}
goToCandidateLink () {
// If here, we assume the voter is on the Office page
historyPush("/candidate/" + this.state.candidate_we_vote_id + "/bto/" + this.state.organization_we_vote_id);
}
goToOfficeLink () {
historyPush("/office/" + this.state.office_we_vote_id + "/btvg/" + this.state.organization_we_vote_id);
}
render () {
renderLog(__filename);
let {
ballot_item_display_name,
party,
we_vote_id,
twitter_description,
twitter_followers_count,
contest_office_name,
// twitter_handle,
} = this.props;
let candidate_we_vote_id = this.props.we_vote_id;
let candidate_photo_url;
if (this.props.showLargeImage) {
if (this.props.candidate_photo_url_large) {
candidate_photo_url = this.props.candidate_photo_url_large;
}
} else if (this.props.candidate_photo_url_medium) {
candidate_photo_url = this.props.candidate_photo_url_medium;
}
let candidate_photo_url_html;
if (candidate_photo_url) {
candidate_photo_url_html = <ImageHandler className="card-main__avatar"
sizeClassName="icon-office-child "
imageUrl={candidate_photo_url}
alt="candidate-photo"
kind_of_ballot_item="CANDIDATE" />;
} else {
candidate_photo_url_html = <i className="card-main__avatar icon-office-child icon-main icon-icon-person-placeholder-6-1" />;
}
// let positions_in_your_network = SupportStore.get(we_vote_id) && ( SupportStore.get(we_vote_id).oppose_count || SupportStore.get(we_vote_id).support_count);
let one_candidate = CandidateStore.getCandidate(candidate_we_vote_id);
let candidateSupportStore = SupportStore.get(candidate_we_vote_id);
let organizationsToFollowSupport = VoterGuideStore.getVoterGuidesToFollowForBallotItemIdSupports(candidate_we_vote_id);
let organizationsToFollowOppose = VoterGuideStore.getVoterGuidesToFollowForBallotItemIdOpposes(candidate_we_vote_id);
let positions_display_raccoon = <div>
<div className="u-flex u-flex-auto u-flex-row u-justify-between u-items-center u-min-50">
{/* Positions in Your Network and Possible Voter Guides to Follow */}
<ItemSupportOpposeRaccoon ballotItemWeVoteId={candidate_we_vote_id}
ballot_item_display_name={one_candidate.ballot_item_display_name}
goToCandidate={this.goToCandidateLink}
maximumOrganizationDisplay={8}
organizationsToFollowSupport={organizationsToFollowSupport}
organizationsToFollowOppose={organizationsToFollowOppose}
popoverBottom
showPositionStatementActionBar={this.props.showPositionStatementActionBar}
supportProps={candidateSupportStore}
type="CANDIDATE"/>
</div>
</div>;
return <div className="card-main candidate-card">
<div className="card-main__media-object">
<div className="card-main__media-object-anchor">
{this.props.link_to_ballot_item_page ?
<Link to={this.getCandidateLink} className="u-no-underline">{candidate_photo_url_html}</Link> :
candidate_photo_url_html
}
{twitter_followers_count ?
<span className={this.props.link_to_ballot_item_page ?
"twitter-followers__badge u-cursor--pointer" :
"twitter-followers__badge" }
onClick={ this.props.link_to_ballot_item_page ? this.goToCandidateLink : null }
>
<span className="fa fa-twitter twitter-followers__icon" />
<span title={numberWithCommas(twitter_followers_count)}>{abbreviateNumber(twitter_followers_count)}</span>
</span> :
null
}
</div>
<div className="card-main__media-object-content">
<h2 className="card-main__display-name">
{ this.props.link_to_ballot_item_page ?
<Link to={this.getCandidateLink}>{ballot_item_display_name}</Link> :
ballot_item_display_name
}
</h2>
<BookmarkToggle we_vote_id={we_vote_id} type="CANDIDATE"/>
<p className={this.props.link_to_ballot_item_page ?
"u-gray-darker u-cursor--pointer" :
"u-gray-darker"
} onClick={this.props.link_to_ballot_item_page ?
this.goToCandidateLink : null }
>
{ contest_office_name ?
<OfficeNameText
political_party={party}
contest_office_name={contest_office_name}
office_link={this.getOfficeLink()}
/> :
null
}
</p>
{ twitter_description ?
<div className={ "u-stack--sm" + (this.props.link_to_ballot_item_page ? " card-main__description-container--truncated" : " card-main__description-container")}>
<div>
<ParsedTwitterDescription
twitter_description={twitter_description}
/>
</div>
<Link to={this.getCandidateLink}>
{ this.props.link_to_ballot_item_page ? <span className="card-main__read-more-pseudo" /> : null }
</Link>
{ this.props.link_to_ballot_item_page ?
<Link to={this.getCandidateLink} className="card-main__read-more-link"> Read more</Link> :
null
}
</div> :
null
}
</div> {/* END .card-main__media-object-content */}
</div> {/* END .card-main__media-object */}
<div className="card-main__actions">
{positions_display_raccoon}
{/* this.state.hide_position_statement ?
null :
<ItemPositionStatementActionBar ballot_item_we_vote_id={we_vote_id}
ballot_item_display_name={ballot_item_display_name}
supportProps={supportProps}
transitioning={transitioning}
type="CANDIDATE" /> */}
</div>
</div>;
}
}