2019-04-21 21:38:57 +00:00
|
|
|
import { Component, linkEvent } from 'inferno';
|
2019-04-05 19:14:54 +00:00
|
|
|
import { Link } from 'inferno-router';
|
2019-10-19 00:20:27 +00:00
|
|
|
import { Subscription } from 'rxjs';
|
2019-04-05 19:14:54 +00:00
|
|
|
import { retryWhen, delay, take } from 'rxjs/operators';
|
2019-10-19 00:20:27 +00:00
|
|
|
import {
|
|
|
|
UserOperation,
|
|
|
|
CommunityUser,
|
|
|
|
GetFollowedCommunitiesResponse,
|
|
|
|
ListCommunitiesForm,
|
|
|
|
ListCommunitiesResponse,
|
|
|
|
Community,
|
|
|
|
SortType,
|
|
|
|
GetSiteResponse,
|
|
|
|
ListingType,
|
2020-02-08 04:05:15 +00:00
|
|
|
DataType,
|
2019-10-19 00:20:27 +00:00
|
|
|
SiteResponse,
|
|
|
|
GetPostsResponse,
|
2020-02-01 01:02:20 +00:00
|
|
|
PostResponse,
|
2019-10-19 00:20:27 +00:00
|
|
|
Post,
|
|
|
|
GetPostsForm,
|
2020-02-08 04:05:15 +00:00
|
|
|
Comment,
|
|
|
|
GetCommentsForm,
|
|
|
|
GetCommentsResponse,
|
|
|
|
CommentResponse,
|
2020-02-01 01:02:20 +00:00
|
|
|
AddAdminResponse,
|
|
|
|
BanUserResponse,
|
2020-01-19 05:38:45 +00:00
|
|
|
WebSocketJsonResponse,
|
2019-10-19 00:20:27 +00:00
|
|
|
} from '../interfaces';
|
2019-04-05 19:14:54 +00:00
|
|
|
import { WebSocketService, UserService } from '../services';
|
|
|
|
import { PostListings } from './post-listings';
|
2020-02-08 04:05:15 +00:00
|
|
|
import { CommentNodes } from './comment-nodes';
|
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';
|
2020-02-08 04:05:15 +00:00
|
|
|
import { DataTypeSelect } from './data-type-select';
|
2019-04-21 21:38:57 +00:00
|
|
|
import { SiteForm } from './site-form';
|
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
|
|
|
repoUrl,
|
|
|
|
mdToHtml,
|
|
|
|
fetchLimit,
|
2019-12-29 20:39:48 +00:00
|
|
|
pictshareAvatarThumbnail,
|
2020-01-02 21:55:54 +00:00
|
|
|
showAvatars,
|
2020-01-23 03:29:11 +00:00
|
|
|
toast,
|
2020-02-08 04:05:15 +00:00
|
|
|
getListingTypeFromProps,
|
|
|
|
getPageFromProps,
|
|
|
|
getSortTypeFromProps,
|
|
|
|
getDataTypeFromProps,
|
2020-02-09 04:20:11 +00:00
|
|
|
editCommentRes,
|
|
|
|
saveCommentRes,
|
|
|
|
createCommentLikeRes,
|
|
|
|
createPostLikeFindRes,
|
|
|
|
editPostFindRes,
|
|
|
|
commentsToFlatNodes,
|
2020-02-09 16:44:24 +00:00
|
|
|
commentSortSortType,
|
2019-10-19 00:20:27 +00:00
|
|
|
} from '../utils';
|
2019-08-10 00:14:43 +00:00
|
|
|
import { i18n } from '../i18next';
|
|
|
|
import { T } from 'inferno-i18next';
|
2019-04-20 19:42:52 +00:00
|
|
|
|
|
|
|
interface MainState {
|
2019-04-05 19:14:54 +00:00
|
|
|
subscribedCommunities: Array<CommunityUser>;
|
2019-04-10 06:19:12 +00:00
|
|
|
trendingCommunities: Array<Community>;
|
2020-02-01 01:02:20 +00:00
|
|
|
siteRes: GetSiteResponse;
|
2019-04-21 21:38:57 +00:00
|
|
|
showEditSite: boolean;
|
2019-04-08 21:46:09 +00:00
|
|
|
loading: boolean;
|
2019-04-29 00:19:04 +00:00
|
|
|
posts: Array<Post>;
|
2020-02-08 04:05:15 +00:00
|
|
|
comments: Array<Comment>;
|
|
|
|
listingType: ListingType;
|
|
|
|
dataType: DataType;
|
2019-04-29 00:19:04 +00:00
|
|
|
sort: SortType;
|
|
|
|
page: number;
|
2019-04-05 19:14:54 +00:00
|
|
|
}
|
|
|
|
|
2019-04-29 00:19:04 +00:00
|
|
|
export class Main extends Component<any, MainState> {
|
2019-04-05 19:14:54 +00:00
|
|
|
private subscription: Subscription;
|
2019-04-20 19:42:52 +00:00
|
|
|
private emptyState: MainState = {
|
2019-04-08 21:46:09 +00:00
|
|
|
subscribedCommunities: [],
|
2019-04-10 06:19:12 +00:00
|
|
|
trendingCommunities: [],
|
2020-02-01 01:02:20 +00:00
|
|
|
siteRes: {
|
2019-04-16 23:04:23 +00:00
|
|
|
site: {
|
|
|
|
id: null,
|
|
|
|
name: null,
|
|
|
|
creator_id: null,
|
|
|
|
creator_name: null,
|
|
|
|
published: null,
|
|
|
|
number_of_users: null,
|
|
|
|
number_of_posts: null,
|
|
|
|
number_of_comments: null,
|
2019-08-29 04:28:06 +00:00
|
|
|
number_of_communities: null,
|
2019-12-29 20:39:48 +00:00
|
|
|
enable_downvotes: null,
|
|
|
|
open_registration: null,
|
|
|
|
enable_nsfw: null,
|
2019-04-16 23:04:23 +00:00
|
|
|
},
|
|
|
|
admins: [],
|
|
|
|
banned: [],
|
2019-09-13 16:09:01 +00:00
|
|
|
online: null,
|
2019-04-16 23:04:23 +00:00
|
|
|
},
|
2019-04-21 21:38:57 +00:00
|
|
|
showEditSite: false,
|
2019-04-29 00:19:04 +00:00
|
|
|
loading: true,
|
|
|
|
posts: [],
|
2020-02-08 04:05:15 +00:00
|
|
|
comments: [],
|
|
|
|
listingType: getListingTypeFromProps(this.props),
|
|
|
|
dataType: getDataTypeFromProps(this.props),
|
|
|
|
sort: getSortTypeFromProps(this.props),
|
|
|
|
page: getPageFromProps(this.props),
|
2019-10-19 00:20:27 +00:00
|
|
|
};
|
2019-04-29 00:19:04 +00:00
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
constructor(props: any, context: any) {
|
2019-04-05 19:14:54 +00:00
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = this.emptyState;
|
2019-06-01 22:12:10 +00:00
|
|
|
this.handleEditCancel = this.handleEditCancel.bind(this);
|
2019-10-21 00:49:13 +00:00
|
|
|
this.handleSortChange = this.handleSortChange.bind(this);
|
2020-02-08 04:05:15 +00:00
|
|
|
this.handleListingTypeChange = this.handleListingTypeChange.bind(this);
|
|
|
|
this.handleDataTypeChange = this.handleDataTypeChange.bind(this);
|
2019-04-05 19:14:54 +00:00
|
|
|
|
|
|
|
this.subscription = WebSocketService.Instance.subject
|
2020-01-15 22:28:59 +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-05 19:14:54 +00:00
|
|
|
() => console.log('complete')
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-05 19:14:54 +00:00
|
|
|
|
2019-04-16 23:04:23 +00:00
|
|
|
WebSocketService.Instance.getSite();
|
|
|
|
|
|
|
|
if (UserService.Instance.user) {
|
2019-04-05 19:14:54 +00:00
|
|
|
WebSocketService.Instance.getFollowedCommunities();
|
|
|
|
}
|
2019-04-10 06:19:12 +00:00
|
|
|
|
|
|
|
let listCommunitiesForm: ListCommunitiesForm = {
|
2019-05-02 05:26:31 +00:00
|
|
|
sort: SortType[SortType.Hot],
|
2019-10-19 00:20:27 +00:00
|
|
|
limit: 6,
|
|
|
|
};
|
2019-04-10 06:19:12 +00:00
|
|
|
|
|
|
|
WebSocketService.Instance.listCommunities(listCommunitiesForm);
|
2019-04-21 21:38:57 +00:00
|
|
|
|
2020-02-08 04:05:15 +00:00
|
|
|
this.fetchData();
|
2019-04-05 19:14:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
|
2019-04-29 00:19:04 +00:00
|
|
|
// Necessary for back button for some reason
|
|
|
|
componentWillReceiveProps(nextProps: any) {
|
2019-10-19 00:20:27 +00:00
|
|
|
if (
|
|
|
|
nextProps.history.action == 'POP' ||
|
|
|
|
nextProps.history.action == 'PUSH'
|
|
|
|
) {
|
2020-02-08 04:05:15 +00:00
|
|
|
this.state.listingType = getListingTypeFromProps(nextProps);
|
|
|
|
this.state.dataType = getDataTypeFromProps(nextProps);
|
|
|
|
this.state.sort = getSortTypeFromProps(nextProps);
|
|
|
|
this.state.page = getPageFromProps(nextProps);
|
2019-09-06 01:34:10 +00:00
|
|
|
this.setState(this.state);
|
2020-02-08 04:05:15 +00:00
|
|
|
this.fetchData();
|
2019-04-29 00:19:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-05 19:14:54 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div class="container">
|
|
|
|
<div class="row">
|
2020-02-02 18:50:44 +00:00
|
|
|
<main role="main" class="col-12 col-md-8">
|
|
|
|
{this.posts()}
|
|
|
|
</main>
|
2020-01-31 20:52:27 +00:00
|
|
|
<aside class="col-12 col-md-4">{this.my_sidebar()}</aside>
|
2019-08-10 00:14:43 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-08-10 00:14:43 +00:00
|
|
|
}
|
2019-10-19 00:20:27 +00:00
|
|
|
|
2019-08-10 00:14:43 +00:00
|
|
|
my_sidebar() {
|
2019-10-19 00:20:27 +00:00
|
|
|
return (
|
2019-08-10 00:14:43 +00:00
|
|
|
<div>
|
2019-10-19 00:20:27 +00:00
|
|
|
{!this.state.loading && (
|
2019-08-10 00:14:43 +00:00
|
|
|
<div>
|
2019-08-20 02:37:32 +00:00
|
|
|
<div class="card border-secondary mb-3">
|
|
|
|
<div class="card-body">
|
|
|
|
{this.trendingCommunities()}
|
2019-10-19 00:20:27 +00:00
|
|
|
{UserService.Instance.user &&
|
|
|
|
this.state.subscribedCommunities.length > 0 && (
|
|
|
|
<div>
|
|
|
|
<h5>
|
|
|
|
<T i18nKey="subscribed_to_communities">
|
|
|
|
#
|
|
|
|
<Link class="text-white" to="/communities">
|
|
|
|
#
|
|
|
|
</Link>
|
|
|
|
</T>
|
|
|
|
</h5>
|
|
|
|
<ul class="list-inline">
|
|
|
|
{this.state.subscribedCommunities.map(community => (
|
|
|
|
<li class="list-inline-item">
|
|
|
|
<Link to={`/c/${community.community_name}`}>
|
|
|
|
{community.community_name}
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<Link
|
|
|
|
class="btn btn-sm btn-secondary btn-block"
|
|
|
|
to="/create_community"
|
|
|
|
>
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('create_a_community')}
|
2019-08-20 02:37:32 +00:00
|
|
|
</Link>
|
2019-04-29 00:19:04 +00:00
|
|
|
</div>
|
2019-08-10 00:14:43 +00:00
|
|
|
</div>
|
2019-08-20 02:37:32 +00:00
|
|
|
{this.sidebar()}
|
|
|
|
{this.landing()}
|
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
2019-04-05 19:14:54 +00:00
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-05 19:14:54 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 06:19:12 +00:00
|
|
|
trendingCommunities() {
|
|
|
|
return (
|
|
|
|
<div>
|
2019-08-10 00:14:43 +00:00
|
|
|
<h5>
|
2019-10-19 00:20:27 +00:00
|
|
|
<T i18nKey="trending_communities">
|
|
|
|
#
|
|
|
|
<Link class="text-white" to="/communities">
|
|
|
|
#
|
|
|
|
</Link>
|
|
|
|
</T>
|
2019-08-10 00:14:43 +00:00
|
|
|
</h5>
|
2019-10-19 00:20:27 +00:00
|
|
|
<ul class="list-inline">
|
|
|
|
{this.state.trendingCommunities.map(community => (
|
|
|
|
<li class="list-inline-item">
|
|
|
|
<Link to={`/c/${community.name}`}>{community.name}</Link>
|
|
|
|
</li>
|
|
|
|
))}
|
2019-04-10 06:19:12 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-10 06:19:12 +00:00
|
|
|
}
|
|
|
|
|
2019-04-21 21:38:57 +00:00
|
|
|
sidebar() {
|
2019-04-09 21:21:19 +00:00
|
|
|
return (
|
2019-08-20 04:45:06 +00:00
|
|
|
<div>
|
2019-10-19 00:20:27 +00:00
|
|
|
{!this.state.showEditSite ? (
|
|
|
|
this.siteInfo()
|
|
|
|
) : (
|
2019-08-20 04:45:06 +00:00
|
|
|
<SiteForm
|
2020-02-01 01:02:20 +00:00
|
|
|
site={this.state.siteRes.site}
|
2019-10-19 00:20:27 +00:00
|
|
|
onCancel={this.handleEditCancel}
|
2019-08-20 04:45:06 +00:00
|
|
|
/>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
2019-04-21 21:38:57 +00:00
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-21 21:38:57 +00:00
|
|
|
}
|
|
|
|
|
2019-04-29 00:19:04 +00:00
|
|
|
updateUrl() {
|
2020-02-08 04:05:15 +00:00
|
|
|
let listingTypeStr = ListingType[this.state.listingType].toLowerCase();
|
|
|
|
let dataTypeStr = DataType[this.state.dataType].toLowerCase();
|
2019-04-29 00:19:04 +00:00
|
|
|
let sortStr = SortType[this.state.sort].toLowerCase();
|
2019-10-19 00:20:27 +00:00
|
|
|
this.props.history.push(
|
2020-02-08 04:05:15 +00:00
|
|
|
`/home/data_type/${dataTypeStr}/listing_type/${listingTypeStr}/sort/${sortStr}/page/${this.state.page}`
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-29 00:19:04 +00:00
|
|
|
}
|
|
|
|
|
2019-04-21 21:38:57 +00:00
|
|
|
siteInfo() {
|
|
|
|
return (
|
|
|
|
<div>
|
2019-08-20 04:45:06 +00:00
|
|
|
<div class="card border-secondary mb-3">
|
|
|
|
<div class="card-body">
|
2020-02-01 01:02:20 +00:00
|
|
|
<h5 class="mb-0">{`${this.state.siteRes.site.name}`}</h5>
|
2019-10-19 00:20:27 +00:00
|
|
|
{this.canAdmin && (
|
|
|
|
<ul class="list-inline mb-1 text-muted small font-weight-bold">
|
2019-08-20 04:45:06 +00:00
|
|
|
<li className="list-inline-item">
|
2019-10-19 00:20:27 +00:00
|
|
|
<span
|
|
|
|
class="pointer"
|
|
|
|
onClick={linkEvent(this, this.handleEditClick)}
|
|
|
|
>
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('edit')}
|
2019-08-20 04:45:06 +00:00
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
2019-08-20 04:45:06 +00:00
|
|
|
<ul class="my-2 list-inline">
|
2019-09-13 16:09:01 +00:00
|
|
|
<li className="list-inline-item badge badge-secondary">
|
2020-02-02 19:37:19 +00:00
|
|
|
{i18n.t('number_online', { count: this.state.siteRes.online })}
|
2019-09-13 16:09:01 +00:00
|
|
|
</li>
|
2019-08-20 04:45:06 +00:00
|
|
|
<li className="list-inline-item badge badge-secondary">
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('number_of_users', {
|
2020-02-02 19:37:19 +00:00
|
|
|
count: this.state.siteRes.site.number_of_users,
|
2020-02-02 18:50:44 +00:00
|
|
|
})}
|
2019-08-20 04:45:06 +00:00
|
|
|
</li>
|
2019-08-29 04:28:06 +00:00
|
|
|
<li className="list-inline-item badge badge-secondary">
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('number_of_communities', {
|
2020-02-02 19:37:19 +00:00
|
|
|
count: this.state.siteRes.site.number_of_communities,
|
2020-02-02 18:50:44 +00:00
|
|
|
})}
|
2019-08-29 04:28:06 +00:00
|
|
|
</li>
|
2019-08-20 04:45:06 +00:00
|
|
|
<li className="list-inline-item badge badge-secondary">
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('number_of_posts', {
|
2020-02-02 19:37:19 +00:00
|
|
|
count: this.state.siteRes.site.number_of_posts,
|
2020-02-02 18:50:44 +00:00
|
|
|
})}
|
2019-08-20 04:45:06 +00:00
|
|
|
</li>
|
|
|
|
<li className="list-inline-item badge badge-secondary">
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('number_of_comments', {
|
2020-02-02 19:37:19 +00:00
|
|
|
count: this.state.siteRes.site.number_of_comments,
|
2020-02-02 18:50:44 +00:00
|
|
|
})}
|
2019-08-20 04:45:06 +00:00
|
|
|
</li>
|
|
|
|
<li className="list-inline-item">
|
|
|
|
<Link className="badge badge-secondary" to="/modlog">
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('modlog')}
|
2019-08-20 04:45:06 +00:00
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2019-10-19 00:20:27 +00:00
|
|
|
<ul class="mt-1 list-inline small mb-0">
|
2020-02-02 18:50:44 +00:00
|
|
|
<li class="list-inline-item">{i18n.t('admins')}:</li>
|
2020-02-01 01:02:20 +00:00
|
|
|
{this.state.siteRes.admins.map(admin => (
|
2019-10-19 00:20:27 +00:00
|
|
|
<li class="list-inline-item">
|
|
|
|
<Link class="text-info" to={`/u/${admin.name}`}>
|
2020-01-02 21:55:54 +00:00
|
|
|
{admin.avatar && showAvatars() && (
|
2019-12-29 20:39:48 +00:00
|
|
|
<img
|
|
|
|
height="32"
|
|
|
|
width="32"
|
|
|
|
src={pictshareAvatarThumbnail(admin.avatar)}
|
|
|
|
class="rounded-circle mr-1"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<span>{admin.name}</span>
|
2019-10-19 00:20:27 +00:00
|
|
|
</Link>
|
2019-08-20 04:45:06 +00:00
|
|
|
</li>
|
2019-10-19 00:20:27 +00:00
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-02-01 01:02:20 +00:00
|
|
|
{this.state.siteRes.site.description && (
|
2019-10-19 00:20:27 +00:00
|
|
|
<div class="card border-secondary mb-3">
|
|
|
|
<div class="card-body">
|
|
|
|
<div
|
|
|
|
className="md-div"
|
|
|
|
dangerouslySetInnerHTML={mdToHtml(
|
2020-02-01 01:02:20 +00:00
|
|
|
this.state.siteRes.site.description
|
2019-08-20 04:45:06 +00:00
|
|
|
)}
|
2019-10-19 00:20:27 +00:00
|
|
|
/>
|
2019-08-20 04:45:06 +00:00
|
|
|
</div>
|
2019-04-16 23:04:23 +00:00
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
2019-04-21 21:38:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
landing() {
|
|
|
|
return (
|
2019-08-20 02:37:32 +00:00
|
|
|
<div class="card border-secondary">
|
|
|
|
<div class="card-body">
|
|
|
|
<h5>
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('powered_by')}
|
2019-10-19 00:20:27 +00:00
|
|
|
<svg class="icon mx-2">
|
|
|
|
<use xlinkHref="#icon-mouse">#</use>
|
|
|
|
</svg>
|
|
|
|
<a href={repoUrl}>
|
|
|
|
Lemmy<sup>beta</sup>
|
|
|
|
</a>
|
2019-08-20 02:37:32 +00:00
|
|
|
</h5>
|
2019-08-20 04:45:06 +00:00
|
|
|
<p class="mb-0">
|
2019-10-19 00:20:27 +00:00
|
|
|
<T i18nKey="landing_0">
|
|
|
|
#
|
|
|
|
<a href="https://en.wikipedia.org/wiki/Social_network_aggregation">
|
|
|
|
#
|
|
|
|
</a>
|
|
|
|
<a href="https://en.wikipedia.org/wiki/Fediverse">#</a>
|
|
|
|
<br></br>
|
|
|
|
<code>#</code>
|
|
|
|
<br></br>
|
|
|
|
<b>#</b>
|
|
|
|
<br></br>
|
|
|
|
<a href={repoUrl}>#</a>
|
|
|
|
<br></br>
|
|
|
|
<a href="https://www.rust-lang.org">#</a>
|
|
|
|
<a href="https://actix.rs/">#</a>
|
|
|
|
<a href="https://infernojs.org">#</a>
|
|
|
|
<a href="https://www.typescriptlang.org/">#</a>
|
|
|
|
</T>
|
|
|
|
</p>
|
|
|
|
</div>
|
2019-04-09 21:21:19 +00:00
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-29 00:19:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
posts() {
|
|
|
|
return (
|
2020-01-31 20:52:27 +00:00
|
|
|
<div class="main-content-wrapper">
|
2020-02-16 01:29:57 +00:00
|
|
|
{this.selects()}
|
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>
|
2020-02-08 04:05:15 +00:00
|
|
|
{this.listings()}
|
2019-10-19 00:20:27 +00:00
|
|
|
{this.paginator()}
|
|
|
|
</div>
|
|
|
|
)}
|
2019-04-29 00:19:04 +00:00
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-29 00:19:04 +00:00
|
|
|
}
|
|
|
|
|
2020-02-08 04:05:15 +00:00
|
|
|
listings() {
|
|
|
|
return this.state.dataType == DataType.Post ? (
|
2020-02-09 16:44:24 +00:00
|
|
|
<PostListings
|
|
|
|
posts={this.state.posts}
|
|
|
|
showCommunity
|
|
|
|
removeDuplicates
|
|
|
|
sort={this.state.sort}
|
|
|
|
/>
|
2020-02-08 04:05:15 +00:00
|
|
|
) : (
|
2020-02-09 04:20:11 +00:00
|
|
|
<CommentNodes
|
|
|
|
nodes={commentsToFlatNodes(this.state.comments)}
|
|
|
|
noIndent
|
|
|
|
showCommunity
|
2020-02-09 16:44:24 +00:00
|
|
|
sortType={this.state.sort}
|
2020-02-09 04:20:11 +00:00
|
|
|
/>
|
2020-02-08 04:05:15 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-29 00:19:04 +00:00
|
|
|
selects() {
|
|
|
|
return (
|
2019-08-20 02:37:32 +00:00
|
|
|
<div className="mb-3">
|
2020-02-08 04:05:15 +00:00
|
|
|
<DataTypeSelect
|
|
|
|
type_={this.state.dataType}
|
|
|
|
onChange={this.handleDataTypeChange}
|
2019-10-21 04:21:54 +00:00
|
|
|
/>
|
2020-02-16 01:29:57 +00:00
|
|
|
<span class="mx-3">
|
2020-02-08 04:05:15 +00:00
|
|
|
<ListingTypeSelect
|
|
|
|
type_={this.state.listingType}
|
|
|
|
onChange={this.handleListingTypeChange}
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
<span class="mr-2">
|
2019-10-21 00:49:13 +00:00
|
|
|
<SortSelect sort={this.state.sort} onChange={this.handleSortChange} />
|
|
|
|
</span>
|
2020-02-08 04:05:15 +00:00
|
|
|
{this.state.listingType == ListingType.All && (
|
2019-12-02 06:20:01 +00:00
|
|
|
<a
|
|
|
|
href={`/feeds/all.xml?sort=${SortType[this.state.sort]}`}
|
|
|
|
target="_blank"
|
|
|
|
>
|
2019-12-02 01:21:19 +00:00
|
|
|
<svg class="icon mx-1 text-muted small">
|
|
|
|
<use xlinkHref="#icon-rss">#</use>
|
|
|
|
</svg>
|
|
|
|
</a>
|
|
|
|
)}
|
2019-12-08 00:39:43 +00:00
|
|
|
{UserService.Instance.user &&
|
2020-02-08 04:05:15 +00:00
|
|
|
this.state.listingType == ListingType.Subscribed && (
|
2019-12-08 00:39:43 +00:00
|
|
|
<a
|
|
|
|
href={`/feeds/front/${UserService.Instance.auth}.xml?sort=${
|
|
|
|
SortType[this.state.sort]
|
|
|
|
}`}
|
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
<svg class="icon mx-1 text-muted small">
|
|
|
|
<use xlinkHref="#icon-rss">#</use>
|
|
|
|
</svg>
|
|
|
|
</a>
|
|
|
|
)}
|
2019-04-29 00:19:04 +00:00
|
|
|
</div>
|
2019-10-19 00:20:27 +00:00
|
|
|
);
|
2019-04-09 21:21:19 +00:00
|
|
|
}
|
2019-04-05 19:14:54 +00:00
|
|
|
|
2019-04-29 00:19:04 +00:00
|
|
|
paginator() {
|
|
|
|
return (
|
2019-08-18 05:00:11 +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)}
|
|
|
|
>
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('prev')}
|
2019-10-19 00:20:27 +00:00
|
|
|
</button>
|
|
|
|
)}
|
2020-01-19 21:47:54 +00:00
|
|
|
{this.state.posts.length == fetchLimit && (
|
|
|
|
<button
|
|
|
|
class="btn btn-sm btn-secondary"
|
|
|
|
onClick={linkEvent(this, this.nextPage)}
|
|
|
|
>
|
2020-02-02 18:50:44 +00:00
|
|
|
{i18n.t('next')}
|
2020-01-19 21:47:54 +00:00
|
|
|
</button>
|
|
|
|
)}
|
2019-04-29 00:19:04 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-21 21:38:57 +00:00
|
|
|
get canAdmin(): boolean {
|
2019-10-19 00:20:27 +00:00
|
|
|
return (
|
|
|
|
UserService.Instance.user &&
|
2020-02-01 01:02:20 +00:00
|
|
|
this.state.siteRes.admins
|
2019-10-19 00:20:27 +00:00
|
|
|
.map(a => a.id)
|
|
|
|
.includes(UserService.Instance.user.id)
|
|
|
|
);
|
2019-04-21 21:38:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleEditClick(i: Main) {
|
|
|
|
i.state.showEditSite = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEditCancel() {
|
|
|
|
this.state.showEditSite = false;
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
|
2019-10-19 00:20:27 +00:00
|
|
|
nextPage(i: Main) {
|
2019-04-29 00:19:04 +00:00
|
|
|
i.state.page++;
|
2019-08-29 23:49:58 +00:00
|
|
|
i.state.loading = true;
|
2019-04-29 00:19:04 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
i.updateUrl();
|
2020-02-08 04:05:15 +00:00
|
|
|
i.fetchData();
|
2019-10-19 00:20:27 +00:00
|
|
|
window.scrollTo(0, 0);
|
2019-04-29 00:19:04 +00:00
|
|
|
}
|
|
|
|
|
2019-10-19 00:20:27 +00:00
|
|
|
prevPage(i: Main) {
|
2019-04-29 00:19:04 +00:00
|
|
|
i.state.page--;
|
2019-08-29 23:49:58 +00:00
|
|
|
i.state.loading = true;
|
2019-04-29 00:19:04 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
i.updateUrl();
|
2020-02-08 04:05:15 +00:00
|
|
|
i.fetchData();
|
2019-10-19 00:20:27 +00:00
|
|
|
window.scrollTo(0, 0);
|
2019-04-29 00:19:04 +00:00
|
|
|
}
|
|
|
|
|
2019-10-21 00:49:13 +00:00
|
|
|
handleSortChange(val: SortType) {
|
|
|
|
this.state.sort = val;
|
|
|
|
this.state.page = 1;
|
|
|
|
this.state.loading = true;
|
|
|
|
this.setState(this.state);
|
|
|
|
this.updateUrl();
|
2020-02-08 04:05:15 +00:00
|
|
|
this.fetchData();
|
2019-10-19 00:20:27 +00:00
|
|
|
window.scrollTo(0, 0);
|
2019-04-29 00:19:04 +00:00
|
|
|
}
|
|
|
|
|
2020-02-08 04:05:15 +00:00
|
|
|
handleListingTypeChange(val: ListingType) {
|
|
|
|
this.state.listingType = val;
|
2019-10-21 04:21:54 +00:00
|
|
|
this.state.page = 1;
|
|
|
|
this.state.loading = true;
|
|
|
|
this.setState(this.state);
|
|
|
|
this.updateUrl();
|
2020-02-08 04:05:15 +00:00
|
|
|
this.fetchData();
|
2019-10-19 00:20:27 +00:00
|
|
|
window.scrollTo(0, 0);
|
2019-10-13 19:37:10 +00:00
|
|
|
}
|
|
|
|
|
2020-02-08 04:05:15 +00:00
|
|
|
handleDataTypeChange(val: DataType) {
|
|
|
|
this.state.dataType = val;
|
|
|
|
this.state.page = 1;
|
|
|
|
this.state.loading = true;
|
|
|
|
this.setState(this.state);
|
|
|
|
this.updateUrl();
|
|
|
|
this.fetchData();
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchData() {
|
|
|
|
if (this.state.dataType == DataType.Post) {
|
|
|
|
let getPostsForm: GetPostsForm = {
|
|
|
|
page: this.state.page,
|
|
|
|
limit: fetchLimit,
|
|
|
|
sort: SortType[this.state.sort],
|
|
|
|
type_: ListingType[this.state.listingType],
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.getPosts(getPostsForm);
|
|
|
|
} else {
|
|
|
|
let getCommentsForm: GetCommentsForm = {
|
|
|
|
page: this.state.page,
|
|
|
|
limit: fetchLimit,
|
|
|
|
sort: SortType[this.state.sort],
|
|
|
|
type_: ListingType[this.state.listingType],
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.getComments(getCommentsForm);
|
|
|
|
}
|
2019-04-29 00:19:04 +00:00
|
|
|
}
|
|
|
|
|
2020-01-19 05:38:45 +00:00
|
|
|
parseMessage(msg: WebSocketJsonResponse) {
|
2019-04-05 19:14:54 +00:00
|
|
|
console.log(msg);
|
2020-01-19 04:54:10 +00:00
|
|
|
let 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');
|
2019-04-05 19:14:54 +00:00
|
|
|
return;
|
2020-02-04 16:19:05 +00:00
|
|
|
} else if (msg.reconnect) {
|
2020-02-08 04:05:15 +00:00
|
|
|
this.fetchData();
|
2020-01-19 04:54:10 +00:00
|
|
|
} else if (res.op == UserOperation.GetFollowedCommunities) {
|
|
|
|
let data = res.data as GetFollowedCommunitiesResponse;
|
|
|
|
this.state.subscribedCommunities = data.communities;
|
2019-04-05 19:14:54 +00:00
|
|
|
this.setState(this.state);
|
2020-01-19 04:54:10 +00:00
|
|
|
} else if (res.op == UserOperation.ListCommunities) {
|
|
|
|
let data = res.data as ListCommunitiesResponse;
|
|
|
|
this.state.trendingCommunities = data.communities;
|
2019-04-10 06:19:12 +00:00
|
|
|
this.setState(this.state);
|
2020-01-19 04:54:10 +00:00
|
|
|
} else if (res.op == UserOperation.GetSite) {
|
|
|
|
let data = res.data as GetSiteResponse;
|
2019-04-16 23:04:23 +00:00
|
|
|
|
|
|
|
// This means it hasn't been set up yet
|
2020-01-19 04:54:10 +00:00
|
|
|
if (!data.site) {
|
2019-10-19 00:20:27 +00:00
|
|
|
this.context.router.history.push('/setup');
|
2019-04-16 23:04:23 +00:00
|
|
|
}
|
2020-02-01 01:02:20 +00:00
|
|
|
this.state.siteRes.admins = data.admins;
|
|
|
|
this.state.siteRes.site = data.site;
|
|
|
|
this.state.siteRes.banned = data.banned;
|
|
|
|
this.state.siteRes.online = data.online;
|
2019-04-16 23:04:23 +00:00
|
|
|
this.setState(this.state);
|
2019-06-03 01:35:46 +00:00
|
|
|
document.title = `${WebSocketService.Instance.site.name}`;
|
2020-01-19 04:54:10 +00:00
|
|
|
} else if (res.op == UserOperation.EditSite) {
|
|
|
|
let data = res.data as SiteResponse;
|
2020-02-01 01:02:20 +00:00
|
|
|
this.state.siteRes.site = data.site;
|
2019-04-21 21:38:57 +00:00
|
|
|
this.state.showEditSite = false;
|
|
|
|
this.setState(this.state);
|
2020-01-19 04:54:10 +00:00
|
|
|
} else if (res.op == UserOperation.GetPosts) {
|
|
|
|
let data = res.data as GetPostsResponse;
|
|
|
|
this.state.posts = data.posts;
|
2019-04-29 00:19:04 +00:00
|
|
|
this.state.loading = false;
|
2020-02-01 01:02:20 +00:00
|
|
|
this.setState(this.state);
|
|
|
|
} else if (res.op == UserOperation.CreatePost) {
|
|
|
|
let data = res.data as PostResponse;
|
|
|
|
|
|
|
|
// If you're on subscribed, only push it if you're subscribed.
|
2020-02-08 04:05:15 +00:00
|
|
|
if (this.state.listingType == ListingType.Subscribed) {
|
2020-02-01 01:02:20 +00:00
|
|
|
if (
|
|
|
|
this.state.subscribedCommunities
|
|
|
|
.map(c => c.community_id)
|
|
|
|
.includes(data.post.community_id)
|
|
|
|
) {
|
|
|
|
this.state.posts.unshift(data.post);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.state.posts.unshift(data.post);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState(this.state);
|
|
|
|
} else if (res.op == UserOperation.EditPost) {
|
|
|
|
let data = res.data as PostResponse;
|
2020-02-09 04:20:11 +00:00
|
|
|
editPostFindRes(data, this.state.posts);
|
|
|
|
this.setState(this.state);
|
2020-01-19 04:54:10 +00:00
|
|
|
} else if (res.op == UserOperation.CreatePostLike) {
|
2020-02-02 17:45:41 +00:00
|
|
|
let data = res.data as PostResponse;
|
2020-02-09 04:20:11 +00:00
|
|
|
createPostLikeFindRes(data, this.state.posts);
|
|
|
|
this.setState(this.state);
|
2020-02-01 01:02:20 +00:00
|
|
|
} else if (res.op == UserOperation.AddAdmin) {
|
|
|
|
let data = res.data as AddAdminResponse;
|
|
|
|
this.state.siteRes.admins = data.admins;
|
|
|
|
this.setState(this.state);
|
|
|
|
} else if (res.op == UserOperation.BanUser) {
|
|
|
|
let data = res.data as BanUserResponse;
|
|
|
|
let found = this.state.siteRes.banned.find(u => (u.id = data.user.id));
|
|
|
|
|
|
|
|
// Remove the banned if its found in the list, and the action is an unban
|
|
|
|
if (found && !data.banned) {
|
|
|
|
this.state.siteRes.banned = this.state.siteRes.banned.filter(
|
|
|
|
i => i.id !== data.user.id
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.state.siteRes.banned.push(data.user);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.state.posts
|
|
|
|
.filter(p => p.creator_id == data.user.id)
|
|
|
|
.forEach(p => (p.banned = data.banned));
|
|
|
|
|
2019-04-29 00:19:04 +00:00
|
|
|
this.setState(this.state);
|
2020-02-08 04:05:15 +00:00
|
|
|
} else if (res.op == UserOperation.GetComments) {
|
|
|
|
let data = res.data as GetCommentsResponse;
|
|
|
|
this.state.comments = data.comments;
|
|
|
|
this.state.loading = false;
|
|
|
|
this.setState(this.state);
|
|
|
|
} else if (res.op == UserOperation.EditComment) {
|
|
|
|
let data = res.data as CommentResponse;
|
2020-02-09 04:20:11 +00:00
|
|
|
editCommentRes(data, this.state.comments);
|
|
|
|
this.setState(this.state);
|
2020-02-08 04:05:15 +00:00
|
|
|
} else if (res.op == UserOperation.CreateComment) {
|
|
|
|
let data = res.data as CommentResponse;
|
|
|
|
|
|
|
|
// Necessary since it might be a user reply
|
|
|
|
if (data.recipient_ids.length == 0) {
|
|
|
|
// If you're on subscribed, only push it if you're subscribed.
|
|
|
|
if (this.state.listingType == ListingType.Subscribed) {
|
|
|
|
if (
|
|
|
|
this.state.subscribedCommunities
|
|
|
|
.map(c => c.community_id)
|
|
|
|
.includes(data.comment.community_id)
|
|
|
|
) {
|
|
|
|
this.state.comments.unshift(data.comment);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.state.comments.unshift(data.comment);
|
|
|
|
}
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
} else if (res.op == UserOperation.SaveComment) {
|
|
|
|
let data = res.data as CommentResponse;
|
2020-02-09 04:20:11 +00:00
|
|
|
saveCommentRes(data, this.state.comments);
|
2020-02-08 04:05:15 +00:00
|
|
|
this.setState(this.state);
|
|
|
|
} else if (res.op == UserOperation.CreateCommentLike) {
|
|
|
|
let data = res.data as CommentResponse;
|
2020-02-09 04:20:11 +00:00
|
|
|
createCommentLikeRes(data, this.state.comments);
|
2020-02-08 04:05:15 +00:00
|
|
|
this.setState(this.state);
|
2019-04-21 21:38:57 +00:00
|
|
|
}
|
2019-04-05 19:14:54 +00:00
|
|
|
}
|
|
|
|
}
|