-
Notifications
You must be signed in to change notification settings - Fork 430
/
UserProfile.jsx
766 lines (727 loc) · 29.3 KB
/
UserProfile.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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
/* eslint react/prop-types: 0 */
import React from 'react';
import { Link } from 'react-router';
import { connect } from 'react-redux';
import { browserHistory } from 'react-router';
import classnames from 'classnames';
import * as transactionActions from 'app/redux/TransactionReducer';
import * as userActions from 'app/redux/UserReducer';
import { actions as fetchDataSagaActions } from 'app/redux/FetchDataSaga';
import Icon from 'app/components/elements/Icon';
import UserKeys from 'app/components/elements/UserKeys';
import PasswordReset from 'app/components/elements/PasswordReset';
import UserWallet from 'app/components/modules/UserWallet';
import Settings from 'app/components/modules/Settings';
import CurationRewards from 'app/components/modules/CurationRewards';
import AuthorRewards from 'app/components/modules/AuthorRewards';
import UserList from 'app/components/elements/UserList';
import Follow from 'app/components/elements/Follow';
import LoadingIndicator from 'app/components/elements/LoadingIndicator';
import PostsList from 'app/components/cards/PostsList';
import { isFetchingOrRecentlyUpdated } from 'app/utils/StateFunctions';
import { repLog10 } from 'app/utils/ParsersAndFormatters.js';
import Tooltip from 'app/components/elements/Tooltip';
import DateJoinWrapper from 'app/components/elements/DateJoinWrapper';
import tt from 'counterpart';
import WalletSubMenu from 'app/components/elements/WalletSubMenu';
import Userpic from 'app/components/elements/Userpic';
import Callout from 'app/components/elements/Callout';
import normalizeProfile from 'app/utils/NormalizeProfile';
import userIllegalContent from 'app/utils/userIllegalContent';
import proxifyImageUrl from 'app/utils/ProxifyUrl';
import ArticleLayoutSelector from 'app/components/modules/ArticleLayoutSelector';
import SanitizedLink from 'app/components/elements/SanitizedLink';
import DropdownMenu from 'app/components/elements/DropdownMenu';
export default class UserProfile extends React.Component {
constructor() {
super();
this.state = {};
this.onPrint = () => {
window.print();
};
this.loadMore = this.loadMore.bind(this);
}
shouldComponentUpdate(np) {
const { follow } = this.props;
const { follow_count } = this.props;
let followersLoading = false,
npFollowersLoading = false;
let followingLoading = false,
npFollowingLoading = false;
const account = np.routeParams.accountname.toLowerCase();
if (follow) {
followersLoading = follow.getIn(
['getFollowersAsync', account, 'blog_loading'],
false
);
followingLoading = follow.getIn(
['getFollowingAsync', account, 'blog_loading'],
false
);
}
if (np.follow) {
npFollowersLoading = np.follow.getIn(
['getFollowersAsync', account, 'blog_loading'],
false
);
npFollowingLoading = np.follow.getIn(
['getFollowingAsync', account, 'blog_loading'],
false
);
}
return (
np.current_user !== this.props.current_user ||
np.accounts.get(account) !== this.props.accounts.get(account) ||
np.wifShown !== this.props.wifShown ||
np.global_status !== this.props.global_status ||
(npFollowersLoading !== followersLoading && !npFollowersLoading) ||
(npFollowingLoading !== followingLoading && !npFollowingLoading) ||
np.loading !== this.props.loading ||
np.location.pathname !== this.props.location.pathname ||
np.routeParams.accountname !== this.props.routeParams.accountname ||
np.follow_count !== this.props.follow_count ||
np.blogmode !== this.props.blogmode
);
}
componentWillUnmount() {
this.props.clearTransferDefaults();
this.props.clearPowerdownDefaults();
}
loadMore(last_post, category) {
const { accountname } = this.props.routeParams;
if (!last_post) return;
let order;
switch (category) {
case 'feed':
order = 'by_feed';
break;
case 'blog':
order = 'by_author';
break;
case 'comments':
order = 'by_comments';
break;
case 'recent_replies':
order = 'by_replies';
break;
default:
console.log('unhandled category:', category);
}
if (
isFetchingOrRecentlyUpdated(
this.props.global_status,
order,
category
)
)
return;
const [author, permlink] = last_post.split('/');
this.props.requestData({
author,
permlink,
order,
category,
accountname,
});
}
render() {
const {
props: { current_user, wifShown, global_status, follow },
onPrint,
} = this;
let { accountname, section } = this.props.routeParams;
// normalize account from cased params
accountname = accountname.toLowerCase();
const username = current_user ? current_user.get('username') : null;
// const gprops = this.props.global.getIn( ['props'] ).toJS();
if (!section) section = 'blog';
// @user/"posts" is deprecated in favor of "comments" as of oct-2016 (#443)
if (section == 'posts') section = 'comments';
// const isMyAccount = current_user ? current_user.get('username') === accountname : false;
// Loading status
const status = global_status
? global_status.getIn([section, 'by_author'])
: null;
const fetching = (status && status.fetching) || this.props.loading;
let account;
let accountImm = this.props.accounts.get(accountname);
if (accountImm) {
account = accountImm.toJS();
} else if (fetching) {
return (
<center>
<LoadingIndicator type="circle" />
</center>
);
} else {
return (
<div>
<center>{tt('user_profile.unknown_account')}</center>
</div>
);
}
const followers =
follow && follow.getIn(['getFollowersAsync', accountname]);
const following =
follow && follow.getIn(['getFollowingAsync', accountname]);
// instantiate following items
let totalCounts = this.props.follow_count;
let followerCount = 0;
let followingCount = 0;
if (totalCounts && accountname) {
totalCounts = totalCounts.get(accountname);
if (totalCounts) {
totalCounts = totalCounts.toJS();
followerCount = totalCounts.follower_count;
followingCount = totalCounts.following_count;
}
}
const rep = repLog10(account.reputation);
const isMyAccount = username === account.name;
let tab_content = null;
// const global_status = this.props.global.get('status');
// let balance_steem = parseFloat(account.balance.split(' ')[0]);
// let vesting_steem = vestingSteem(account, gprops).toFixed(2);
// const steem_balance_str = numberWithCommas(balance_steem.toFixed(2)) + " STEEM";
// const power_balance_str = numberWithCommas(vesting_steem) + " STEEM POWER";
// const sbd_balance = parseFloat(account.sbd_balance)
// const sbd_balance_str = numberWithCommas('$' + sbd_balance.toFixed(2));
let rewardsClass = '',
walletClass = '';
if (section === 'transfers') {
walletClass = 'active';
tab_content = (
<div>
<UserWallet
account={accountImm}
showTransfer={this.props.showTransfer}
showPowerdown={this.props.showPowerdown}
current_user={current_user}
withdrawVesting={this.props.withdrawVesting}
/>
</div>
);
} else if (section === 'curation-rewards') {
rewardsClass = 'active';
tab_content = (
<CurationRewards
account={account}
current_user={current_user}
/>
);
} else if (section === 'author-rewards') {
rewardsClass = 'active';
tab_content = (
<AuthorRewards account={account} current_user={current_user} />
);
} else if (section === 'followers') {
if (followers && followers.has('blog_result')) {
tab_content = (
<div>
<UserList
title={tt('user_profile.followers')}
account={account}
users={followers.get('blog_result')}
/>
</div>
);
}
} else if (section === 'followed') {
if (following && following.has('blog_result')) {
tab_content = (
<UserList
title="Followed"
account={account}
users={following.get('blog_result')}
/>
);
}
} else if (section === 'settings') {
tab_content = <Settings routeParams={this.props.routeParams} />;
} else if (section === 'comments' && account.post_history) {
if (account.comments) {
let posts =
accountImm.get('posts') || accountImm.get('comments');
if (!fetching && (posts && !posts.size)) {
tab_content = (
<Callout>
{tt('user_profile.user_hasnt_made_any_posts_yet', {
name: accountname,
})}
</Callout>
);
} else {
tab_content = (
<PostsList
posts={posts}
loading={fetching}
category="comments"
loadMore={this.loadMore}
showSpam
/>
);
}
} else {
tab_content = (
<center>
<LoadingIndicator type="circle" />
</center>
);
}
} else if (!section || section === 'blog') {
if (account.blog) {
let posts = accountImm.get('blog');
const emptyText = isMyAccount ? (
<div>
{tt(
'user_profile.looks_like_you_havent_posted_anything_yet'
)}
<br />
<br />
<Link to="/submit.html">
{tt('user_profile.create_a_post')}
</Link>
<br />
<Link to="/trending">
{tt('user_profile.explore_trending_articles')}
</Link>
<br />
<Link to="/welcome">
{tt('user_profile.read_the_quick_start_guide')}
</Link>
<br />
<Link to="/faq.html">
{tt('user_profile.browse_the_faq')}
</Link>
<br />
</div>
) : (
tt('user_profile.user_hasnt_started_bloggin_yet', {
name: accountname,
})
);
if (!fetching && (posts && !posts.size)) {
tab_content = <Callout>{emptyText}</Callout>;
} else {
tab_content = (
<PostsList
account={account.name}
posts={posts}
loading={fetching}
category="blog"
loadMore={this.loadMore}
showSpam
/>
);
}
} else {
tab_content = (
<center>
<LoadingIndicator type="circle" />
</center>
);
}
} else if (section === 'recent-replies') {
if (account.recent_replies) {
let posts = accountImm.get('recent_replies');
if (!fetching && (posts && !posts.size)) {
tab_content = (
<Callout>
{tt('user_profile.user_hasnt_had_any_replies_yet', {
name: accountname,
}) + '.'}
</Callout>
);
} else {
tab_content = (
<div>
<PostsList
posts={posts}
loading={fetching}
category="recent_replies"
loadMore={this.loadMore}
showSpam={false}
/>
</div>
);
}
} else {
tab_content = (
<center>
<LoadingIndicator type="circle" />
</center>
);
}
} else if (section === 'permissions' && isMyAccount) {
walletClass = 'active';
tab_content = (
<div>
<div className="row">
<div className="column">
<WalletSubMenu account_name={account.name} />
</div>
</div>
<br />
<UserKeys account={accountImm} />
</div>
);
} else if (section === 'password') {
walletClass = 'active';
tab_content = (
<div>
<div className="row">
<div className="column">
<WalletSubMenu account_name={account.name} />
</div>
</div>
<br />
<PasswordReset account={accountImm} />
</div>
);
} else {
// console.log( "no matches" );
}
// detect illegal users
if (userIllegalContent.includes(accountname)) {
tab_content = <div>Unavailable For Legal Reasons.</div>;
}
var page_title = '';
// Page title
if (isMyAccount) {
if (section === 'blog') {
page_title = tt('g.my_blog');
} else if (section === 'comments') {
page_title = tt('g.my_comments');
} else if (section === 'recent-replies') {
page_title = tt('g.my_replies');
} else if (section === 'settings') {
page_title = tt('g.settings');
} else if (section === 'curation-rewards') {
page_title = tt('g.curation_rewards');
} else if (section === 'author-rewards') {
page_title = tt('g.author_rewards');
}
} else {
if (section === 'blog') {
page_title = tt('g.blog');
} else if (section === 'comments') {
page_title = tt('g.comments');
} else if (section === 'recent-replies') {
page_title = tt('g.replies');
} else if (section === 'settings') {
page_title = tt('g.settings');
} else if (section === 'curation-rewards') {
page_title = tt('g.curation_rewards');
} else if (section === 'author-rewards') {
page_title = tt('g.author_rewards');
}
}
const layoutClass = this.props.blogmode
? 'layout-block'
: 'layout-list';
const blog_header = (
<div>
<div className="articles__header">
<div className="articles__header-col">
<h1 className="articles__h1">{page_title}</h1>
</div>
<div className="articles__header-col articles__header-col--right">
<ArticleLayoutSelector />
</div>
</div>
<hr className="articles__hr" />
</div>
);
if (
!(
section === 'transfers' ||
section === 'permissions' ||
section === 'password'
)
) {
tab_content = (
<div className="row">
<div
className={classnames(
'UserProfile__tab_content',
'column',
layoutClass,
section
)}
>
<article className="articles">
{section === 'blog' || 'comments'
? blog_header
: null}
{tab_content}
</article>
</div>
</div>
);
}
let printLink = null;
if (section === 'permissions') {
if (isMyAccount && wifShown) {
printLink = (
<div>
<a className="float-right noPrint" onClick={onPrint}>
<Icon name="printer" /> {tt('g.print')}
</a>
</div>
);
}
}
// const wallet_tab_active = section === 'transfers' || section === 'password' || section === 'permissions' ? 'active' : ''; // className={wallet_tab_active}
let rewardsMenu = [
{
link: `/@${accountname}/curation-rewards`,
label: tt('g.curation_rewards'),
value: tt('g.curation_rewards'),
},
{
link: `/@${accountname}/author-rewards`,
label: tt('g.author_rewards'),
value: tt('g.author_rewards'),
},
];
// set account join date
let accountjoin = account.created;
const top_menu = (
<div className="row UserProfile__top-menu">
<div className="columns small-10 medium-12 medium-expand">
<ul className="menu" style={{ flexWrap: 'wrap' }}>
<li>
<Link
to={`/@${accountname}`}
activeClassName="active"
>
{tt('g.blog')}
</Link>
</li>
<li>
<Link
to={`/@${accountname}/comments`}
activeClassName="active"
>
{tt('g.comments')}
</Link>
</li>
<li>
<Link
to={`/@${accountname}/recent-replies`}
activeClassName="active"
>
{tt('g.replies')}
</Link>
</li>
{/*<li><Link to={`/@${accountname}/feed`} activeClassName="active">Feed</Link></li>*/}
<DropdownMenu
className={rewardsClass}
items={rewardsMenu}
el="li"
selected={tt('g.rewards')}
position="right"
/>
</ul>
</div>
<div className="columns shrink">
<ul className="menu" style={{ flexWrap: 'wrap' }}>
<li>
<a
href={`/@${accountname}/transfers`}
className={walletClass}
onClick={e => {
e.preventDefault();
browserHistory.push(e.target.pathname);
return false;
}}
>
{tt('g.wallet')}
</a>
</li>
{isMyAccount && (
<li>
<Link
to={`/@${accountname}/settings`}
activeClassName="active"
>
{tt('g.settings')}
</Link>
</li>
)}
</ul>
</div>
</div>
);
const {
name,
location,
about,
website,
cover_image,
} = normalizeProfile(account);
const website_label = website
? website.replace(/^https?:\/\/(www\.)?/, '').replace(/\/$/, '')
: null;
let cover_image_style = {};
if (cover_image) {
cover_image_style = {
backgroundImage:
'url(' + proxifyImageUrl(cover_image, '2048x512') + ')',
};
}
return (
<div className="UserProfile">
<div className="UserProfile__banner row expanded">
<div className="column" style={cover_image_style}>
<div style={{ position: 'relative' }}>
<div className="UserProfile__buttons hide-for-small-only">
<Follow
follower={username}
following={accountname}
/>
</div>
</div>
<h1>
<Userpic account={account.name} hideIfDefault />
{name || account.name}{' '}
<Tooltip
t={tt(
'user_profile.this_is_users_reputations_score_it_is_based_on_history_of_votes',
{ name: accountname }
)}
>
<span className="UserProfile__rep">
({rep})
</span>
</Tooltip>
</h1>
<div>
{about && (
<p className="UserProfile__bio">{about}</p>
)}
<div className="UserProfile__stats">
<span>
<Link to={`/@${accountname}/followers`}>
{tt('user_profile.follower_count', {
count: followerCount,
})}
</Link>
</span>
<span>
<Link to={`/@${accountname}`}>
{tt('user_profile.post_count', {
count: account.post_count || 0,
})}
</Link>
</span>
<span>
<Link to={`/@${accountname}/followed`}>
{tt('user_profile.followed_count', {
count: followingCount,
})}
</Link>
</span>
</div>
<p className="UserProfile__info">
{location && (
<span>
<Icon name="location" /> {location}
</span>
)}
{website && (
<span>
<Icon name="link" />{' '}
<SanitizedLink
url={website}
text={website_label}
/>
</span>
)}
<Icon name="calendar" />{' '}
<DateJoinWrapper date={accountjoin} />
</p>
</div>
<div className="UserProfile__buttons_mobile show-for-small-only">
<Follow
follower={username}
following={accountname}
what="blog"
/>
</div>
</div>
</div>
<div className="UserProfile__top-nav row expanded noPrint">
{top_menu}
</div>
<div>{printLink}</div>
<div>{tab_content}</div>
</div>
);
}
}
module.exports = {
path: '@:accountname(/:section)',
component: connect(
state => {
const wifShown = state.global.get('UserKeys_wifShown');
const current_user = state.user.get('current');
// const current_account = current_user && state.global.getIn(['accounts', current_user.get('username')])
return {
discussions: state.global.get('discussion_idx'),
current_user,
// current_account,
wifShown,
loading: state.app.get('loading'),
global_status: state.global.get('status'),
accounts: state.global.get('accounts'),
follow: state.global.get('follow'),
follow_count: state.global.get('follow_count'),
blogmode: state.app.getIn(['user_preferences', 'blogmode']),
};
},
dispatch => ({
login: () => {
dispatch(userActions.showLogin());
},
clearTransferDefaults: () => {
dispatch(userActions.clearTransferDefaults());
},
showTransfer: transferDefaults => {
dispatch(userActions.setTransferDefaults(transferDefaults));
dispatch(userActions.showTransfer());
},
clearPowerdownDefaults: () => {
dispatch(userActions.clearPowerdownDefaults());
},
showPowerdown: powerdownDefaults => {
console.log('power down defaults:', powerdownDefaults);
dispatch(userActions.setPowerdownDefaults(powerdownDefaults));
dispatch(userActions.showPowerdown());
},
withdrawVesting: ({
account,
vesting_shares,
errorCallback,
successCallback,
}) => {
const successCallbackWrapper = (...args) => {
dispatch(
globalActions.getState({ url: `@${account}/transfers` })
);
return successCallback(...args);
};
dispatch(
transactionActions.broadcastOperation({
type: 'withdraw_vesting',
operation: { account, vesting_shares },
errorCallback,
successCallback: successCallbackWrapper,
})
);
},
requestData: args =>
dispatch(fetchDataSagaActions.requestData(args)),
})
)(UserProfile),
};