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,
|
|
|
|
Post,
|
|
|
|
Comment,
|
|
|
|
CommunityUser,
|
|
|
|
GetUserDetailsForm,
|
|
|
|
SortType,
|
2019-10-21 04:21:54 +00:00
|
|
|
ListingType,
|
2019-10-19 00:20:27 +00:00
|
|
|
UserDetailsResponse,
|
|
|
|
UserView,
|
|
|
|
CommentResponse,
|
|
|
|
UserSettingsForm,
|
|
|
|
LoginResponse,
|
|
|
|
BanUserResponse,
|
|
|
|
AddAdminResponse,
|
|
|
|
DeleteAccountForm,
|
2020-01-20 23:39:45 +00:00
|
|
|
CreatePostLikeResponse,
|
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 {
|
|
|
|
msgOp,
|
|
|
|
fetchLimit,
|
|
|
|
routeSortTypeToEnum,
|
|
|
|
capitalizeFirstLetter,
|
|
|
|
themes,
|
|
|
|
setTheme,
|
2019-12-09 08:24:53 +00:00
|
|
|
languages,
|
2020-01-02 21:55:54 +00:00
|
|
|
showAvatars,
|
2019-10-19 00:20:27 +00:00
|
|
|
} from '../utils';
|
2019-04-08 05:19:02 +00:00
|
|
|
import { PostListing } from './post-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 { CommentNodes } from './comment-nodes';
|
|
|
|
import { MomentTime } from './moment-time';
|
2019-08-10 00:14:43 +00:00
|
|
|
import { i18n } from '../i18next';
|
|
|
|
import { T } from 'inferno-i18next';
|
2019-04-08 05:19:02 +00:00
|
|
|
|
|
|
|
enum View {
|
2019-10-19 00:20:27 +00:00
|
|
|
Overview,
|
|
|
|
Comments,
|
|
|
|
Posts,
|
|
|
|
Saved,
|
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>;
|
|
|
|
comments: Array<Comment>;
|
|
|
|
posts: Array<Post>;
|
|
|
|
saved?: Array<Post>;
|
2019-10-14 00:36:35 +00:00
|
|
|
admins: Array<UserView>;
|
2019-04-08 05:19:02 +00:00
|
|
|
view: View;
|
|
|
|
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;
|
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,
|
|
|
|
fedi_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,
|
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: [],
|
|
|
|
comments: [],
|
|
|
|
posts: [],
|
2019-10-14 00:36:35 +00:00
|
|
|
admins: [],
|
2019-04-29 00:41:24 +00:00
|
|
|
loading: true,
|
2019-12-29 20:39:48 +00:00
|
|
|
avatarLoading: false,
|
2019-04-29 00:41:24 +00:00
|
|
|
view: this.getViewFromProps(this.props),
|
|
|
|
sort: this.getSortTypeFromProps(this.props),
|
|
|
|
page: this.getPageFromProps(this.props),
|
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
|
|
|
},
|
|
|
|
};
|
2019-04-08 05:19:02 +00:00
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
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
|
|
|
|
);
|
2019-04-08 05:19:02 +00:00
|
|
|
|
2019-04-17 18:30:13 +00:00
|
|
|
this.state.user_id = Number(this.props.match.params.id);
|
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
|
|
|
|
2019-04-17 18:30:13 +00:00
|
|
|
this.refetch();
|
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
|
|
|
}
|
|
|
|
|
2019-04-29 00:41:24 +00:00
|
|
|
getViewFromProps(props: any): View {
|
2019-10-19 00:20:27 +00:00
|
|
|
return props.match.params.view
|
|
|
|
? View[capitalizeFirstLetter(props.match.params.view)]
|
|
|
|
: View.Overview;
|
2019-04-29 00:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getSortTypeFromProps(props: any): SortType {
|
2019-10-19 00:20:27 +00:00
|
|
|
return props.match.params.sort
|
|
|
|
? routeSortTypeToEnum(props.match.params.sort)
|
|
|
|
: SortType.New;
|
2019-04-29 00:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getPageFromProps(props: any): number {
|
2019-10-19 00:20:27 +00:00
|
|
|
return props.match.params.page ? Number(props.match.params.page) : 1;
|
2019-04-29 00:41:24 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
componentWillUnmount() {
|
|
|
|
this.subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
|
2019-04-29 00:41:24 +00:00
|
|
|
// Necessary for back button for some reason
|
|
|
|
componentWillReceiveProps(nextProps: any) {
|
2019-10-21 00:49:13 +00:00
|
|
|
if (
|
|
|
|
nextProps.history.action == 'POP' ||
|
|
|
|
nextProps.history.action == 'PUSH'
|
|
|
|
) {
|
2019-04-29 00:41:24 +00:00
|
|
|
this.state.view = this.getViewFromProps(nextProps);
|
|
|
|
this.state.sort = this.getSortTypeFromProps(nextProps);
|
|
|
|
this.state.page = this.getPageFromProps(nextProps);
|
2019-10-21 00:49:13 +00:00
|
|
|
this.setState(this.state);
|
2019-04-29 00:41:24 +00:00
|
|
|
this.refetch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div class="container">
|
2019-10-19 00:20:27 +00:00
|
|
|
{this.state.loading ? (
|
|
|
|
<h5>
|
|
|
|
<svg class="icon icon-spinner spin">
|
|
|
|
<use xlinkHref="#icon-spinner"></use>
|
|
|
|
</svg>
|
|
|
|
</h5>
|
|
|
|
) : (
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-12 col-md-8">
|
2019-12-29 20:39:48 +00:00
|
|
|
<h5>
|
2020-01-02 21:55:54 +00:00
|
|
|
{this.state.user.avatar && showAvatars() && (
|
2019-12-29 20:39:48 +00:00
|
|
|
<img
|
|
|
|
height="80"
|
|
|
|
width="80"
|
|
|
|
src={this.state.user.avatar}
|
|
|
|
class="rounded-circle mr-2"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<span>/u/{this.state.user.name}</span>
|
|
|
|
</h5>
|
2019-10-19 00:20:27 +00:00
|
|
|
{this.selects()}
|
|
|
|
{this.state.view == View.Overview && this.overview()}
|
|
|
|
{this.state.view == View.Comments && this.comments()}
|
|
|
|
{this.state.view == View.Posts && this.posts()}
|
|
|
|
{this.state.view == View.Saved && this.overview()}
|
|
|
|
{this.paginator()}
|
|
|
|
</div>
|
|
|
|
<div class="col-12 col-md-4">
|
|
|
|
{this.userInfo()}
|
|
|
|
{this.isCurrentUser && this.userSettings()}
|
|
|
|
{this.moderates()}
|
|
|
|
{this.follows()}
|
|
|
|
</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
|
|
|
}
|
|
|
|
|
|
|
|
selects() {
|
|
|
|
return (
|
|
|
|
<div className="mb-2">
|
2019-10-19 00:20:27 +00:00
|
|
|
<select
|
|
|
|
value={this.state.view}
|
|
|
|
onChange={linkEvent(this, this.handleViewChange)}
|
|
|
|
class="custom-select custom-select-sm w-auto"
|
|
|
|
>
|
|
|
|
<option disabled>
|
|
|
|
<T i18nKey="view">#</T>
|
|
|
|
</option>
|
|
|
|
<option value={View.Overview}>
|
|
|
|
<T i18nKey="overview">#</T>
|
|
|
|
</option>
|
|
|
|
<option value={View.Comments}>
|
|
|
|
<T i18nKey="comments">#</T>
|
|
|
|
</option>
|
|
|
|
<option value={View.Posts}>
|
|
|
|
<T i18nKey="posts">#</T>
|
|
|
|
</option>
|
|
|
|
<option value={View.Saved}>
|
|
|
|
<T i18nKey="saved">#</T>
|
|
|
|
</option>
|
2019-04-08 05:19:02 +00:00
|
|
|
</select>
|
2019-10-21 00:49:13 +00:00
|
|
|
<span class="ml-2">
|
|
|
|
<SortSelect
|
|
|
|
sort={this.state.sort}
|
|
|
|
onChange={this.handleSortChange}
|
|
|
|
hideHot
|
|
|
|
/>
|
|
|
|
</span>
|
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"
|
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
|
|
|
}
|
|
|
|
|
|
|
|
overview() {
|
2019-10-19 00:20:27 +00:00
|
|
|
let combined: Array<{ type_: string; data: Comment | Post }> = [];
|
|
|
|
let comments = this.state.comments.map(e => {
|
|
|
|
return { type_: 'comments', data: e };
|
|
|
|
});
|
|
|
|
let posts = this.state.posts.map(e => {
|
|
|
|
return { type_: 'posts', data: e };
|
|
|
|
});
|
2019-04-15 23:12:06 +00:00
|
|
|
|
|
|
|
combined.push(...comments);
|
|
|
|
combined.push(...posts);
|
2019-04-08 05:19:02 +00:00
|
|
|
|
|
|
|
// Sort it
|
|
|
|
if (this.state.sort == SortType.New) {
|
2019-04-15 23:12:06 +00:00
|
|
|
combined.sort((a, b) => b.data.published.localeCompare(a.data.published));
|
2019-04-08 05:19:02 +00:00
|
|
|
} else {
|
2019-04-15 23:12:06 +00:00
|
|
|
combined.sort((a, b) => b.data.score - a.data.score);
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2019-10-19 00:20:27 +00:00
|
|
|
{combined.map(i => (
|
2019-04-08 05:19:02 +00:00
|
|
|
<div>
|
2019-10-19 00:20:27 +00:00
|
|
|
{i.type_ == 'posts' ? (
|
|
|
|
<PostListing
|
|
|
|
post={i.data as Post}
|
|
|
|
admins={this.state.admins}
|
|
|
|
showCommunity
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<CommentNodes
|
|
|
|
nodes={[{ comment: i.data as Comment }]}
|
2019-10-14 00:36:35 +00:00
|
|
|
admins={this.state.admins}
|
2019-10-19 00:20:27 +00:00
|
|
|
noIndent
|
|
|
|
/>
|
|
|
|
)}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
comments() {
|
|
|
|
return (
|
|
|
|
<div>
|
2019-10-19 00:20:27 +00:00
|
|
|
{this.state.comments.map(comment => (
|
|
|
|
<CommentNodes
|
|
|
|
nodes={[{ comment: comment }]}
|
2019-10-14 00:36:35 +00:00
|
|
|
admins={this.state.admins}
|
2019-10-19 00:20:27 +00:00
|
|
|
noIndent
|
|
|
|
/>
|
|
|
|
))}
|
2019-04-08 05:19:02 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
posts() {
|
|
|
|
return (
|
|
|
|
<div>
|
2019-10-19 00:20:27 +00:00
|
|
|
{this.state.posts.map(post => (
|
2020-01-20 23:39:45 +00:00
|
|
|
<PostListing post={post} admins={this.state.admins} showCommunity />
|
2019-10-19 00:20:27 +00:00
|
|
|
))}
|
2019-04-08 05:19:02 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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">
|
|
|
|
<li className="list-inline-item">{user.name}</li>
|
2019-10-19 00:20:27 +00:00
|
|
|
{user.banned && (
|
|
|
|
<li className="list-inline-item badge badge-danger">
|
|
|
|
<T i18nKey="banned">#</T>
|
|
|
|
</li>
|
|
|
|
)}
|
2019-09-06 00:18:48 +00:00
|
|
|
</ul>
|
|
|
|
</h5>
|
2019-10-19 00:20:27 +00:00
|
|
|
<div>
|
|
|
|
{i18n.t('joined')} <MomentTime data={user} />
|
|
|
|
</div>
|
2019-08-20 02:37:32 +00:00
|
|
|
<div class="table-responsive">
|
|
|
|
<table class="table table-bordered table-sm mt-2 mb-0">
|
|
|
|
<tr>
|
2019-10-19 00:20:27 +00:00
|
|
|
<td>
|
|
|
|
<T
|
|
|
|
i18nKey="number_of_points"
|
|
|
|
interpolation={{ count: user.post_score }}
|
|
|
|
>
|
|
|
|
#
|
|
|
|
</T>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<T
|
|
|
|
i18nKey="number_of_posts"
|
|
|
|
interpolation={{ count: user.number_of_posts }}
|
|
|
|
>
|
|
|
|
#
|
|
|
|
</T>
|
|
|
|
</td>
|
2019-08-20 02:37:32 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2019-10-19 00:20:27 +00:00
|
|
|
<td>
|
|
|
|
<T
|
|
|
|
i18nKey="number_of_points"
|
|
|
|
interpolation={{ count: user.comment_score }}
|
|
|
|
>
|
|
|
|
#
|
|
|
|
</T>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<T
|
|
|
|
i18nKey="number_of_comments"
|
|
|
|
interpolation={{ count: user.number_of_comments }}
|
|
|
|
>
|
|
|
|
#
|
|
|
|
</T>
|
|
|
|
</td>
|
2019-08-20 02:37:32 +00:00
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</div>
|
2019-10-30 03:35:39 +00:00
|
|
|
{this.isCurrentUser && (
|
|
|
|
<button
|
|
|
|
class="btn btn-block btn-secondary mt-3"
|
|
|
|
onClick={linkEvent(this, this.handleLogoutClick)}
|
|
|
|
>
|
|
|
|
<T i18nKey="logout">#</T>
|
|
|
|
</button>
|
|
|
|
)}
|
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">
|
2019-10-19 00:20:27 +00:00
|
|
|
<h5>
|
|
|
|
<T i18nKey="settings">#</T>
|
|
|
|
</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-01-01 20:46:14 +00:00
|
|
|
<label>
|
|
|
|
<T i18nKey="avatar">#</T>
|
|
|
|
</label>
|
|
|
|
<form class="d-inline">
|
|
|
|
<label
|
|
|
|
htmlFor="file-upload"
|
|
|
|
class="pointer ml-4 text-muted small font-weight-bold"
|
|
|
|
>
|
2020-01-14 21:58:14 +00:00
|
|
|
{!this.state.userSettingsForm.avatar ? (
|
|
|
|
<span class="btn btn-sm btn-secondary">
|
|
|
|
<T i18nKey="upload_avatar">#</T>
|
|
|
|
</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>
|
2019-12-09 08:24:53 +00:00
|
|
|
<div class="form-group">
|
2020-01-01 20:46:14 +00:00
|
|
|
<label>
|
|
|
|
<T i18nKey="language">#</T>
|
|
|
|
</label>
|
|
|
|
<select
|
|
|
|
value={this.state.userSettingsForm.lang}
|
|
|
|
onChange={linkEvent(this, this.handleUserSettingsLangChange)}
|
|
|
|
class="ml-2 custom-select custom-select-sm w-auto"
|
|
|
|
>
|
|
|
|
<option disabled>
|
2019-12-09 08:24:53 +00:00
|
|
|
<T i18nKey="language">#</T>
|
2020-01-01 20:46:14 +00:00
|
|
|
</option>
|
|
|
|
<option value="browser">
|
|
|
|
<T i18nKey="browser_default">#</T>
|
|
|
|
</option>
|
|
|
|
<option disabled>──</option>
|
|
|
|
{languages.map(lang => (
|
|
|
|
<option value={lang.code}>{lang.name}</option>
|
|
|
|
))}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<label>
|
|
|
|
<T i18nKey="theme">#</T>
|
|
|
|
</label>
|
|
|
|
<select
|
|
|
|
value={this.state.userSettingsForm.theme}
|
|
|
|
onChange={linkEvent(this, this.handleUserSettingsThemeChange)}
|
|
|
|
class="ml-2 custom-select custom-select-sm w-auto"
|
|
|
|
>
|
|
|
|
<option disabled>
|
|
|
|
<T i18nKey="theme">#</T>
|
|
|
|
</option>
|
|
|
|
{themes.map(theme => (
|
|
|
|
<option value={theme}>{theme}</option>
|
|
|
|
))}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<form className="form-group">
|
|
|
|
<label>
|
|
|
|
<T i18nKey="sort_type" class="mr-2">
|
|
|
|
#
|
|
|
|
</T>
|
|
|
|
</label>
|
|
|
|
<ListingTypeSelect
|
|
|
|
type_={this.state.userSettingsForm.default_listing_type}
|
|
|
|
onChange={this.handleUserSettingsListingTypeChange}
|
|
|
|
/>
|
|
|
|
</form>
|
|
|
|
<form className="form-group">
|
|
|
|
<label>
|
|
|
|
<T i18nKey="type" class="mr-2">
|
|
|
|
#
|
|
|
|
</T>
|
|
|
|
</label>
|
|
|
|
<SortSelect
|
|
|
|
sort={this.state.userSettingsForm.default_sort_type}
|
|
|
|
onChange={this.handleUserSettingsSortTypeChange}
|
|
|
|
/>
|
|
|
|
</form>
|
|
|
|
<div class="form-group row">
|
|
|
|
<label class="col-lg-3 col-form-label">
|
|
|
|
<T i18nKey="email">#</T>
|
|
|
|
</label>
|
|
|
|
<div class="col-lg-9">
|
|
|
|
<input
|
|
|
|
type="email"
|
|
|
|
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-01 20:46:14 +00:00
|
|
|
<div class="form-group row">
|
|
|
|
<label class="col-lg-5 col-form-label">
|
|
|
|
<T i18nKey="new_password">#</T>
|
|
|
|
</label>
|
|
|
|
<div class="col-lg-7">
|
|
|
|
<input
|
|
|
|
type="password"
|
|
|
|
class="form-control"
|
|
|
|
value={this.state.userSettingsForm.new_password}
|
|
|
|
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">
|
|
|
|
<label class="col-lg-5 col-form-label">
|
|
|
|
<T i18nKey="verify_password">#</T>
|
|
|
|
</label>
|
|
|
|
<div class="col-lg-7">
|
|
|
|
<input
|
|
|
|
type="password"
|
|
|
|
class="form-control"
|
|
|
|
value={this.state.userSettingsForm.new_password_verify}
|
|
|
|
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">
|
|
|
|
<label class="col-lg-5 col-form-label">
|
|
|
|
<T i18nKey="old_password">#</T>
|
|
|
|
</label>
|
|
|
|
<div class="col-lg-7">
|
|
|
|
<input
|
|
|
|
type="password"
|
|
|
|
class="form-control"
|
|
|
|
value={this.state.userSettingsForm.old_password}
|
|
|
|
onInput={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleUserSettingsOldPasswordChange
|
|
|
|
)}
|
2019-10-21 04:21:54 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2020-01-01 20:46:14 +00:00
|
|
|
</div>
|
2019-12-11 20:21:47 +00:00
|
|
|
{WebSocketService.Instance.site.enable_nsfw && (
|
|
|
|
<div class="form-group">
|
2020-01-01 20:46:14 +00:00
|
|
|
<div class="form-check">
|
|
|
|
<input
|
|
|
|
class="form-check-input"
|
|
|
|
type="checkbox"
|
|
|
|
checked={this.state.userSettingsForm.show_nsfw}
|
|
|
|
onChange={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleUserSettingsShowNsfwChange
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<label class="form-check-label">
|
|
|
|
<T i18nKey="show_nsfw">#</T>
|
|
|
|
</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"
|
|
|
|
type="checkbox"
|
|
|
|
checked={this.state.userSettingsForm.show_avatars}
|
|
|
|
onChange={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleUserSettingsShowAvatarsChange
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<label class="form-check-label">
|
|
|
|
<T i18nKey="show_avatars">#</T>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<div class="form-check">
|
|
|
|
<input
|
|
|
|
class="form-check-input"
|
|
|
|
type="checkbox"
|
|
|
|
disabled={!this.state.user.email}
|
|
|
|
checked={
|
|
|
|
this.state.userSettingsForm.send_notifications_to_email
|
|
|
|
}
|
|
|
|
onChange={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleUserSettingsSendNotificationsToEmailChange
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<label class="form-check-label">
|
|
|
|
<T i18nKey="send_notifications_to_email">#</T>
|
|
|
|
</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
|
|
|
>
|
|
|
|
<T i18nKey="delete_account">#</T>
|
|
|
|
</button>
|
|
|
|
{this.state.deleteAccountShowConfirm && (
|
|
|
|
<>
|
|
|
|
<div class="my-2 alert alert-danger" role="alert">
|
|
|
|
<T i18nKey="delete_account_confirm">#</T>
|
|
|
|
</div>
|
|
|
|
<input
|
|
|
|
type="password"
|
|
|
|
value={this.state.deleteAccountForm.password}
|
|
|
|
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
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<T i18nKey="cancel">#</T>
|
|
|
|
</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">
|
2019-10-19 00:20:27 +00:00
|
|
|
<h5>
|
|
|
|
<T i18nKey="moderates">#</T>
|
|
|
|
</h5>
|
|
|
|
<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">
|
2019-10-19 00:20:27 +00:00
|
|
|
<h5>
|
|
|
|
<T i18nKey="subscribed">#</T>
|
|
|
|
</h5>
|
|
|
|
<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
|
|
|
}
|
|
|
|
|
2019-04-17 18:30:13 +00:00
|
|
|
paginator() {
|
|
|
|
return (
|
2019-08-20 02:37:32 +00:00
|
|
|
<div class="my-2">
|
2019-10-19 00:20:27 +00:00
|
|
|
{this.state.page > 1 && (
|
|
|
|
<button
|
|
|
|
class="btn btn-sm btn-secondary mr-1"
|
|
|
|
onClick={linkEvent(this, this.prevPage)}
|
|
|
|
>
|
|
|
|
<T i18nKey="prev">#</T>
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
<button
|
|
|
|
class="btn btn-sm btn-secondary"
|
|
|
|
onClick={linkEvent(this, this.nextPage)}
|
|
|
|
>
|
|
|
|
<T i18nKey="next">#</T>
|
|
|
|
</button>
|
2019-04-17 18:30:13 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-29 00:41:24 +00:00
|
|
|
updateUrl() {
|
|
|
|
let viewStr = View[this.state.view].toLowerCase();
|
|
|
|
let sortStr = SortType[this.state.sort].toLowerCase();
|
2019-10-19 00:20:27 +00:00
|
|
|
this.props.history.push(
|
|
|
|
`/u/${this.state.user.name}/view/${viewStr}/sort/${sortStr}/page/${this.state.page}`
|
|
|
|
);
|
2019-04-29 00:41:24 +00:00
|
|
|
}
|
|
|
|
|
2019-10-19 00:20:27 +00:00
|
|
|
nextPage(i: User) {
|
2019-04-17 18:30:13 +00:00
|
|
|
i.state.page++;
|
|
|
|
i.setState(i.state);
|
2019-04-29 00:41:24 +00:00
|
|
|
i.updateUrl();
|
2019-04-17 18:30:13 +00:00
|
|
|
i.refetch();
|
|
|
|
}
|
|
|
|
|
2019-10-19 00:20:27 +00:00
|
|
|
prevPage(i: User) {
|
2019-04-17 18:30:13 +00:00
|
|
|
i.state.page--;
|
2019-04-08 05:19:02 +00:00
|
|
|
i.setState(i.state);
|
2019-04-29 00:41:24 +00:00
|
|
|
i.updateUrl();
|
2019-04-17 18:30:13 +00:00
|
|
|
i.refetch();
|
|
|
|
}
|
2019-04-08 05:19:02 +00:00
|
|
|
|
2019-04-17 18:30:13 +00:00
|
|
|
refetch() {
|
2019-04-08 05:19:02 +00:00
|
|
|
let form: GetUserDetailsForm = {
|
2019-04-17 18:30:13 +00:00
|
|
|
user_id: this.state.user_id,
|
2019-04-25 21:52:18 +00:00
|
|
|
username: this.state.username,
|
2019-04-17 18:30:13 +00:00
|
|
|
sort: SortType[this.state.sort],
|
2019-04-20 04:06:25 +00:00
|
|
|
saved_only: this.state.view == View.Saved,
|
2019-04-17 18:30:13 +00:00
|
|
|
page: this.state.page,
|
|
|
|
limit: fetchLimit,
|
2019-04-08 05:19:02 +00:00
|
|
|
};
|
|
|
|
WebSocketService.Instance.getUserDetails(form);
|
|
|
|
}
|
|
|
|
|
2019-10-21 00:49:13 +00:00
|
|
|
handleSortChange(val: SortType) {
|
|
|
|
this.state.sort = val;
|
|
|
|
this.state.page = 1;
|
|
|
|
this.setState(this.state);
|
|
|
|
this.updateUrl();
|
|
|
|
this.refetch();
|
2019-04-17 18:30:13 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
handleViewChange(i: User, event: any) {
|
|
|
|
i.state.view = Number(event.target.value);
|
2019-04-17 18:30:13 +00:00
|
|
|
i.state.page = 1;
|
2019-04-08 05:19:02 +00:00
|
|
|
i.setState(i.state);
|
2019-04-29 00:41:24 +00:00
|
|
|
i.updateUrl();
|
2019-04-17 18:30:13 +00:00
|
|
|
i.refetch();
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 02:52:43 +00:00
|
|
|
handleUserSettingsShowNsfwChange(i: User, event: any) {
|
|
|
|
i.state.userSettingsForm.show_nsfw = event.target.checked;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
setTheme(event.target.value);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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];
|
|
|
|
const imageUploadUrl = `/pictshare/api/upload.php`;
|
|
|
|
const formData = new FormData();
|
|
|
|
formData.append('file', file);
|
|
|
|
|
|
|
|
i.state.avatarLoading = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
|
|
|
|
fetch(imageUploadUrl, {
|
|
|
|
method: 'POST',
|
|
|
|
body: formData,
|
|
|
|
})
|
|
|
|
.then(res => res.json())
|
|
|
|
.then(res => {
|
|
|
|
let url = `${window.location.origin}/pictshare/${res.url}`;
|
|
|
|
if (res.filetype == 'mp4') {
|
|
|
|
url += '/raw';
|
|
|
|
}
|
|
|
|
i.state.userSettingsForm.avatar = url;
|
|
|
|
console.log(url);
|
|
|
|
i.state.avatarLoading = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
i.state.avatarLoading = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
alert(error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
parseMessage(msg: any) {
|
|
|
|
console.log(msg);
|
|
|
|
let op: UserOperation = msgOp(msg);
|
|
|
|
if (msg.error) {
|
2019-08-10 00:14:43 +00:00
|
|
|
alert(i18n.t(msg.error));
|
2019-10-18 04:25:23 +00:00
|
|
|
this.state.deleteAccountLoading = false;
|
2020-01-01 20:46:14 +00:00
|
|
|
this.state.avatarLoading = false;
|
|
|
|
this.state.userSettingsLoading = false;
|
2019-12-29 01:58:01 +00:00
|
|
|
if (msg.error == 'couldnt_find_that_username_or_email') {
|
|
|
|
this.context.router.history.push('/');
|
|
|
|
}
|
2019-10-18 04:25:23 +00:00
|
|
|
this.setState(this.state);
|
2019-04-08 05:19:02 +00:00
|
|
|
return;
|
|
|
|
} else if (op == UserOperation.GetUserDetails) {
|
|
|
|
let res: UserDetailsResponse = msg;
|
|
|
|
this.state.user = res.user;
|
|
|
|
this.state.comments = res.comments;
|
|
|
|
this.state.follows = res.follows;
|
|
|
|
this.state.moderates = res.moderates;
|
|
|
|
this.state.posts = res.posts;
|
2019-10-14 00:36:35 +00:00
|
|
|
this.state.admins = res.admins;
|
2019-04-29 00:41:24 +00:00
|
|
|
this.state.loading = false;
|
2019-08-14 02:52:43 +00:00
|
|
|
if (this.isCurrentUser) {
|
2019-10-19 00:20:27 +00:00
|
|
|
this.state.userSettingsForm.show_nsfw =
|
|
|
|
UserService.Instance.user.show_nsfw;
|
|
|
|
this.state.userSettingsForm.theme = UserService.Instance.user.theme
|
|
|
|
? UserService.Instance.user.theme
|
|
|
|
: 'darkly';
|
2019-10-21 04:21:54 +00:00
|
|
|
this.state.userSettingsForm.default_sort_type =
|
|
|
|
UserService.Instance.user.default_sort_type;
|
|
|
|
this.state.userSettingsForm.default_listing_type =
|
|
|
|
UserService.Instance.user.default_listing_type;
|
2019-12-09 08:24:53 +00:00
|
|
|
this.state.userSettingsForm.lang = UserService.Instance.user.lang;
|
2019-12-29 20:39:48 +00:00
|
|
|
this.state.userSettingsForm.avatar = UserService.Instance.user.avatar;
|
2020-01-01 20:46:14 +00:00
|
|
|
this.state.userSettingsForm.email = this.state.user.email;
|
2020-01-02 21:55:54 +00:00
|
|
|
this.state.userSettingsForm.send_notifications_to_email = this.state.user.send_notifications_to_email;
|
|
|
|
this.state.userSettingsForm.show_avatars =
|
|
|
|
UserService.Instance.user.show_avatars;
|
2019-08-14 02:52:43 +00:00
|
|
|
}
|
2019-06-03 01:35:46 +00:00
|
|
|
document.title = `/u/${this.state.user.name} - ${WebSocketService.Instance.site.name}`;
|
2019-10-19 00:20:27 +00:00
|
|
|
window.scrollTo(0, 0);
|
2019-04-08 05:19:02 +00:00
|
|
|
this.setState(this.state);
|
2019-04-22 18:32:50 +00:00
|
|
|
} else if (op == UserOperation.EditComment) {
|
|
|
|
let res: CommentResponse = msg;
|
|
|
|
|
|
|
|
let found = this.state.comments.find(c => c.id == res.comment.id);
|
|
|
|
found.content = res.comment.content;
|
|
|
|
found.updated = res.comment.updated;
|
|
|
|
found.removed = res.comment.removed;
|
2019-04-29 19:14:54 +00:00
|
|
|
found.deleted = res.comment.deleted;
|
2019-04-22 18:32:50 +00:00
|
|
|
found.upvotes = res.comment.upvotes;
|
|
|
|
found.downvotes = res.comment.downvotes;
|
|
|
|
found.score = res.comment.score;
|
|
|
|
|
|
|
|
this.setState(this.state);
|
|
|
|
} else if (op == UserOperation.CreateComment) {
|
|
|
|
// let res: CommentResponse = msg;
|
2019-08-10 00:14:43 +00:00
|
|
|
alert(i18n.t('reply_sent'));
|
2019-04-22 18:32:50 +00:00
|
|
|
// this.state.comments.unshift(res.comment); // TODO do this right
|
|
|
|
// this.setState(this.state);
|
|
|
|
} else if (op == UserOperation.SaveComment) {
|
|
|
|
let res: CommentResponse = msg;
|
|
|
|
let found = this.state.comments.find(c => c.id == res.comment.id);
|
|
|
|
found.saved = res.comment.saved;
|
|
|
|
this.setState(this.state);
|
|
|
|
} else if (op == UserOperation.CreateCommentLike) {
|
|
|
|
let res: CommentResponse = msg;
|
2019-10-19 00:20:27 +00:00
|
|
|
let found: Comment = this.state.comments.find(
|
|
|
|
c => c.id === res.comment.id
|
|
|
|
);
|
2019-04-22 18:32:50 +00:00
|
|
|
found.score = res.comment.score;
|
|
|
|
found.upvotes = res.comment.upvotes;
|
|
|
|
found.downvotes = res.comment.downvotes;
|
2019-10-19 00:20:27 +00:00
|
|
|
if (res.comment.my_vote !== null) found.my_vote = res.comment.my_vote;
|
2019-04-22 18:32:50 +00:00
|
|
|
this.setState(this.state);
|
2020-01-20 23:39:45 +00:00
|
|
|
} else if (op == UserOperation.CreatePostLike) {
|
|
|
|
let res: CreatePostLikeResponse = msg;
|
|
|
|
let found = this.state.posts.find(c => c.id == res.post.id);
|
|
|
|
found.my_vote = res.post.my_vote;
|
|
|
|
found.score = res.post.score;
|
|
|
|
found.upvotes = res.post.upvotes;
|
|
|
|
found.downvotes = res.post.downvotes;
|
|
|
|
this.setState(this.state);
|
2019-10-14 00:36:35 +00:00
|
|
|
} else if (op == UserOperation.BanUser) {
|
|
|
|
let res: BanUserResponse = msg;
|
2019-10-19 00:20:27 +00:00
|
|
|
this.state.comments
|
|
|
|
.filter(c => c.creator_id == res.user.id)
|
|
|
|
.forEach(c => (c.banned = res.banned));
|
|
|
|
this.state.posts
|
|
|
|
.filter(c => c.creator_id == res.user.id)
|
|
|
|
.forEach(c => (c.banned = res.banned));
|
2019-10-14 00:36:35 +00:00
|
|
|
this.setState(this.state);
|
|
|
|
} else if (op == UserOperation.AddAdmin) {
|
|
|
|
let res: AddAdminResponse = msg;
|
|
|
|
this.state.admins = res.admins;
|
|
|
|
this.setState(this.state);
|
2019-08-14 02:52:43 +00:00
|
|
|
} else if (op == UserOperation.SaveUserSettings) {
|
2019-10-19 00:20:27 +00:00
|
|
|
this.state = this.emptyState;
|
|
|
|
this.state.userSettingsLoading = false;
|
|
|
|
this.setState(this.state);
|
|
|
|
let res: LoginResponse = msg;
|
|
|
|
UserService.Instance.login(res);
|
2019-10-15 22:09:01 +00:00
|
|
|
} else if (op == UserOperation.DeleteAccount) {
|
2019-10-19 00:20:27 +00:00
|
|
|
this.state.deleteAccountLoading = false;
|
|
|
|
this.state.deleteAccountShowConfirm = false;
|
|
|
|
this.setState(this.state);
|
|
|
|
this.context.router.history.push('/');
|
2019-04-22 18:32:50 +00:00
|
|
|
}
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
}
|