/
OrganizationPositionItem.jsx
268 lines (250 loc) · 12.9 KB
/
OrganizationPositionItem.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
256
257
258
259
260
261
262
263
264
265
266
267
268
import React, { Component } from "react";
import PropTypes from "prop-types";
import { Link } from "react-router";
import BookmarkToggle from "../Bookmarks/BookmarkToggle";
import ImageHandler from "../ImageHandler";
import ItemActionBar from "../Widgets/ItemActionBar";
import ItemPositionStatementActionBar from "../Widgets/ItemPositionStatementActionBar";
import FriendsOnlyIndicator from "../Widgets/FriendsOnlyIndicator";
import { renderLog } from "../../utils/logging";
import OfficeNameText from "../Widgets/OfficeNameText";
import OrganizationStore from "../../stores/OrganizationStore";
import PositionInformationOnlySnippet from "../Widgets/PositionInformationOnlySnippet";
import PositionRatingSnippet from "../Widgets/PositionRatingSnippet";
import PositionSupportOpposeSnippet from "../Widgets/PositionSupportOpposeSnippet";
import { capitalizeString } from "../../utils/textFormat";
import SupportStore from "../../stores/SupportStore";
import VoterStore from "../../stores/VoterStore";
import CandidateStore from "../../stores/CandidateStore";
export default class OrganizationPositionItem extends Component {
static propTypes = {
ballotItemLink: PropTypes.string,
comment_text_off: PropTypes.bool,
editMode: PropTypes.bool,
link_to_edit_modal_off: PropTypes.bool,
organization: PropTypes.object.isRequired,
placement: PropTypes.string,
position: PropTypes.object.isRequired,
popover_off: PropTypes.bool,
stance_display_off: PropTypes.bool,
turnOffLogo: PropTypes.bool,
turnOffName: PropTypes.bool,
};
constructor (props) {
super(props);
this.state = {
hide_position_statement: false,
supportProps: SupportStore.get(this.props.position.ballot_item_we_vote_id),
transitioning: false,
};
}
componentDidMount () {
this.organizationStoreListener = OrganizationStore.addListener(this._onOrganizationStoreChange.bind(this));
this.supportStoreListener = SupportStore.addListener(this.onSupportStoreChange.bind(this));
this._onVoterStoreChange();
this.voterStoreListener = VoterStore.addListener(this._onVoterStoreChange.bind(this));
this.setState({
organization: OrganizationStore.getOrganizationByWeVoteId(this.props.organization.organization_we_vote_id),
});
}
componentWillReceiveProps (nextProps) {
// console.log("OrganizationPositionItem componentWillReceiveProps");
this.setState({
organization: OrganizationStore.getOrganizationByWeVoteId(nextProps.organization.organization_we_vote_id),
});
}
componentWillUnmount () {
this.organizationStoreListener.remove();
this.supportStoreListener.remove();
this.voterStoreListener.remove();
}
_onOrganizationStoreChange (){
// console.log("OrganizationPositionItem _onOrganizationStoreChange, org_we_vote_id: ", this.state.organization.organization_we_vote_id);
this.setState({
organization: OrganizationStore.getOrganizationByWeVoteId(this.state.organization.organization_we_vote_id),
});
}
onSupportStoreChange () {
this.setState({
organization: OrganizationStore.getOrganizationByWeVoteId(this.state.organization.organization_we_vote_id),
supportProps: SupportStore.get(this.props.position.ballot_item_we_vote_id),
transitioning: false
});
}
_onVoterStoreChange () {
this.setState({ voter: VoterStore.getVoter() });
}
togglePositionStatement (){
this.setState({hide_position_statement: !this.state.hide_position_statement});
}
render () {
renderLog(__filename);
let position = this.props.position;
let organization = this.state.organization;
if (!position.ballot_item_we_vote_id) {
// console.log("OrganizationPositionItem cannot render yet -- missing position and organization");
return null;
}
let { stance_display_off, comment_text_off, popover_off, placement } = this.props;
const { supportProps } = this.state;
// Manage the control over this organization voter guide
let organization_twitter_handle_being_viewed = "";
let organization_facebook_id_being_viewed = 0;
let organization_we_vote_id = "";
let signed_in_with_this_organization = false;
if (organization !== undefined) {
organization_twitter_handle_being_viewed = organization.organization_twitter_handle !== undefined ? organization.organization_twitter_handle : "";
organization_facebook_id_being_viewed = organization.facebook_id !== undefined ? organization.facebook_id : 0;
organization_we_vote_id = organization.organization_we_vote_id;
signed_in_with_this_organization = this.state.voter && this.state.voter.linked_organization_we_vote_id === organization_we_vote_id;
}
// console.log("signed_in_with_this_organization: ", signed_in_with_this_organization);
var signed_in_twitter = this.state.voter === undefined ? false : this.state.voter.signed_in_twitter;
var signed_in_with_this_twitter_account = false;
if (signed_in_twitter && this.state.voter.twitter_screen_name !== null) {
signed_in_with_this_twitter_account = this.state.voter.twitter_screen_name.toLowerCase() === organization_twitter_handle_being_viewed.toLowerCase();
}
var signed_in_facebook = this.state.voter === undefined ? false : this.state.voter.signed_in_facebook;
var signed_in_with_this_facebook_account = false;
if (signed_in_facebook) {
signed_in_with_this_facebook_account = this.state.voter.facebook_id === organization_facebook_id_being_viewed;
}
var statement_text;
var is_public_position;
var is_support;
var is_oppose;
// If looking at your own page, update when supportProps change
if (signed_in_with_this_twitter_account || signed_in_with_this_organization) {
// console.log("OrganizationPositionItem signed_in_with_this_twitter_account");
// When component first loads, use the value in the incoming position. If there are any supportProps updates, use those.
statement_text = supportProps && supportProps.voter_statement_text ? supportProps.voter_statement_text : position.statement_text;
is_public_position = supportProps && supportProps.is_public_position ? supportProps.is_public_position : position.is_public_position;
is_support = supportProps && supportProps.is_support !== undefined ? supportProps.is_support : position.is_support;
is_oppose = supportProps && supportProps.is_oppose !== undefined ? supportProps.is_oppose : position.is_oppose;
} else {
// console.log("OrganizationPositionItem NOT signed_in_with_this_twitter_account");
statement_text = position.statement_text;
is_public_position = position.is_public_position;
is_support = position.is_support;
is_oppose = position.is_oppose;
}
let ballotItemLink;
if (this.props.ballotItemLink) {
ballotItemLink = this.props.ballotItemLink;
} else {
// TwitterHandle-based link
let ballot_item_url = position.kind_of_ballot_item === "MEASURE" ? "/measure/" : "/candidate/";
// We are turning off links to twitter pages until we get politician pages working
//let ballotItemLink = position.ballot_item_twitter_handle ? "/" + position.ballot_item_twitter_handle : ballot_item_url + position.ballot_item_we_vote_id;
ballotItemLink = ballot_item_url + position.ballot_item_we_vote_id;
}
let position_description = "";
let is_candidate = position.kind_of_ballot_item === "CANDIDATE";
let ballot_item_display_name = "";
if (position.ballot_item_display_name) {
ballot_item_display_name = capitalizeString(position.ballot_item_display_name);
}
const is_on_ballot_item_page = false;
if (position.vote_smart_rating) {
// console.log("PositionRatingSnippet");
position_description = <PositionRatingSnippet {...position}
popover_off={popover_off}
placement={placement} />;
} else if (is_support || is_oppose) {
// console.log("PositionSupportOpposeSnippet");
// We overwrite the "statement_text" passed in with position
position_description = <PositionSupportOpposeSnippet {...position}
statement_text={statement_text}
is_support={is_support}
is_oppose={is_oppose}
is_on_ballot_item_page={is_on_ballot_item_page}
stance_display_off={stance_display_off}
comment_text_off={comment_text_off} />;
} else {
// console.log("PositionInformationOnlySnippet");
position_description = <PositionInformationOnlySnippet {...position}
is_on_ballot_item_page={is_on_ballot_item_page}
stance_display_off={stance_display_off}
comment_text_off={comment_text_off} />;
}
// const onEditPositionClick = this.state.showEditPositionModal ? this.closeEditPositionModal.bind(this) : this.openEditPositionModal.bind(this);
let contest_office_name;
let political_party;
if (position.kind_of_ballot_item === "CANDIDATE") {
contest_office_name = position.contest_office_name;
political_party = position.ballot_item_political_party;
}
//CHICHI
let { office_we_vote_id } = CandidateStore.getCandidate(position.ballot_item_we_vote_id);
return <li className="position-item card-child">
{ is_candidate && !this.props.turnOffLogo ?
<div className="card-child__media-object-anchor">
<Link to={ ballotItemLink }
className="u-no-underline"
onlyActiveOnIndex={false}>
<ImageHandler
className="card-child__avatar--round"
sizeClassName="icon-lg "
imageUrl={position.ballot_item_image_url_https_large}
alt="candidate-photo"
kind_of_ballot_item={position.kind_of_ballot_item}/>
</Link>
</div> :
null
}
<div className="card-child__media-object-content">
<div className="card-child__content">
{!this.props.turnOffName ?
<div className="u-flex items-center">
<Link to={ ballotItemLink }
onlyActiveOnIndex={false}
className="position-rating__candidate-name u-flex-auto">
{ballot_item_display_name}
</Link>
{ (signed_in_with_this_twitter_account ||
signed_in_with_this_organization ||
signed_in_with_this_facebook_account) &&
this.props.editMode ?
<FriendsOnlyIndicator isFriendsOnly={!is_public_position}/> :
<FriendsOnlyIndicator isFriendsOnly={!is_public_position}/>
}
<BookmarkToggle we_vote_id={position.ballot_item_we_vote_id} type={position.kind_of_ballot_item} />
</div> :
null }
{ position.kind_of_ballot_item === "CANDIDATE" && contest_office_name !== undefined ?
<OfficeNameText
political_party={political_party}
contest_office_name={contest_office_name}
office_link={"/office/" + office_we_vote_id}
/> :
null
}
{/* show explicit position, if available, otherwise show rating */}
{ position_description }
{ this.props.editMode ?
<div>
<ItemActionBar ballot_item_we_vote_id={position.ballot_item_we_vote_id}
ballot_item_display_name={ballot_item_display_name}
commentButtonHide
shareButtonHide
supportProps={supportProps}
transitioning={this.state.transitioning}
type={position.kind_of_ballot_item}
toggleFunction={this.togglePositionStatement.bind(this)}
/>
{ this.state.hide_position_statement ?
null :
<ItemPositionStatementActionBar ballot_item_we_vote_id={position.ballot_item_we_vote_id}
ballot_item_display_name={position.ballot_item_display_name}
comment_edit_mode_on
stance_display_off
supportProps={supportProps}
transitioning={this.state.transitioning}
type={position.kind_of_ballot_item} /> }
</div> :
null }
</div>
</div>
</li>;
}
}