2019-04-08 05:19:02 +00:00
|
|
|
import { Component, linkEvent } from 'inferno';
|
|
|
|
import { Link } from 'inferno-router';
|
2019-10-19 00:20:27 +00:00
|
|
|
import { Subscription } from 'rxjs';
|
2019-04-08 05:19:02 +00:00
|
|
|
import { retryWhen, delay, take } from 'rxjs/operators';
|
2019-10-19 00:20:27 +00:00
|
|
|
import {
|
|
|
|
UserOperation,
|
|
|
|
CommunityUser,
|
|
|
|
SortType,
|
2019-10-21 04:21:54 +00:00
|
|
|
ListingType,
|
2019-10-19 00:20:27 +00:00
|
|
|
UserView,
|
|
|
|
UserSettingsForm,
|
|
|
|
LoginResponse,
|
|
|
|
DeleteAccountForm,
|
2020-01-19 05:38:45 +00:00
|
|
|
WebSocketJsonResponse,
|
2020-07-08 05:02:14 +00:00
|
|
|
GetSiteResponse,
|
2020-07-12 08:00:10 +00:00
|
|
|
UserDetailsView,
|
|
|
|
UserDetailsResponse,
|
2020-07-20 19:32:15 +00:00
|
|
|
AddAdminResponse,
|
2019-10-19 00:20:27 +00:00
|
|
|
} from '../interfaces';
|
2019-08-14 02:52:43 +00:00
|
|
|
import { WebSocketService, UserService } from '../services';
|
2019-10-19 00:20:27 +00:00
|
|
|
import {
|
2020-01-19 04:54:10 +00:00
|
|
|
wsJsonToRes,
|
2019-10-19 00:20:27 +00:00
|
|
|
fetchLimit,
|
|
|
|
routeSortTypeToEnum,
|
|
|
|
capitalizeFirstLetter,
|
|
|
|
themes,
|
|
|
|
setTheme,
|
2019-12-09 08:24:53 +00:00
|
|
|
languages,
|
2020-01-02 21:55:54 +00:00
|
|
|
showAvatars,
|
2020-01-23 03:29:11 +00:00
|
|
|
toast,
|
2020-03-08 18:29:17 +00:00
|
|
|
setupTippy,
|
2019-10-19 00:20:27 +00:00
|
|
|
} from '../utils';
|
2020-04-14 23:18:13 +00:00
|
|
|
import { UserListing } from './user-listing';
|
2019-10-21 00:49:13 +00:00
|
|
|
import { SortSelect } from './sort-select';
|
2019-10-21 04:21:54 +00:00
|
|
|
import { ListingTypeSelect } from './listing-type-select';
|
2019-04-08 05:19:02 +00:00
|
|
|
import { MomentTime } from './moment-time';
|
2019-08-10 00:14:43 +00:00
|
|
|
import { i18n } from '../i18next';
|
2020-07-08 00:28:47 +00:00
|
|
|
import moment from 'moment';
|
2020-07-12 08:00:10 +00:00
|
|
|
import { UserDetails } from './user-details';
|
2019-04-08 05:19:02 +00:00
|
|
|
|
|
|
|
interface UserState {
|
|
|
|
user: UserView;
|
2019-04-17 18:30:13 +00:00
|
|
|
user_id: number;
|
2019-04-25 21:52:18 +00:00
|
|
|
username: string;
|
2019-04-08 05:19:02 +00:00
|
|
|
follows: Array<CommunityUser>;
|
|
|
|
moderates: Array<CommunityUser>;
|
2020-07-12 08:00:10 +00:00
|
|
|
view: UserDetailsView;
|
2019-04-08 05:19:02 +00:00
|
|
|
sort: SortType;
|
2019-04-17 18:30:13 +00:00
|
|
|
page: number;
|
2019-04-29 00:41:24 +00:00
|
|
|
loading: boolean;
|
2019-12-29 20:39:48 +00:00
|
|
|
avatarLoading: boolean;
|
2019-08-14 02:52:43 +00:00
|
|
|
userSettingsForm: UserSettingsForm;
|
|
|
|
userSettingsLoading: boolean;
|
2019-10-15 22:09:01 +00:00
|
|
|
deleteAccountLoading: boolean;
|
|
|
|
deleteAccountShowConfirm: boolean;
|
2019-10-18 04:25:23 +00:00
|
|
|
deleteAccountForm: DeleteAccountForm;
|
2020-07-20 19:32:15 +00:00
|
|
|
siteRes: GetSiteResponse;
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 05:13:43 +00:00
|
|
|
interface UserProps {
|
|
|
|
view: UserDetailsView;
|
|
|
|
sort: SortType;
|
|
|
|
page: number;
|
|
|
|
user_id: number | null;
|
|
|
|
username: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface UrlParams {
|
|
|
|
view?: string;
|
|
|
|
sort?: string;
|
|
|
|
page?: number;
|
|
|
|
}
|
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
export class User extends Component<any, UserState> {
|
|
|
|
private subscription: Subscription;
|
|
|
|
private emptyState: UserState = {
|
|
|
|
user: {
|
|
|
|
id: null,
|
|
|
|
name: null,
|
|
|
|
published: null,
|
|
|
|
number_of_posts: null,
|
|
|
|
post_score: null,
|
|
|
|
number_of_comments: null,
|
|
|
|
comment_score: null,
|
2019-09-06 00:18:48 +00:00
|
|
|
banned: null,
|
2019-12-29 20:39:48 +00:00
|
|
|
avatar: null,
|
2020-01-02 21:55:54 +00:00
|
|
|
show_avatars: null,
|
|
|
|
send_notifications_to_email: null,
|
2020-04-14 23:18:13 +00:00
|
|
|
actor_id: null,
|
|
|
|
local: null,
|
2019-04-08 05:19:02 +00:00
|
|
|
},
|
2019-04-17 18:30:13 +00:00
|
|
|
user_id: null,
|
2019-04-25 21:52:18 +00:00
|
|
|
username: null,
|
2019-04-08 05:19:02 +00:00
|
|
|
follows: [],
|
|
|
|
moderates: [],
|
2020-07-17 15:48:06 +00:00
|
|
|
loading: true,
|
2019-12-29 20:39:48 +00:00
|
|
|
avatarLoading: false,
|
2020-07-12 08:00:10 +00:00
|
|
|
view: User.getViewFromProps(this.props.match.view),
|
|
|
|
sort: User.getSortTypeFromProps(this.props.match.sort),
|
|
|
|
page: User.getPageFromProps(this.props.match.page),
|
2019-08-14 02:52:43 +00:00
|
|
|
userSettingsForm: {
|
|
|
|
show_nsfw: null,
|
2019-10-15 19:21:27 +00:00
|
|
|
theme: null,
|
2019-10-21 04:21:54 +00:00
|
|
|
default_sort_type: null,
|
|
|
|
default_listing_type: null,
|
2019-12-09 08:24:53 +00:00
|
|
|
lang: null,
|
2020-01-02 21:55:54 +00:00
|
|
|
show_avatars: null,
|
|
|
|
send_notifications_to_email: null,
|
2019-08-14 02:52:43 +00:00
|
|
|
auth: null,
|
|
|
|
},
|
|
|
|
userSettingsLoading: null,
|
2019-10-15 22:09:01 +00:00
|
|
|
deleteAccountLoading: null,
|
|
|
|
deleteAccountShowConfirm: false,
|
2019-10-18 04:25:23 +00:00
|
|
|
deleteAccountForm: {
|
|
|
|
password: null,
|
2019-10-19 00:20:27 +00:00
|
|
|
},
|
2020-07-20 19:32:15 +00:00
|
|
|
siteRes: {
|
|
|
|
admins: [],
|
|
|
|
banned: [],
|
|
|
|
online: undefined,
|
|
|
|
site: {
|
|
|
|
id: undefined,
|
|
|
|
name: undefined,
|
|
|
|
creator_id: undefined,
|
|
|
|
published: undefined,
|
|
|
|
creator_name: undefined,
|
|
|
|
number_of_users: undefined,
|
|
|
|
number_of_posts: undefined,
|
|
|
|
number_of_comments: undefined,
|
|
|
|
number_of_communities: undefined,
|
|
|
|
enable_downvotes: undefined,
|
|
|
|
open_registration: undefined,
|
|
|
|
enable_nsfw: undefined,
|
|
|
|
},
|
2020-07-08 05:02:14 +00:00
|
|
|
},
|
2019-10-19 00:20:27 +00:00
|
|
|
};
|
2019-04-08 05:19:02 +00:00
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
2020-07-14 05:13:43 +00:00
|
|
|
this.state = this.emptyState;
|
2019-10-21 00:49:13 +00:00
|
|
|
this.handleSortChange = this.handleSortChange.bind(this);
|
2019-10-21 04:21:54 +00:00
|
|
|
this.handleUserSettingsSortTypeChange = this.handleUserSettingsSortTypeChange.bind(
|
|
|
|
this
|
|
|
|
);
|
|
|
|
this.handleUserSettingsListingTypeChange = this.handleUserSettingsListingTypeChange.bind(
|
|
|
|
this
|
|
|
|
);
|
2020-07-14 05:13:43 +00:00
|
|
|
this.handlePageChange = this.handlePageChange.bind(this);
|
2019-04-08 05:19:02 +00:00
|
|
|
|
2020-07-12 08:00:10 +00:00
|
|
|
this.state.user_id = Number(this.props.match.params.id) || null;
|
2019-04-25 21:52:18 +00:00
|
|
|
this.state.username = this.props.match.params.username;
|
2019-04-08 05:19:02 +00:00
|
|
|
|
|
|
|
this.subscription = WebSocketService.Instance.subject
|
2020-01-14 21:58:14 +00:00
|
|
|
.pipe(retryWhen(errors => errors.pipe(delay(3000), take(10))))
|
2019-10-19 00:20:27 +00:00
|
|
|
.subscribe(
|
|
|
|
msg => this.parseMessage(msg),
|
|
|
|
err => console.error(err),
|
2019-04-08 05:19:02 +00:00
|
|
|
() => console.log('complete')
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-08 05:19:02 +00:00
|
|
|
|
2020-07-08 05:02:14 +00:00
|
|
|
WebSocketService.Instance.getSite();
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 02:52:43 +00:00
|
|
|
get isCurrentUser() {
|
2019-10-19 00:20:27 +00:00
|
|
|
return (
|
|
|
|
UserService.Instance.user &&
|
|
|
|
UserService.Instance.user.id == this.state.user.id
|
|
|
|
);
|
2019-08-14 02:52:43 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 08:00:10 +00:00
|
|
|
static getViewFromProps(view: any): UserDetailsView {
|
|
|
|
return view
|
|
|
|
? UserDetailsView[capitalizeFirstLetter(view)]
|
|
|
|
: UserDetailsView.Overview;
|
2019-04-29 00:41:24 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 08:00:10 +00:00
|
|
|
static getSortTypeFromProps(sort: any): SortType {
|
|
|
|
return sort ? routeSortTypeToEnum(sort) : SortType.New;
|
2019-04-29 00:41:24 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 08:00:10 +00:00
|
|
|
static getPageFromProps(page: any): number {
|
|
|
|
return page ? Number(page) : 1;
|
2019-04-29 00:41:24 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
componentWillUnmount() {
|
|
|
|
this.subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
|
2020-07-14 05:13:43 +00:00
|
|
|
static getDerivedStateFromProps(props: any): UserProps {
|
2020-07-12 08:00:10 +00:00
|
|
|
return {
|
|
|
|
view: this.getViewFromProps(props.match.params.view),
|
|
|
|
sort: this.getSortTypeFromProps(props.match.params.sort),
|
|
|
|
page: this.getPageFromProps(props.match.params.page),
|
|
|
|
user_id: Number(props.match.params.id) || null,
|
|
|
|
username: props.match.params.username,
|
|
|
|
};
|
2019-04-29 00:41:24 +00:00
|
|
|
}
|
|
|
|
|
2019-11-23 00:32:18 +00:00
|
|
|
componentDidUpdate(lastProps: any, _lastState: UserState, _snapshot: any) {
|
|
|
|
// Necessary if you are on a post and you click another post (same route)
|
2019-12-08 20:23:11 +00:00
|
|
|
if (
|
|
|
|
lastProps.location.pathname.split('/')[2] !==
|
|
|
|
lastProps.history.location.pathname.split('/')[2]
|
|
|
|
) {
|
2019-11-23 00:32:18 +00:00
|
|
|
// Couldnt get a refresh working. This does for now.
|
|
|
|
location.reload();
|
|
|
|
}
|
2020-07-20 19:32:15 +00:00
|
|
|
document.title = `/u/${this.state.username} - ${this.state.siteRes.site.name}`;
|
2020-07-12 08:00:10 +00:00
|
|
|
setupTippy();
|
2019-11-23 00:32:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div class="container">
|
2020-07-17 15:48:06 +00:00
|
|
|
<div class="row">
|
|
|
|
<div class="col-12 col-md-8">
|
|
|
|
<h5>
|
|
|
|
{this.state.user.avatar && showAvatars() && (
|
|
|
|
<img
|
|
|
|
height="80"
|
|
|
|
width="80"
|
|
|
|
src={this.state.user.avatar}
|
|
|
|
class="rounded-circle mr-2"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<span>/u/{this.state.username}</span>
|
|
|
|
</h5>
|
|
|
|
{this.state.loading ? (
|
2019-12-29 20:39:48 +00:00
|
|
|
<h5>
|
2020-07-17 15:48:06 +00:00
|
|
|
<svg class="icon icon-spinner spin">
|
|
|
|
<use xlinkHref="#icon-spinner"></use>
|
|
|
|
</svg>
|
2019-12-29 20:39:48 +00:00
|
|
|
</h5>
|
2020-07-17 15:48:06 +00:00
|
|
|
) : (
|
|
|
|
this.selects()
|
|
|
|
)}
|
|
|
|
<UserDetails
|
|
|
|
user_id={this.state.user_id}
|
|
|
|
username={this.state.username}
|
|
|
|
sort={SortType[this.state.sort]}
|
|
|
|
page={this.state.page}
|
|
|
|
limit={fetchLimit}
|
2020-07-20 19:32:15 +00:00
|
|
|
enableDownvotes={this.state.siteRes.site.enable_downvotes}
|
|
|
|
enableNsfw={this.state.siteRes.site.enable_nsfw}
|
|
|
|
admins={this.state.siteRes.admins}
|
2020-07-17 15:48:06 +00:00
|
|
|
view={this.state.view}
|
|
|
|
onPageChange={this.handlePageChange}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{!this.state.loading && (
|
2019-10-19 00:20:27 +00:00
|
|
|
<div class="col-12 col-md-4">
|
|
|
|
{this.userInfo()}
|
|
|
|
{this.isCurrentUser && this.userSettings()}
|
|
|
|
{this.moderates()}
|
|
|
|
{this.follows()}
|
|
|
|
</div>
|
2020-07-17 15:48:06 +00:00
|
|
|
)}
|
|
|
|
</div>
|
2019-04-08 05:19:02 +00:00
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
|
2020-03-20 22:35:33 +00:00
|
|
|
viewRadios() {
|
2019-04-08 05:19:02 +00:00
|
|
|
return (
|
2020-03-20 22:35:33 +00:00
|
|
|
<div class="btn-group btn-group-toggle">
|
|
|
|
<label
|
2020-03-20 22:52:45 +00:00
|
|
|
className={`btn btn-sm btn-secondary pointer btn-outline-light
|
2020-07-12 08:00:10 +00:00
|
|
|
${this.state.view == UserDetailsView.Overview && 'active'}
|
2020-03-20 22:35:33 +00:00
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
2020-07-12 08:00:10 +00:00
|
|
|
value={UserDetailsView.Overview}
|
|
|
|
checked={this.state.view === UserDetailsView.Overview}
|
2020-03-20 22:35:33 +00:00
|
|
|
onChange={linkEvent(this, this.handleViewChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t('overview')}
|
|
|
|
</label>
|
|
|
|
<label
|
2020-03-20 22:52:45 +00:00
|
|
|
className={`btn btn-sm btn-secondary pointer btn-outline-light
|
2020-07-12 08:00:10 +00:00
|
|
|
${this.state.view == UserDetailsView.Comments && 'active'}
|
2020-03-20 22:35:33 +00:00
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
2020-07-12 08:00:10 +00:00
|
|
|
value={UserDetailsView.Comments}
|
|
|
|
checked={this.state.view == UserDetailsView.Comments}
|
2020-03-20 22:35:33 +00:00
|
|
|
onChange={linkEvent(this, this.handleViewChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t('comments')}
|
|
|
|
</label>
|
|
|
|
<label
|
2020-03-20 22:52:45 +00:00
|
|
|
className={`btn btn-sm btn-secondary pointer btn-outline-light
|
2020-07-12 08:00:10 +00:00
|
|
|
${this.state.view == UserDetailsView.Posts && 'active'}
|
2020-03-20 22:35:33 +00:00
|
|
|
`}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="radio"
|
2020-07-12 08:00:10 +00:00
|
|
|
value={UserDetailsView.Posts}
|
|
|
|
checked={this.state.view == UserDetailsView.Posts}
|
2020-03-20 22:35:33 +00:00
|
|
|
onChange={linkEvent(this, this.handleViewChange)}
|
|
|
|
/>
|
|
|
|
{i18n.t('posts')}
|
|
|
|
</label>
|
|
|
|
<label
|
2020-03-20 22:52:45 +00:00
|
|
|
className={`btn btn-sm btn-secondary pointer btn-outline-light
|
2020-07-12 08:00:10 +00:00
|
|
|
${this.state.view == UserDetailsView.Saved && 'active'}
|
2020-03-20 22:35:33 +00:00
|
|
|
`}
|
2019-10-19 00:20:27 +00:00
|
|
|
>
|
2020-03-20 22:35:33 +00:00
|
|
|
<input
|
|
|
|
type="radio"
|
2020-07-12 08:00:10 +00:00
|
|
|
value={UserDetailsView.Saved}
|
|
|
|
checked={this.state.view == UserDetailsView.Saved}
|
2020-03-20 22:35:33 +00:00
|
|
|
onChange={linkEvent(this, this.handleViewChange)}
|
2019-10-21 00:49:13 +00:00
|
|
|
/>
|
2020-03-20 22:35:33 +00:00
|
|
|
{i18n.t('saved')}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
selects() {
|
|
|
|
return (
|
|
|
|
<div className="mb-2">
|
|
|
|
<span class="mr-3">{this.viewRadios()}</span>
|
|
|
|
<SortSelect
|
|
|
|
sort={this.state.sort}
|
|
|
|
onChange={this.handleSortChange}
|
|
|
|
hideHot
|
|
|
|
/>
|
2019-12-02 01:21:19 +00:00
|
|
|
<a
|
2019-12-02 06:20:01 +00:00
|
|
|
href={`/feeds/u/${this.state.username}.xml?sort=${
|
|
|
|
SortType[this.state.sort]
|
|
|
|
}`}
|
|
|
|
target="_blank"
|
2020-06-30 13:40:57 +00:00
|
|
|
rel="noopener"
|
2020-03-03 07:29:45 +00:00
|
|
|
title="RSS"
|
2019-12-02 01:21:19 +00:00
|
|
|
>
|
|
|
|
<svg class="icon mx-2 text-muted small">
|
|
|
|
<use xlinkHref="#icon-rss">#</use>
|
|
|
|
</svg>
|
|
|
|
</a>
|
2019-04-08 05:19:02 +00:00
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
userInfo() {
|
|
|
|
let user = this.state.user;
|
|
|
|
return (
|
|
|
|
<div>
|
2019-08-20 02:37:32 +00:00
|
|
|
<div class="card border-secondary mb-3">
|
|
|
|
<div class="card-body">
|
2019-09-06 00:18:48 +00:00
|
|
|
<h5>
|
|
|
|
<ul class="list-inline mb-0">
|
2020-04-14 23:18:13 +00:00
|
|
|
<li className="list-inline-item">
|
2020-04-30 15:45:12 +00:00
|
|
|
<UserListing user={user} realLink />
|
2020-04-14 23:18:13 +00:00
|
|
|
</li>
|
2019-10-19 00:20:27 +00:00
|
|
|
{user.banned && (
|
|
|
|
<li className="list-inline-item badge badge-danger">
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('banned')}
|
2019-10-19 00:20:27 +00:00
|
|
|
</li>
|
|
|
|
)}
|
2019-09-06 00:18:48 +00:00
|
|
|
</ul>
|
|
|
|
</h5>
|
2020-07-08 00:28:47 +00:00
|
|
|
<div className="d-flex align-items-center mb-2">
|
|
|
|
<svg class="icon">
|
|
|
|
<use xlinkHref="#icon-cake"></use>
|
|
|
|
</svg>
|
|
|
|
<span className="ml-2">
|
|
|
|
{i18n.t('cake_day_title')}{' '}
|
|
|
|
{moment.utc(user.published).local().format('MMM DD, YYYY')}
|
|
|
|
</span>
|
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
<div>
|
2020-03-08 18:29:17 +00:00
|
|
|
{i18n.t('joined')} <MomentTime data={user} showAgo />
|
2019-10-19 00:20:27 +00:00
|
|
|
</div>
|
2020-02-04 16:29:54 +00:00
|
|
|
<div class="table-responsive mt-1">
|
2019-08-20 02:37:32 +00:00
|
|
|
<table class="table table-bordered table-sm mt-2 mb-0">
|
2020-03-08 18:33:04 +00:00
|
|
|
{/*
|
2020-02-04 16:29:54 +00:00
|
|
|
<tr>
|
|
|
|
<td class="text-center" colSpan={2}>
|
|
|
|
{i18n.t('number_of_points', {
|
|
|
|
count: user.post_score + user.comment_score,
|
|
|
|
})}
|
|
|
|
</td>
|
|
|
|
</tr>
|
2020-03-08 18:33:04 +00:00
|
|
|
*/}
|
2019-08-20 02:37:32 +00:00
|
|
|
<tr>
|
2020-03-08 18:33:04 +00:00
|
|
|
{/*
|
2019-10-19 00:20:27 +00:00
|
|
|
<td>
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('number_of_points', { count: user.post_score })}
|
2019-10-19 00:20:27 +00:00
|
|
|
</td>
|
2020-03-08 18:33:04 +00:00
|
|
|
*/}
|
2019-10-19 00:20:27 +00:00
|
|
|
<td>
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('number_of_posts', { count: user.number_of_posts })}
|
2019-10-19 00:20:27 +00:00
|
|
|
</td>
|
2020-03-08 18:33:04 +00:00
|
|
|
{/*
|
2019-08-20 02:37:32 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2019-10-19 00:20:27 +00:00
|
|
|
<td>
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('number_of_points', { count: user.comment_score })}
|
2019-10-19 00:20:27 +00:00
|
|
|
</td>
|
2020-03-08 18:33:04 +00:00
|
|
|
*/}
|
2019-10-19 00:20:27 +00:00
|
|
|
<td>
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('number_of_comments', {
|
|
|
|
count: user.number_of_comments,
|
|
|
|
})}
|
2019-10-19 00:20:27 +00:00
|
|
|
</td>
|
2019-08-20 02:37:32 +00:00
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</div>
|
2020-01-22 21:35:29 +00:00
|
|
|
{this.isCurrentUser ? (
|
2019-10-30 03:35:39 +00:00
|
|
|
<button
|
|
|
|
class="btn btn-block btn-secondary mt-3"
|
|
|
|
onClick={linkEvent(this, this.handleLogoutClick)}
|
|
|
|
>
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('logout')}
|
2019-10-30 03:35:39 +00:00
|
|
|
</button>
|
2020-01-22 21:35:29 +00:00
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<a
|
2020-04-14 23:18:13 +00:00
|
|
|
className={`btn btn-block btn-secondary mt-3 ${
|
|
|
|
!this.state.user.matrix_user_id && 'disabled'
|
|
|
|
}`}
|
2020-01-22 21:35:29 +00:00
|
|
|
target="_blank"
|
2020-06-30 13:40:57 +00:00
|
|
|
rel="noopener"
|
2020-01-22 21:35:29 +00:00
|
|
|
href={`https://matrix.to/#/${this.state.user.matrix_user_id}`}
|
|
|
|
>
|
|
|
|
{i18n.t('send_secure_message')}
|
|
|
|
</a>
|
|
|
|
<Link
|
|
|
|
class="btn btn-block btn-secondary mt-3"
|
|
|
|
to={`/create_private_message?recipient_id=${this.state.user.id}`}
|
|
|
|
>
|
|
|
|
{i18n.t('send_message')}
|
|
|
|
</Link>
|
|
|
|
</>
|
2019-10-30 03:35:39 +00:00
|
|
|
)}
|
2019-08-20 02:37:32 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-04-08 05:19:02 +00:00
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
|
2019-10-19 00:20:27 +00:00
|
|
|
userSettings() {
|
2019-08-14 02:52:43 +00:00
|
|
|
return (
|
|
|
|
<div>
|
2019-08-20 02:37:32 +00:00
|
|
|
<div class="card border-secondary mb-3">
|
|
|
|
<div class="card-body">
|
2020-02-02 18:50:44 +00:00
|
|
|
<h5>{i18n.t('settings')}</h5>
|
2019-08-20 02:37:32 +00:00
|
|
|
<form onSubmit={linkEvent(this, this.handleUserSettingsSubmit)}>
|
2019-12-29 20:39:48 +00:00
|
|
|
<div class="form-group">
|
2020-02-02 18:50:44 +00:00
|
|
|
<label>{i18n.t('avatar')}</label>
|
2020-01-01 20:46:14 +00:00
|
|
|
<form class="d-inline">
|
|
|
|
<label
|
|
|
|
htmlFor="file-upload"
|
|
|
|
class="pointer ml-4 text-muted small font-weight-bold"
|
|
|
|
>
|
2020-07-10 00:04:09 +00:00
|
|
|
{!this.checkSettingsAvatar ? (
|
2020-01-14 21:58:14 +00:00
|
|
|
<span class="btn btn-sm btn-secondary">
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('upload_avatar')}
|
2020-01-14 21:58:14 +00:00
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<img
|
|
|
|
height="80"
|
|
|
|
width="80"
|
|
|
|
src={this.state.userSettingsForm.avatar}
|
|
|
|
class="rounded-circle"
|
|
|
|
/>
|
|
|
|
)}
|
2020-01-01 20:46:14 +00:00
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
id="file-upload"
|
|
|
|
type="file"
|
|
|
|
accept="image/*,video/*"
|
|
|
|
name="file"
|
|
|
|
class="d-none"
|
|
|
|
disabled={!UserService.Instance.user}
|
|
|
|
onChange={linkEvent(this, this.handleImageUpload)}
|
|
|
|
/>
|
|
|
|
</form>
|
2019-12-29 20:39:48 +00:00
|
|
|
</div>
|
2020-07-10 00:04:09 +00:00
|
|
|
{this.checkSettingsAvatar && (
|
|
|
|
<div class="form-group">
|
|
|
|
<button
|
|
|
|
class="btn btn-secondary btn-block"
|
|
|
|
onClick={linkEvent(this, this.removeAvatar)}
|
|
|
|
>
|
|
|
|
{`${capitalizeFirstLetter(i18n.t('remove'))} ${i18n.t(
|
|
|
|
'avatar'
|
|
|
|
)}`}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)}
|
2019-12-09 08:24:53 +00:00
|
|
|
<div class="form-group">
|
2020-02-02 18:50:44 +00:00
|
|
|
<label>{i18n.t('language')}</label>
|
2020-01-01 20:46:14 +00:00
|
|
|
<select
|
|
|
|
value={this.state.userSettingsForm.lang}
|
|
|
|
onChange={linkEvent(this, this.handleUserSettingsLangChange)}
|
|
|
|
class="ml-2 custom-select custom-select-sm w-auto"
|
|
|
|
>
|
2020-02-02 18:50:44 +00:00
|
|
|
<option disabled>{i18n.t('language')}</option>
|
|
|
|
<option value="browser">{i18n.t('browser_default')}</option>
|
2020-01-01 20:46:14 +00:00
|
|
|
<option disabled>──</option>
|
|
|
|
{languages.map(lang => (
|
|
|
|
<option value={lang.code}>{lang.name}</option>
|
|
|
|
))}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
2020-02-02 18:50:44 +00:00
|
|
|
<label>{i18n.t('theme')}</label>
|
2020-01-01 20:46:14 +00:00
|
|
|
<select
|
|
|
|
value={this.state.userSettingsForm.theme}
|
|
|
|
onChange={linkEvent(this, this.handleUserSettingsThemeChange)}
|
|
|
|
class="ml-2 custom-select custom-select-sm w-auto"
|
|
|
|
>
|
2020-02-02 18:50:44 +00:00
|
|
|
<option disabled>{i18n.t('theme')}</option>
|
2020-01-01 20:46:14 +00:00
|
|
|
{themes.map(theme => (
|
|
|
|
<option value={theme}>{theme}</option>
|
|
|
|
))}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<form className="form-group">
|
|
|
|
<label>
|
2020-02-02 18:50:44 +00:00
|
|
|
<div class="mr-2">{i18n.t('sort_type')}</div>
|
2020-01-01 20:46:14 +00:00
|
|
|
</label>
|
|
|
|
<ListingTypeSelect
|
|
|
|
type_={this.state.userSettingsForm.default_listing_type}
|
|
|
|
onChange={this.handleUserSettingsListingTypeChange}
|
|
|
|
/>
|
|
|
|
</form>
|
|
|
|
<form className="form-group">
|
|
|
|
<label>
|
2020-02-02 18:50:44 +00:00
|
|
|
<div class="mr-2">{i18n.t('type')}</div>
|
2020-01-01 20:46:14 +00:00
|
|
|
</label>
|
|
|
|
<SortSelect
|
|
|
|
sort={this.state.userSettingsForm.default_sort_type}
|
|
|
|
onChange={this.handleUserSettingsSortTypeChange}
|
|
|
|
/>
|
|
|
|
</form>
|
|
|
|
<div class="form-group row">
|
2020-02-02 18:50:44 +00:00
|
|
|
<label class="col-lg-3 col-form-label" htmlFor="user-email">
|
|
|
|
{i18n.t('email')}
|
2020-01-01 20:46:14 +00:00
|
|
|
</label>
|
|
|
|
<div class="col-lg-9">
|
|
|
|
<input
|
|
|
|
type="email"
|
2020-01-31 20:52:27 +00:00
|
|
|
id="user-email"
|
2020-01-01 20:46:14 +00:00
|
|
|
class="form-control"
|
|
|
|
placeholder={i18n.t('optional')}
|
|
|
|
value={this.state.userSettingsForm.email}
|
|
|
|
onInput={linkEvent(
|
2019-12-09 08:24:53 +00:00
|
|
|
this,
|
2020-01-01 20:46:14 +00:00
|
|
|
this.handleUserSettingsEmailChange
|
2019-12-09 08:24:53 +00:00
|
|
|
)}
|
2020-01-01 20:46:14 +00:00
|
|
|
minLength={3}
|
|
|
|
/>
|
2019-12-09 08:24:53 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-01-22 21:35:29 +00:00
|
|
|
<div class="form-group row">
|
|
|
|
<label class="col-lg-5 col-form-label">
|
2020-06-30 13:40:57 +00:00
|
|
|
<a
|
|
|
|
href="https://about.riot.im/"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener"
|
|
|
|
>
|
2020-01-22 21:35:29 +00:00
|
|
|
{i18n.t('matrix_user_id')}
|
|
|
|
</a>
|
|
|
|
</label>
|
|
|
|
<div class="col-lg-7">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
class="form-control"
|
|
|
|
placeholder="@user:example.com"
|
|
|
|
value={this.state.userSettingsForm.matrix_user_id}
|
|
|
|
onInput={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleUserSettingsMatrixUserIdChange
|
|
|
|
)}
|
|
|
|
minLength={3}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-01-01 20:46:14 +00:00
|
|
|
<div class="form-group row">
|
2020-02-02 18:50:44 +00:00
|
|
|
<label class="col-lg-5 col-form-label" htmlFor="user-password">
|
|
|
|
{i18n.t('new_password')}
|
2020-01-01 20:46:14 +00:00
|
|
|
</label>
|
|
|
|
<div class="col-lg-7">
|
|
|
|
<input
|
|
|
|
type="password"
|
2020-01-31 20:52:27 +00:00
|
|
|
id="user-password"
|
2020-01-01 20:46:14 +00:00
|
|
|
class="form-control"
|
|
|
|
value={this.state.userSettingsForm.new_password}
|
2020-05-12 18:36:22 +00:00
|
|
|
autoComplete="new-password"
|
2020-01-01 20:46:14 +00:00
|
|
|
onInput={linkEvent(
|
2019-10-19 00:20:27 +00:00
|
|
|
this,
|
2020-01-01 20:46:14 +00:00
|
|
|
this.handleUserSettingsNewPasswordChange
|
2019-10-15 19:21:27 +00:00
|
|
|
)}
|
2020-01-01 20:46:14 +00:00
|
|
|
/>
|
2019-10-15 19:21:27 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-01-01 20:46:14 +00:00
|
|
|
<div class="form-group row">
|
2020-02-02 18:50:44 +00:00
|
|
|
<label
|
|
|
|
class="col-lg-5 col-form-label"
|
|
|
|
htmlFor="user-verify-password"
|
|
|
|
>
|
|
|
|
{i18n.t('verify_password')}
|
2020-01-01 20:46:14 +00:00
|
|
|
</label>
|
|
|
|
<div class="col-lg-7">
|
|
|
|
<input
|
|
|
|
type="password"
|
2020-01-31 20:52:27 +00:00
|
|
|
id="user-verify-password"
|
2020-01-01 20:46:14 +00:00
|
|
|
class="form-control"
|
|
|
|
value={this.state.userSettingsForm.new_password_verify}
|
2020-05-12 18:36:22 +00:00
|
|
|
autoComplete="new-password"
|
2020-01-01 20:46:14 +00:00
|
|
|
onInput={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleUserSettingsNewPasswordVerifyChange
|
|
|
|
)}
|
2019-10-21 04:21:54 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2020-01-01 20:46:14 +00:00
|
|
|
</div>
|
|
|
|
<div class="form-group row">
|
2020-02-02 18:50:44 +00:00
|
|
|
<label
|
|
|
|
class="col-lg-5 col-form-label"
|
|
|
|
htmlFor="user-old-password"
|
|
|
|
>
|
|
|
|
{i18n.t('old_password')}
|
2020-01-01 20:46:14 +00:00
|
|
|
</label>
|
|
|
|
<div class="col-lg-7">
|
|
|
|
<input
|
|
|
|
type="password"
|
2020-01-31 20:52:27 +00:00
|
|
|
id="user-old-password"
|
2020-01-01 20:46:14 +00:00
|
|
|
class="form-control"
|
|
|
|
value={this.state.userSettingsForm.old_password}
|
2020-05-12 18:36:22 +00:00
|
|
|
autoComplete="new-password"
|
2020-01-01 20:46:14 +00:00
|
|
|
onInput={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleUserSettingsOldPasswordChange
|
|
|
|
)}
|
2019-10-21 04:21:54 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2020-01-01 20:46:14 +00:00
|
|
|
</div>
|
2020-07-20 19:32:15 +00:00
|
|
|
{this.state.siteRes.site.enable_nsfw && (
|
2019-12-11 20:21:47 +00:00
|
|
|
<div class="form-group">
|
2020-01-01 20:46:14 +00:00
|
|
|
<div class="form-check">
|
|
|
|
<input
|
|
|
|
class="form-check-input"
|
2020-01-31 20:52:27 +00:00
|
|
|
id="user-show-nsfw"
|
2020-01-01 20:46:14 +00:00
|
|
|
type="checkbox"
|
|
|
|
checked={this.state.userSettingsForm.show_nsfw}
|
|
|
|
onChange={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleUserSettingsShowNsfwChange
|
|
|
|
)}
|
|
|
|
/>
|
2020-02-02 18:50:44 +00:00
|
|
|
<label class="form-check-label" htmlFor="user-show-nsfw">
|
|
|
|
{i18n.t('show_nsfw')}
|
2020-01-01 20:46:14 +00:00
|
|
|
</label>
|
2019-08-20 02:37:32 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-12-11 20:21:47 +00:00
|
|
|
)}
|
2020-01-02 21:55:54 +00:00
|
|
|
<div class="form-group">
|
|
|
|
<div class="form-check">
|
|
|
|
<input
|
|
|
|
class="form-check-input"
|
2020-01-31 20:52:27 +00:00
|
|
|
id="user-show-avatars"
|
2020-01-02 21:55:54 +00:00
|
|
|
type="checkbox"
|
|
|
|
checked={this.state.userSettingsForm.show_avatars}
|
|
|
|
onChange={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleUserSettingsShowAvatarsChange
|
|
|
|
)}
|
|
|
|
/>
|
2020-02-02 18:50:44 +00:00
|
|
|
<label class="form-check-label" htmlFor="user-show-avatars">
|
|
|
|
{i18n.t('show_avatars')}
|
2020-01-02 21:55:54 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<div class="form-check">
|
|
|
|
<input
|
|
|
|
class="form-check-input"
|
2020-01-31 20:52:27 +00:00
|
|
|
id="user-send-notifications-to-email"
|
2020-01-02 21:55:54 +00:00
|
|
|
type="checkbox"
|
|
|
|
disabled={!this.state.user.email}
|
|
|
|
checked={
|
|
|
|
this.state.userSettingsForm.send_notifications_to_email
|
|
|
|
}
|
|
|
|
onChange={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleUserSettingsSendNotificationsToEmailChange
|
|
|
|
)}
|
|
|
|
/>
|
2020-02-02 18:50:44 +00:00
|
|
|
<label
|
|
|
|
class="form-check-label"
|
|
|
|
htmlFor="user-send-notifications-to-email"
|
|
|
|
>
|
|
|
|
{i18n.t('send_notifications_to_email')}
|
2020-01-02 21:55:54 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-10-21 04:21:54 +00:00
|
|
|
<div class="form-group">
|
2020-01-01 20:46:14 +00:00
|
|
|
<button type="submit" class="btn btn-block btn-secondary mr-4">
|
|
|
|
{this.state.userSettingsLoading ? (
|
|
|
|
<svg class="icon icon-spinner spin">
|
|
|
|
<use xlinkHref="#icon-spinner"></use>
|
|
|
|
</svg>
|
|
|
|
) : (
|
|
|
|
capitalizeFirstLetter(i18n.t('save'))
|
|
|
|
)}
|
|
|
|
</button>
|
2019-10-21 04:21:54 +00:00
|
|
|
</div>
|
|
|
|
<hr />
|
|
|
|
<div class="form-group mb-0">
|
2020-01-01 20:46:14 +00:00
|
|
|
<button
|
|
|
|
class="btn btn-block btn-danger"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleDeleteAccountShowConfirmToggle
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
2020-01-01 20:46:14 +00:00
|
|
|
>
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('delete_account')}
|
2020-01-01 20:46:14 +00:00
|
|
|
</button>
|
|
|
|
{this.state.deleteAccountShowConfirm && (
|
|
|
|
<>
|
|
|
|
<div class="my-2 alert alert-danger" role="alert">
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('delete_account_confirm')}
|
2020-01-01 20:46:14 +00:00
|
|
|
</div>
|
|
|
|
<input
|
|
|
|
type="password"
|
|
|
|
value={this.state.deleteAccountForm.password}
|
2020-05-12 18:36:22 +00:00
|
|
|
autoComplete="new-password"
|
2020-01-01 20:46:14 +00:00
|
|
|
onInput={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleDeleteAccountPasswordChange
|
|
|
|
)}
|
|
|
|
class="form-control my-2"
|
|
|
|
/>
|
|
|
|
<button
|
|
|
|
class="btn btn-danger mr-4"
|
|
|
|
disabled={!this.state.deleteAccountForm.password}
|
|
|
|
onClick={linkEvent(this, this.handleDeleteAccount)}
|
|
|
|
>
|
|
|
|
{this.state.deleteAccountLoading ? (
|
|
|
|
<svg class="icon icon-spinner spin">
|
|
|
|
<use xlinkHref="#icon-spinner"></use>
|
|
|
|
</svg>
|
|
|
|
) : (
|
|
|
|
capitalizeFirstLetter(i18n.t('delete'))
|
|
|
|
)}
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-secondary"
|
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleDeleteAccountShowConfirmToggle
|
|
|
|
)}
|
|
|
|
>
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('cancel')}
|
2020-01-01 20:46:14 +00:00
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
)}
|
2019-08-20 02:37:32 +00:00
|
|
|
</div>
|
|
|
|
</form>
|
2019-08-14 02:52:43 +00:00
|
|
|
</div>
|
2019-08-20 02:37:32 +00:00
|
|
|
</div>
|
2019-08-14 02:52:43 +00:00
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-08-14 02:52:43 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
moderates() {
|
|
|
|
return (
|
|
|
|
<div>
|
2019-10-19 00:20:27 +00:00
|
|
|
{this.state.moderates.length > 0 && (
|
2019-10-15 19:21:27 +00:00
|
|
|
<div class="card border-secondary mb-3">
|
|
|
|
<div class="card-body">
|
2020-02-02 18:50:44 +00:00
|
|
|
<h5>{i18n.t('moderates')}</h5>
|
2019-10-19 00:20:27 +00:00
|
|
|
<ul class="list-unstyled mb-0">
|
|
|
|
{this.state.moderates.map(community => (
|
|
|
|
<li>
|
|
|
|
<Link to={`/c/${community.community_name}`}>
|
|
|
|
{community.community_name}
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
))}
|
2019-10-15 19:21:27 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
2019-04-08 05:19:02 +00:00
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
2019-04-08 05:19:02 +00:00
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
follows() {
|
|
|
|
return (
|
|
|
|
<div>
|
2019-10-19 00:20:27 +00:00
|
|
|
{this.state.follows.length > 0 && (
|
2019-08-20 02:37:32 +00:00
|
|
|
<div class="card border-secondary mb-3">
|
|
|
|
<div class="card-body">
|
2020-02-02 18:50:44 +00:00
|
|
|
<h5>{i18n.t('subscribed')}</h5>
|
2019-10-19 00:20:27 +00:00
|
|
|
<ul class="list-unstyled mb-0">
|
|
|
|
{this.state.follows.map(community => (
|
|
|
|
<li>
|
|
|
|
<Link to={`/c/${community.community_name}`}>
|
|
|
|
{community.community_name}
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
))}
|
2019-08-20 02:37:32 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
2019-04-08 05:19:02 +00:00
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
2019-04-08 05:19:02 +00:00
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 05:13:43 +00:00
|
|
|
updateUrl(paramUpdates: UrlParams) {
|
|
|
|
const page = paramUpdates.page || this.state.page;
|
|
|
|
const viewStr =
|
|
|
|
paramUpdates.view || UserDetailsView[this.state.view].toLowerCase();
|
|
|
|
const sortStr =
|
|
|
|
paramUpdates.sort || SortType[this.state.sort].toLowerCase();
|
2019-10-19 00:20:27 +00:00
|
|
|
this.props.history.push(
|
2020-07-14 05:13:43 +00:00
|
|
|
`/u/${this.state.username}/view/${viewStr}/sort/${sortStr}/page/${page}`
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-29 00:41:24 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 05:13:43 +00:00
|
|
|
handlePageChange(page: number) {
|
|
|
|
this.updateUrl({ page });
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
|
2019-10-21 00:49:13 +00:00
|
|
|
handleSortChange(val: SortType) {
|
2020-07-14 05:13:43 +00:00
|
|
|
this.updateUrl({ sort: SortType[val].toLowerCase(), page: 1 });
|
2019-04-17 18:30:13 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
handleViewChange(i: User, event: any) {
|
2020-07-14 05:13:43 +00:00
|
|
|
i.updateUrl({
|
|
|
|
view: UserDetailsView[Number(event.target.value)].toLowerCase(),
|
|
|
|
page: 1,
|
|
|
|
});
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 02:52:43 +00:00
|
|
|
handleUserSettingsShowNsfwChange(i: User, event: any) {
|
2020-07-14 05:13:43 +00:00
|
|
|
i.state.userSettingsForm.show_nsfw = event.target.checked;
|
|
|
|
i.setState(i.state);
|
2019-08-14 02:52:43 +00:00
|
|
|
}
|
|
|
|
|
2020-01-02 21:55:54 +00:00
|
|
|
handleUserSettingsShowAvatarsChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.show_avatars = event.target.checked;
|
|
|
|
UserService.Instance.user.show_avatars = event.target.checked; // Just for instant updates
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserSettingsSendNotificationsToEmailChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.send_notifications_to_email = event.target.checked;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-10-15 19:21:27 +00:00
|
|
|
handleUserSettingsThemeChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.theme = event.target.value;
|
2020-06-10 15:11:51 +00:00
|
|
|
setTheme(event.target.value, true);
|
2019-10-15 19:21:27 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-12-09 08:24:53 +00:00
|
|
|
handleUserSettingsLangChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.lang = event.target.value;
|
|
|
|
i18n.changeLanguage(i.state.userSettingsForm.lang);
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-10-21 04:21:54 +00:00
|
|
|
handleUserSettingsSortTypeChange(val: SortType) {
|
|
|
|
this.state.userSettingsForm.default_sort_type = val;
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserSettingsListingTypeChange(val: ListingType) {
|
|
|
|
this.state.userSettingsForm.default_listing_type = val;
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
|
2020-01-01 20:46:14 +00:00
|
|
|
handleUserSettingsEmailChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.email = event.target.value;
|
|
|
|
if (i.state.userSettingsForm.email == '' && !i.state.user.email) {
|
|
|
|
i.state.userSettingsForm.email = undefined;
|
|
|
|
}
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2020-01-22 21:35:29 +00:00
|
|
|
handleUserSettingsMatrixUserIdChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.matrix_user_id = event.target.value;
|
|
|
|
if (
|
|
|
|
i.state.userSettingsForm.matrix_user_id == '' &&
|
|
|
|
!i.state.user.matrix_user_id
|
|
|
|
) {
|
|
|
|
i.state.userSettingsForm.matrix_user_id = undefined;
|
|
|
|
}
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2020-01-01 20:46:14 +00:00
|
|
|
handleUserSettingsNewPasswordChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.new_password = event.target.value;
|
|
|
|
if (i.state.userSettingsForm.new_password == '') {
|
|
|
|
i.state.userSettingsForm.new_password = undefined;
|
|
|
|
}
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserSettingsNewPasswordVerifyChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.new_password_verify = event.target.value;
|
|
|
|
if (i.state.userSettingsForm.new_password_verify == '') {
|
|
|
|
i.state.userSettingsForm.new_password_verify = undefined;
|
|
|
|
}
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUserSettingsOldPasswordChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.old_password = event.target.value;
|
|
|
|
if (i.state.userSettingsForm.old_password == '') {
|
|
|
|
i.state.userSettingsForm.old_password = undefined;
|
|
|
|
}
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-12-29 20:39:48 +00:00
|
|
|
handleImageUpload(i: User, event: any) {
|
|
|
|
event.preventDefault();
|
|
|
|
let file = event.target.files[0];
|
2020-06-08 17:52:32 +00:00
|
|
|
const imageUploadUrl = `/pictrs/image`;
|
2019-12-29 20:39:48 +00:00
|
|
|
const formData = new FormData();
|
2020-06-09 21:17:24 +00:00
|
|
|
formData.append('images[]', file);
|
2019-12-29 20:39:48 +00:00
|
|
|
|
|
|
|
i.state.avatarLoading = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
|
|
|
|
fetch(imageUploadUrl, {
|
|
|
|
method: 'POST',
|
|
|
|
body: formData,
|
|
|
|
})
|
|
|
|
.then(res => res.json())
|
|
|
|
.then(res => {
|
2020-06-09 21:17:24 +00:00
|
|
|
console.log('pictrs upload:');
|
|
|
|
console.log(res);
|
|
|
|
if (res.msg == 'ok') {
|
|
|
|
let hash = res.files[0].file;
|
|
|
|
let url = `${window.location.origin}/pictrs/image/${hash}`;
|
|
|
|
i.state.userSettingsForm.avatar = url;
|
|
|
|
i.state.avatarLoading = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
} else {
|
|
|
|
i.state.avatarLoading = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
toast(JSON.stringify(res), 'danger');
|
2019-12-29 20:39:48 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
i.state.avatarLoading = false;
|
|
|
|
i.setState(i.state);
|
2020-01-23 03:29:11 +00:00
|
|
|
toast(error, 'danger');
|
2019-12-29 20:39:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-10 00:04:09 +00:00
|
|
|
removeAvatar(i: User, event: any) {
|
|
|
|
event.preventDefault();
|
|
|
|
i.state.userSettingsLoading = true;
|
|
|
|
i.state.userSettingsForm.avatar = '';
|
|
|
|
i.setState(i.state);
|
|
|
|
|
|
|
|
WebSocketService.Instance.saveUserSettings(i.state.userSettingsForm);
|
|
|
|
}
|
|
|
|
|
|
|
|
get checkSettingsAvatar(): boolean {
|
|
|
|
return (
|
|
|
|
this.state.userSettingsForm.avatar &&
|
|
|
|
this.state.userSettingsForm.avatar != ''
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-14 02:52:43 +00:00
|
|
|
handleUserSettingsSubmit(i: User, event: any) {
|
|
|
|
event.preventDefault();
|
|
|
|
i.state.userSettingsLoading = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
|
|
|
|
WebSocketService.Instance.saveUserSettings(i.state.userSettingsForm);
|
|
|
|
}
|
|
|
|
|
2019-10-15 22:09:01 +00:00
|
|
|
handleDeleteAccountShowConfirmToggle(i: User, event: any) {
|
|
|
|
event.preventDefault();
|
|
|
|
i.state.deleteAccountShowConfirm = !i.state.deleteAccountShowConfirm;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-10-18 04:25:23 +00:00
|
|
|
handleDeleteAccountPasswordChange(i: User, event: any) {
|
|
|
|
i.state.deleteAccountForm.password = event.target.value;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2019-10-30 03:35:39 +00:00
|
|
|
handleLogoutClick(i: User) {
|
|
|
|
UserService.Instance.logout();
|
|
|
|
i.context.router.history.push('/');
|
|
|
|
}
|
|
|
|
|
2019-10-15 22:09:01 +00:00
|
|
|
handleDeleteAccount(i: User, event: any) {
|
|
|
|
event.preventDefault();
|
|
|
|
i.state.deleteAccountLoading = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
|
2019-10-18 04:25:23 +00:00
|
|
|
WebSocketService.Instance.deleteAccount(i.state.deleteAccountForm);
|
2019-10-15 22:09:01 +00:00
|
|
|
}
|
|
|
|
|
2020-01-19 05:38:45 +00:00
|
|
|
parseMessage(msg: WebSocketJsonResponse) {
|
2020-07-15 14:00:55 +00:00
|
|
|
console.log(msg);
|
2020-07-12 08:00:10 +00:00
|
|
|
const res = wsJsonToRes(msg);
|
2020-01-25 14:58:53 +00:00
|
|
|
if (msg.error) {
|
2020-01-23 03:29:11 +00:00
|
|
|
toast(i18n.t(msg.error), 'danger');
|
2020-01-25 14:58:53 +00:00
|
|
|
if (msg.error == 'couldnt_find_that_username_or_email') {
|
2019-12-29 01:58:01 +00:00
|
|
|
this.context.router.history.push('/');
|
|
|
|
}
|
2020-07-12 08:00:10 +00:00
|
|
|
this.setState({
|
|
|
|
deleteAccountLoading: false,
|
|
|
|
avatarLoading: false,
|
|
|
|
userSettingsLoading: false,
|
|
|
|
});
|
2019-04-08 05:19:02 +00:00
|
|
|
return;
|
2020-01-19 04:54:10 +00:00
|
|
|
} else if (res.op == UserOperation.GetUserDetails) {
|
2020-07-12 08:00:10 +00:00
|
|
|
// Since the UserDetails contains posts/comments as well as some general user info we listen here as well
|
|
|
|
// and set the parent state if it is not set or differs
|
|
|
|
const data = res.data as UserDetailsResponse;
|
|
|
|
|
|
|
|
if (this.state.user.id !== data.user.id) {
|
|
|
|
this.state.user = data.user;
|
|
|
|
this.state.follows = data.follows;
|
|
|
|
this.state.moderates = data.moderates;
|
|
|
|
|
|
|
|
if (this.isCurrentUser) {
|
|
|
|
this.state.userSettingsForm.show_nsfw =
|
|
|
|
UserService.Instance.user.show_nsfw;
|
|
|
|
this.state.userSettingsForm.theme = UserService.Instance.user.theme
|
|
|
|
? UserService.Instance.user.theme
|
|
|
|
: 'darkly';
|
|
|
|
this.state.userSettingsForm.default_sort_type =
|
|
|
|
UserService.Instance.user.default_sort_type;
|
|
|
|
this.state.userSettingsForm.default_listing_type =
|
|
|
|
UserService.Instance.user.default_listing_type;
|
|
|
|
this.state.userSettingsForm.lang = UserService.Instance.user.lang;
|
|
|
|
this.state.userSettingsForm.avatar = UserService.Instance.user.avatar;
|
|
|
|
this.state.userSettingsForm.email = this.state.user.email;
|
|
|
|
this.state.userSettingsForm.send_notifications_to_email = this.state.user.send_notifications_to_email;
|
|
|
|
this.state.userSettingsForm.show_avatars =
|
|
|
|
UserService.Instance.user.show_avatars;
|
|
|
|
this.state.userSettingsForm.matrix_user_id = this.state.user.matrix_user_id;
|
|
|
|
}
|
2020-07-17 15:48:06 +00:00
|
|
|
this.state.loading = false;
|
2020-07-12 08:00:10 +00:00
|
|
|
this.setState(this.state);
|
2020-02-08 04:05:15 +00:00
|
|
|
}
|
2020-01-19 04:54:10 +00:00
|
|
|
} else if (res.op == UserOperation.SaveUserSettings) {
|
2020-07-12 08:00:10 +00:00
|
|
|
const data = res.data as LoginResponse;
|
2020-01-19 04:54:10 +00:00
|
|
|
UserService.Instance.login(data);
|
2020-07-12 08:00:10 +00:00
|
|
|
this.setState({
|
|
|
|
userSettingsLoading: false,
|
|
|
|
});
|
|
|
|
window.scrollTo(0, 0);
|
2020-01-19 04:54:10 +00:00
|
|
|
} else if (res.op == UserOperation.DeleteAccount) {
|
2020-07-12 08:00:10 +00:00
|
|
|
this.setState({
|
|
|
|
deleteAccountLoading: false,
|
|
|
|
deleteAccountShowConfirm: false,
|
|
|
|
});
|
2019-10-19 00:20:27 +00:00
|
|
|
this.context.router.history.push('/');
|
2020-07-08 05:02:14 +00:00
|
|
|
} else if (res.op == UserOperation.GetSite) {
|
2020-07-12 08:00:10 +00:00
|
|
|
const data = res.data as GetSiteResponse;
|
2020-07-20 19:32:15 +00:00
|
|
|
this.state.siteRes = data;
|
|
|
|
this.setState(this.state);
|
|
|
|
} else if (res.op == UserOperation.AddAdmin) {
|
|
|
|
const data = res.data as AddAdminResponse;
|
|
|
|
this.state.siteRes.admins = data.admins;
|
|
|
|
this.setState(this.state);
|
2019-04-22 18:32:50 +00:00
|
|
|
}
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
}
|