2021-02-22 02:39:04 +00:00
|
|
|
import { Component, linkEvent } from "inferno";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2021-07-17 20:42:55 +00:00
|
|
|
CommentResponse,
|
2020-12-24 01:58:27 +00:00
|
|
|
CommentView,
|
|
|
|
CommunityView,
|
2021-07-17 20:42:55 +00:00
|
|
|
GetCommunity,
|
|
|
|
GetPersonDetails,
|
|
|
|
ListCommunities,
|
|
|
|
ListCommunitiesResponse,
|
|
|
|
ListingType,
|
2021-03-15 18:09:31 +00:00
|
|
|
PersonViewSafe,
|
2021-07-17 20:42:55 +00:00
|
|
|
PostResponse,
|
|
|
|
PostView,
|
2021-08-23 20:18:11 +00:00
|
|
|
ResolveObject,
|
|
|
|
ResolveObjectResponse,
|
2020-12-24 01:58:27 +00:00
|
|
|
Search as SearchForm,
|
2020-09-06 16:15:25 +00:00
|
|
|
SearchResponse,
|
|
|
|
SearchType,
|
|
|
|
Site,
|
2021-07-17 20:42:55 +00:00
|
|
|
SortType,
|
|
|
|
UserOperation,
|
2021-02-22 02:39:04 +00:00
|
|
|
} from "lemmy-js-client";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { Subscription } from "rxjs";
|
|
|
|
import { InitialFetchRequest } from "shared/interfaces";
|
|
|
|
import { i18n } from "../i18next";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { WebSocketService } from "../services";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2020-12-24 22:05:57 +00:00
|
|
|
authField,
|
2021-07-17 20:42:55 +00:00
|
|
|
capitalizeFirstLetter,
|
2021-04-23 21:48:31 +00:00
|
|
|
choicesConfig,
|
2021-07-17 20:42:55 +00:00
|
|
|
commentsToFlatNodes,
|
|
|
|
communitySelectName,
|
|
|
|
communityToChoice,
|
|
|
|
createCommentLikeRes,
|
|
|
|
createPostLikeFindRes,
|
2021-04-23 21:48:31 +00:00
|
|
|
debounce,
|
|
|
|
fetchCommunities,
|
2021-07-17 20:42:55 +00:00
|
|
|
fetchLimit,
|
2021-04-23 21:48:31 +00:00
|
|
|
fetchUsers,
|
2021-07-17 20:42:55 +00:00
|
|
|
isBrowser,
|
2021-04-26 20:06:16 +00:00
|
|
|
personSelectName,
|
2021-07-17 20:42:55 +00:00
|
|
|
personToChoice,
|
|
|
|
restoreScrollPosition,
|
|
|
|
routeListingTypeToEnum,
|
|
|
|
routeSearchTypeToEnum,
|
|
|
|
routeSortTypeToEnum,
|
|
|
|
saveScrollPosition,
|
|
|
|
setIsoData,
|
|
|
|
setOptionalAuth,
|
|
|
|
showLocal,
|
|
|
|
toast,
|
|
|
|
wsClient,
|
|
|
|
wsJsonToRes,
|
|
|
|
wsSubscribe,
|
|
|
|
wsUserOp,
|
2021-02-22 02:39:04 +00:00
|
|
|
} from "../utils";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { CommentNodes } from "./comment/comment-nodes";
|
|
|
|
import { HtmlTags } from "./common/html-tags";
|
|
|
|
import { Spinner } from "./common/icon";
|
|
|
|
import { ListingTypeSelect } from "./common/listing-type-select";
|
|
|
|
import { Paginator } from "./common/paginator";
|
|
|
|
import { SortSelect } from "./common/sort-select";
|
|
|
|
import { CommunityLink } from "./community/community-link";
|
|
|
|
import { PersonListing } from "./person/person-listing";
|
|
|
|
import { PostListing } from "./post/post-listing";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2021-07-17 20:42:55 +00:00
|
|
|
var Choices: any;
|
2021-04-23 21:48:31 +00:00
|
|
|
if (isBrowser()) {
|
|
|
|
Choices = require("choices.js");
|
|
|
|
}
|
|
|
|
|
2020-09-09 02:40:36 +00:00
|
|
|
interface SearchProps {
|
2020-09-06 16:15:25 +00:00
|
|
|
q: string;
|
|
|
|
type_: SearchType;
|
|
|
|
sort: SortType;
|
2021-04-23 21:48:31 +00:00
|
|
|
listingType: ListingType;
|
|
|
|
communityId: number;
|
|
|
|
creatorId: number;
|
2020-09-06 16:15:25 +00:00
|
|
|
page: number;
|
|
|
|
}
|
|
|
|
|
2020-09-09 02:40:36 +00:00
|
|
|
interface SearchState {
|
2020-09-06 16:15:25 +00:00
|
|
|
q: string;
|
|
|
|
type_: SearchType;
|
|
|
|
sort: SortType;
|
2021-04-23 21:48:31 +00:00
|
|
|
listingType: ListingType;
|
|
|
|
communityId: number;
|
|
|
|
creatorId: number;
|
2020-09-06 16:15:25 +00:00
|
|
|
page: number;
|
2020-09-09 02:40:36 +00:00
|
|
|
searchResponse: SearchResponse;
|
2021-04-23 21:48:31 +00:00
|
|
|
communities: CommunityView[];
|
|
|
|
creator?: PersonViewSafe;
|
2020-09-09 02:40:36 +00:00
|
|
|
loading: boolean;
|
|
|
|
site: Site;
|
|
|
|
searchText: string;
|
2021-08-23 20:18:11 +00:00
|
|
|
resolveObjectResponse: ResolveObjectResponse;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface UrlParams {
|
|
|
|
q?: string;
|
|
|
|
type_?: SearchType;
|
|
|
|
sort?: SortType;
|
2021-04-23 21:48:31 +00:00
|
|
|
listingType?: ListingType;
|
|
|
|
communityId?: number;
|
|
|
|
creatorId?: number;
|
2020-09-06 16:15:25 +00:00
|
|
|
page?: number;
|
|
|
|
}
|
|
|
|
|
2021-08-23 20:18:11 +00:00
|
|
|
interface Combined {
|
|
|
|
type_: string;
|
|
|
|
data: CommentView | PostView | CommunityView | PersonViewSafe;
|
|
|
|
published: string;
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
export class Search extends Component<any, SearchState> {
|
2020-09-09 02:40:36 +00:00
|
|
|
private isoData = setIsoData(this.context);
|
2021-04-23 21:48:31 +00:00
|
|
|
private communityChoices: any;
|
|
|
|
private creatorChoices: any;
|
2020-09-06 16:15:25 +00:00
|
|
|
private subscription: Subscription;
|
|
|
|
private emptyState: SearchState = {
|
2020-09-09 02:40:36 +00:00
|
|
|
q: Search.getSearchQueryFromProps(this.props.match.params.q),
|
|
|
|
type_: Search.getSearchTypeFromProps(this.props.match.params.type),
|
|
|
|
sort: Search.getSortTypeFromProps(this.props.match.params.sort),
|
2021-04-23 21:48:31 +00:00
|
|
|
listingType: Search.getListingTypeFromProps(
|
|
|
|
this.props.match.params.listing_type
|
|
|
|
),
|
2020-09-09 02:40:36 +00:00
|
|
|
page: Search.getPageFromProps(this.props.match.params.page),
|
|
|
|
searchText: Search.getSearchQueryFromProps(this.props.match.params.q),
|
2021-04-23 21:48:31 +00:00
|
|
|
communityId: Search.getCommunityIdFromProps(
|
|
|
|
this.props.match.params.community_id
|
|
|
|
),
|
|
|
|
creatorId: Search.getCreatorIdFromProps(this.props.match.params.creator_id),
|
2020-09-06 16:15:25 +00:00
|
|
|
searchResponse: {
|
|
|
|
type_: null,
|
|
|
|
posts: [],
|
|
|
|
comments: [],
|
|
|
|
communities: [],
|
|
|
|
users: [],
|
|
|
|
},
|
2021-08-23 20:18:11 +00:00
|
|
|
resolveObjectResponse: {
|
|
|
|
comment: null,
|
|
|
|
post: null,
|
|
|
|
community: null,
|
|
|
|
person: null,
|
|
|
|
},
|
2021-03-25 17:36:09 +00:00
|
|
|
loading: true,
|
2020-12-24 01:58:27 +00:00
|
|
|
site: this.isoData.site_res.site_view.site,
|
2021-04-23 21:48:31 +00:00
|
|
|
communities: [],
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
|
|
|
|
2020-09-09 02:40:36 +00:00
|
|
|
static getSearchQueryFromProps(q: string): string {
|
2021-02-22 02:39:04 +00:00
|
|
|
return decodeURIComponent(q) || "";
|
2020-09-09 02:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static getSearchTypeFromProps(type_: string): SearchType {
|
|
|
|
return type_ ? routeSearchTypeToEnum(type_) : SearchType.All;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2020-09-09 02:40:36 +00:00
|
|
|
static getSortTypeFromProps(sort: string): SortType {
|
|
|
|
return sort ? routeSortTypeToEnum(sort) : SortType.TopAll;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2021-04-23 21:48:31 +00:00
|
|
|
static getListingTypeFromProps(listingType: string): ListingType {
|
|
|
|
return listingType ? routeListingTypeToEnum(listingType) : ListingType.All;
|
|
|
|
}
|
|
|
|
|
|
|
|
static getCommunityIdFromProps(id: string): number {
|
|
|
|
return id ? Number(id) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static getCreatorIdFromProps(id: string): number {
|
|
|
|
return id ? Number(id) : 0;
|
|
|
|
}
|
|
|
|
|
2020-09-09 02:40:36 +00:00
|
|
|
static getPageFromProps(page: string): number {
|
|
|
|
return page ? Number(page) : 1;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = this.emptyState;
|
|
|
|
this.handleSortChange = this.handleSortChange.bind(this);
|
2021-04-23 21:48:31 +00:00
|
|
|
this.handleListingTypeChange = this.handleListingTypeChange.bind(this);
|
2021-07-16 19:40:56 +00:00
|
|
|
this.handlePageChange = this.handlePageChange.bind(this);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2020-09-09 02:40:36 +00:00
|
|
|
this.parseMessage = this.parseMessage.bind(this);
|
|
|
|
this.subscription = wsSubscribe(this.parseMessage);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2020-09-09 02:40:36 +00:00
|
|
|
// Only fetch the data if coming from another route
|
2021-04-23 21:48:31 +00:00
|
|
|
if (this.isoData.path == this.context.router.route.match.url) {
|
|
|
|
let singleOrMultipleCommunities = this.isoData.routeData[0];
|
|
|
|
if (singleOrMultipleCommunities.communities) {
|
|
|
|
this.state.communities = this.isoData.routeData[0].communities;
|
|
|
|
} else {
|
|
|
|
this.state.communities = [this.isoData.routeData[0].community_view];
|
|
|
|
}
|
|
|
|
|
|
|
|
let creator = this.isoData.routeData[1];
|
|
|
|
if (creator?.person_view) {
|
|
|
|
this.state.creator = this.isoData.routeData[1].person_view;
|
|
|
|
}
|
|
|
|
if (this.state.q != "") {
|
|
|
|
this.state.searchResponse = this.isoData.routeData[2];
|
2021-08-23 20:18:11 +00:00
|
|
|
this.state.resolveObjectResponse = this.isoData.routeData[3];
|
2020-09-09 02:40:36 +00:00
|
|
|
this.state.loading = false;
|
|
|
|
} else {
|
|
|
|
this.search();
|
|
|
|
}
|
2021-04-23 21:48:31 +00:00
|
|
|
} else {
|
|
|
|
this.fetchCommunities();
|
|
|
|
this.search();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.subscription.unsubscribe();
|
2021-02-02 18:36:59 +00:00
|
|
|
saveScrollPosition(this.context);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2021-04-23 21:48:31 +00:00
|
|
|
componentDidMount() {
|
|
|
|
this.setupCommunityFilter();
|
|
|
|
this.setupCreatorFilter();
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
static getDerivedStateFromProps(props: any): SearchProps {
|
|
|
|
return {
|
2020-09-09 02:40:36 +00:00
|
|
|
q: Search.getSearchQueryFromProps(props.match.params.q),
|
|
|
|
type_: Search.getSearchTypeFromProps(props.match.params.type),
|
|
|
|
sort: Search.getSortTypeFromProps(props.match.params.sort),
|
2021-04-23 21:48:31 +00:00
|
|
|
listingType: Search.getListingTypeFromProps(
|
|
|
|
props.match.params.listing_type
|
|
|
|
),
|
|
|
|
communityId: Search.getCommunityIdFromProps(
|
|
|
|
props.match.params.community_id
|
|
|
|
),
|
|
|
|
creatorId: Search.getCreatorIdFromProps(props.match.params.creator_id),
|
2020-09-09 02:40:36 +00:00
|
|
|
page: Search.getPageFromProps(props.match.params.page),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-04-23 21:48:31 +00:00
|
|
|
fetchCommunities() {
|
|
|
|
let listCommunitiesForm: ListCommunities = {
|
|
|
|
type_: ListingType.All,
|
|
|
|
sort: SortType.TopAll,
|
|
|
|
limit: fetchLimit,
|
|
|
|
auth: authField(false),
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.listCommunities(listCommunitiesForm)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-12 21:56:46 +00:00
|
|
|
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
2021-02-22 02:39:04 +00:00
|
|
|
let pathSplit = req.path.split("/");
|
2020-09-09 02:40:36 +00:00
|
|
|
let promises: Promise<any>[] = [];
|
|
|
|
|
2021-04-23 21:48:31 +00:00
|
|
|
let communityId = this.getCommunityIdFromProps(pathSplit[11]);
|
|
|
|
if (communityId !== 0) {
|
|
|
|
let getCommunityForm: GetCommunity = {
|
|
|
|
id: communityId,
|
|
|
|
};
|
|
|
|
setOptionalAuth(getCommunityForm, req.auth);
|
|
|
|
promises.push(req.client.getCommunity(getCommunityForm));
|
|
|
|
} else {
|
|
|
|
let listCommunitiesForm: ListCommunities = {
|
|
|
|
type_: ListingType.All,
|
|
|
|
sort: SortType.TopAll,
|
|
|
|
limit: fetchLimit,
|
|
|
|
};
|
|
|
|
setOptionalAuth(listCommunitiesForm, req.auth);
|
|
|
|
promises.push(req.client.listCommunities(listCommunitiesForm));
|
|
|
|
}
|
|
|
|
|
|
|
|
let creatorId = this.getCreatorIdFromProps(pathSplit[13]);
|
|
|
|
if (creatorId !== 0) {
|
|
|
|
let getCreatorForm: GetPersonDetails = {
|
|
|
|
person_id: creatorId,
|
|
|
|
};
|
|
|
|
setOptionalAuth(getCreatorForm, req.auth);
|
|
|
|
promises.push(req.client.getPersonDetails(getCreatorForm));
|
|
|
|
} else {
|
|
|
|
promises.push(Promise.resolve());
|
|
|
|
}
|
|
|
|
|
2020-09-09 02:40:36 +00:00
|
|
|
let form: SearchForm = {
|
|
|
|
q: this.getSearchQueryFromProps(pathSplit[3]),
|
|
|
|
type_: this.getSearchTypeFromProps(pathSplit[5]),
|
|
|
|
sort: this.getSortTypeFromProps(pathSplit[7]),
|
2021-04-23 21:48:31 +00:00
|
|
|
listing_type: this.getListingTypeFromProps(pathSplit[9]),
|
|
|
|
page: this.getPageFromProps(pathSplit[15]),
|
2020-09-09 02:40:36 +00:00
|
|
|
limit: fetchLimit,
|
|
|
|
};
|
2021-04-23 21:48:31 +00:00
|
|
|
if (communityId !== 0) {
|
|
|
|
form.community_id = communityId;
|
|
|
|
}
|
|
|
|
if (creatorId !== 0) {
|
|
|
|
form.creator_id = creatorId;
|
|
|
|
}
|
2020-12-24 22:05:57 +00:00
|
|
|
setOptionalAuth(form, req.auth);
|
2020-09-09 02:40:36 +00:00
|
|
|
|
2021-08-23 20:18:11 +00:00
|
|
|
let resolveObjectForm: ResolveObject = {
|
|
|
|
q: this.getSearchQueryFromProps(pathSplit[3]),
|
|
|
|
};
|
|
|
|
setOptionalAuth(resolveObjectForm, req.auth);
|
|
|
|
|
2021-02-22 02:39:04 +00:00
|
|
|
if (form.q != "") {
|
2020-11-12 21:56:46 +00:00
|
|
|
promises.push(req.client.search(form));
|
2021-08-23 20:18:11 +00:00
|
|
|
promises.push(req.client.resolveObject(resolveObjectForm));
|
2020-09-09 02:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return promises;
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
componentDidUpdate(_: any, lastState: SearchState) {
|
|
|
|
if (
|
|
|
|
lastState.q !== this.state.q ||
|
|
|
|
lastState.type_ !== this.state.type_ ||
|
|
|
|
lastState.sort !== this.state.sort ||
|
2021-04-23 21:48:31 +00:00
|
|
|
lastState.listingType !== this.state.listingType ||
|
|
|
|
lastState.communityId !== this.state.communityId ||
|
|
|
|
lastState.creatorId !== this.state.creatorId ||
|
2020-09-06 16:15:25 +00:00
|
|
|
lastState.page !== this.state.page
|
|
|
|
) {
|
|
|
|
this.setState({ loading: true, searchText: this.state.q });
|
|
|
|
this.search();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get documentTitle(): string {
|
2020-09-11 18:09:21 +00:00
|
|
|
if (this.state.q) {
|
2021-02-22 02:39:04 +00:00
|
|
|
return `${i18n.t("search")} - ${this.state.q} - ${this.state.site.name}`;
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
2021-02-22 02:39:04 +00:00
|
|
|
return `${i18n.t("search")} - ${this.state.site.name}`;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div class="container">
|
2020-09-11 18:09:21 +00:00
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
|
|
|
/>
|
2021-02-22 02:39:04 +00:00
|
|
|
<h5>{i18n.t("search")}</h5>
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.selects()}
|
|
|
|
{this.searchForm()}
|
|
|
|
{this.state.type_ == SearchType.All && this.all()}
|
|
|
|
{this.state.type_ == SearchType.Comments && this.comments()}
|
|
|
|
{this.state.type_ == SearchType.Posts && this.posts()}
|
|
|
|
{this.state.type_ == SearchType.Communities && this.communities()}
|
|
|
|
{this.state.type_ == SearchType.Users && this.users()}
|
2021-05-04 21:31:38 +00:00
|
|
|
{this.state.type_ == SearchType.Url && this.posts()}
|
2021-02-22 02:39:04 +00:00
|
|
|
{this.resultsCount() == 0 && <span>{i18n.t("no_results")}</span>}
|
2021-07-16 19:40:56 +00:00
|
|
|
<Paginator page={this.state.page} onChange={this.handlePageChange} />
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
searchForm() {
|
|
|
|
return (
|
|
|
|
<form
|
|
|
|
class="form-inline"
|
|
|
|
onSubmit={linkEvent(this, this.handleSearchSubmit)}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
class="form-control mr-2 mb-2"
|
|
|
|
value={this.state.searchText}
|
2021-02-22 02:39:04 +00:00
|
|
|
placeholder={`${i18n.t("search")}...`}
|
|
|
|
aria-label={i18n.t("search")}
|
2020-09-06 16:15:25 +00:00
|
|
|
onInput={linkEvent(this, this.handleQChange)}
|
|
|
|
required
|
|
|
|
minLength={3}
|
|
|
|
/>
|
|
|
|
<button type="submit" class="btn btn-secondary mr-2 mb-2">
|
2021-02-22 02:39:04 +00:00
|
|
|
{this.state.loading ? <Spinner /> : <span>{i18n.t("search")}</span>}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
selects() {
|
|
|
|
return (
|
|
|
|
<div className="mb-2">
|
|
|
|
<select
|
|
|
|
value={this.state.type_}
|
|
|
|
onChange={linkEvent(this, this.handleTypeChange)}
|
|
|
|
class="custom-select w-auto mb-2"
|
2021-02-22 02:39:04 +00:00
|
|
|
aria-label={i18n.t("type")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-06 20:20:41 +00:00
|
|
|
<option disabled aria-hidden="true">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("type")}
|
2021-02-06 20:20:41 +00:00
|
|
|
</option>
|
2021-02-22 02:39:04 +00:00
|
|
|
<option value={SearchType.All}>{i18n.t("all")}</option>
|
|
|
|
<option value={SearchType.Comments}>{i18n.t("comments")}</option>
|
|
|
|
<option value={SearchType.Posts}>{i18n.t("posts")}</option>
|
2020-09-06 16:15:25 +00:00
|
|
|
<option value={SearchType.Communities}>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("communities")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</option>
|
2021-02-22 02:39:04 +00:00
|
|
|
<option value={SearchType.Users}>{i18n.t("users")}</option>
|
2021-05-04 21:31:38 +00:00
|
|
|
<option value={SearchType.Url}>{i18n.t("url")}</option>
|
2020-09-06 16:15:25 +00:00
|
|
|
</select>
|
2021-04-23 21:48:31 +00:00
|
|
|
<span class="ml-2">
|
|
|
|
<ListingTypeSelect
|
|
|
|
type_={this.state.listingType}
|
|
|
|
showLocal={showLocal(this.isoData)}
|
|
|
|
onChange={this.handleListingTypeChange}
|
|
|
|
/>
|
|
|
|
</span>
|
2020-09-06 16:15:25 +00:00
|
|
|
<span class="ml-2">
|
|
|
|
<SortSelect
|
|
|
|
sort={this.state.sort}
|
|
|
|
onChange={this.handleSortChange}
|
|
|
|
hideHot
|
2021-02-01 18:48:42 +00:00
|
|
|
hideMostComments
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
</span>
|
2021-04-23 21:48:31 +00:00
|
|
|
<div class="form-row">
|
|
|
|
{this.state.communities.length > 0 && this.communityFilter()}
|
|
|
|
{this.creatorFilter()}
|
|
|
|
</div>
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-23 20:18:11 +00:00
|
|
|
postViewToCombined(postView: PostView): Combined {
|
|
|
|
return {
|
|
|
|
type_: "posts",
|
|
|
|
data: postView,
|
|
|
|
published: postView.post.published,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
commentViewToCombined(commentView: CommentView): Combined {
|
|
|
|
return {
|
|
|
|
type_: "comments",
|
|
|
|
data: commentView,
|
|
|
|
published: commentView.comment.published,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
communityViewToCombined(communityView: CommunityView): Combined {
|
|
|
|
return {
|
|
|
|
type_: "communities",
|
|
|
|
data: communityView,
|
|
|
|
published: communityView.community.published,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
personViewSafeToCombined(personViewSafe: PersonViewSafe): Combined {
|
|
|
|
return {
|
|
|
|
type_: "users",
|
|
|
|
data: personViewSafe,
|
|
|
|
published: personViewSafe.person.published,
|
|
|
|
};
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2021-08-23 20:18:11 +00:00
|
|
|
buildCombined(): Combined[] {
|
|
|
|
let combined: Combined[] = [];
|
|
|
|
|
|
|
|
// Push the possible resolve / federated objects first
|
|
|
|
let resolveComment = this.state.resolveObjectResponse.comment;
|
|
|
|
if (resolveComment) {
|
|
|
|
combined.push(this.commentViewToCombined(resolveComment));
|
|
|
|
}
|
|
|
|
let resolvePost = this.state.resolveObjectResponse.post;
|
|
|
|
if (resolvePost) {
|
|
|
|
combined.push(this.postViewToCombined(resolvePost));
|
|
|
|
}
|
|
|
|
let resolveCommunity = this.state.resolveObjectResponse.community;
|
|
|
|
if (resolveCommunity) {
|
|
|
|
combined.push(this.communityViewToCombined(resolveCommunity));
|
|
|
|
}
|
|
|
|
let resolveUser = this.state.resolveObjectResponse.person;
|
|
|
|
if (resolveUser) {
|
|
|
|
combined.push(this.personViewSafeToCombined(resolveUser));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push the search results
|
|
|
|
combined.push(
|
|
|
|
...this.state.searchResponse.comments.map(e =>
|
|
|
|
this.commentViewToCombined(e)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
combined.push(
|
|
|
|
...this.state.searchResponse.posts.map(e => this.postViewToCombined(e))
|
|
|
|
);
|
|
|
|
combined.push(
|
|
|
|
...this.state.searchResponse.communities.map(e =>
|
|
|
|
this.communityViewToCombined(e)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
combined.push(
|
|
|
|
...this.state.searchResponse.users.map(e =>
|
|
|
|
this.personViewSafeToCombined(e)
|
|
|
|
)
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
// Sort it
|
|
|
|
if (this.state.sort == SortType.New) {
|
2020-12-24 01:58:27 +00:00
|
|
|
combined.sort((a, b) => b.published.localeCompare(a.published));
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
|
|
|
combined.sort(
|
|
|
|
(a, b) =>
|
2020-12-24 01:58:27 +00:00
|
|
|
((b.data as CommentView | PostView).counts.score |
|
|
|
|
(b.data as CommunityView).counts.subscribers |
|
2021-03-15 18:09:31 +00:00
|
|
|
(b.data as PersonViewSafe).counts.comment_score) -
|
2020-12-24 01:58:27 +00:00
|
|
|
((a.data as CommentView | PostView).counts.score |
|
|
|
|
(a.data as CommunityView).counts.subscribers |
|
2021-03-15 18:09:31 +00:00
|
|
|
(a.data as PersonViewSafe).counts.comment_score)
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
}
|
2021-08-23 20:18:11 +00:00
|
|
|
return combined;
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2021-08-23 20:18:11 +00:00
|
|
|
all() {
|
|
|
|
let combined = this.buildCombined();
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{combined.map(i => (
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-12">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i.type_ == "posts" && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<PostListing
|
2020-12-24 01:58:27 +00:00
|
|
|
key={(i.data as PostView).post.id}
|
|
|
|
post_view={i.data as PostView}
|
2020-09-06 16:15:25 +00:00
|
|
|
showCommunity
|
|
|
|
enableDownvotes={this.state.site.enable_downvotes}
|
|
|
|
enableNsfw={this.state.site.enable_nsfw}
|
|
|
|
/>
|
|
|
|
)}
|
2021-02-22 02:39:04 +00:00
|
|
|
{i.type_ == "comments" && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<CommentNodes
|
2020-12-24 01:58:27 +00:00
|
|
|
key={(i.data as CommentView).comment.id}
|
|
|
|
nodes={[{ comment_view: i.data as CommentView }]}
|
2020-09-06 16:15:25 +00:00
|
|
|
locked
|
|
|
|
noIndent
|
|
|
|
enableDownvotes={this.state.site.enable_downvotes}
|
|
|
|
/>
|
|
|
|
)}
|
2021-02-22 02:39:04 +00:00
|
|
|
{i.type_ == "communities" && (
|
2020-12-24 01:58:27 +00:00
|
|
|
<div>{this.communityListing(i.data as CommunityView)}</div>
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
2021-02-22 02:39:04 +00:00
|
|
|
{i.type_ == "users" && (
|
2021-03-15 18:09:31 +00:00
|
|
|
<div>{this.userListing(i.data as PersonViewSafe)}</div>
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
comments() {
|
2021-08-23 20:18:11 +00:00
|
|
|
let comments: CommentView[] = [];
|
|
|
|
|
|
|
|
let resolveComment = this.state.resolveObjectResponse.comment;
|
|
|
|
if (resolveComment) {
|
|
|
|
comments.push(resolveComment);
|
|
|
|
}
|
|
|
|
|
|
|
|
comments.push(...this.state.searchResponse.comments);
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<CommentNodes
|
2021-08-23 20:18:11 +00:00
|
|
|
nodes={commentsToFlatNodes(comments)}
|
2020-09-06 16:15:25 +00:00
|
|
|
locked
|
|
|
|
noIndent
|
|
|
|
enableDownvotes={this.state.site.enable_downvotes}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
posts() {
|
2021-08-23 20:18:11 +00:00
|
|
|
let posts: PostView[] = [];
|
|
|
|
|
|
|
|
let resolvePost = this.state.resolveObjectResponse.post;
|
|
|
|
if (resolvePost) {
|
|
|
|
posts.push(resolvePost);
|
|
|
|
}
|
|
|
|
|
|
|
|
posts.push(...this.state.searchResponse.posts);
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<>
|
2021-08-23 20:18:11 +00:00
|
|
|
{posts.map(post => (
|
2020-09-06 16:15:25 +00:00
|
|
|
<div class="row">
|
|
|
|
<div class="col-12">
|
|
|
|
<PostListing
|
2020-12-24 01:58:27 +00:00
|
|
|
post_view={post}
|
2020-09-06 16:15:25 +00:00
|
|
|
showCommunity
|
|
|
|
enableDownvotes={this.state.site.enable_downvotes}
|
|
|
|
enableNsfw={this.state.site.enable_nsfw}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
communities() {
|
2021-08-23 20:18:11 +00:00
|
|
|
let communities: CommunityView[] = [];
|
|
|
|
|
|
|
|
let resolveCommunity = this.state.resolveObjectResponse.community;
|
|
|
|
if (resolveCommunity) {
|
|
|
|
communities.push(resolveCommunity);
|
|
|
|
}
|
|
|
|
|
|
|
|
communities.push(...this.state.searchResponse.communities);
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<>
|
2021-08-23 20:18:11 +00:00
|
|
|
{communities.map(community => (
|
2020-09-06 16:15:25 +00:00
|
|
|
<div class="row">
|
|
|
|
<div class="col-12">{this.communityListing(community)}</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-23 20:18:11 +00:00
|
|
|
users() {
|
|
|
|
let users: PersonViewSafe[] = [];
|
|
|
|
|
|
|
|
let resolveUser = this.state.resolveObjectResponse.person;
|
|
|
|
if (resolveUser) {
|
|
|
|
users.push(resolveUser);
|
|
|
|
}
|
|
|
|
|
|
|
|
users.push(...this.state.searchResponse.users);
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{users.map(user => (
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-12">{this.userListing(user)}</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
communityListing(community_view: CommunityView) {
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<span>
|
2020-12-24 01:58:27 +00:00
|
|
|
<CommunityLink community={community_view.community} />
|
2020-09-06 16:15:25 +00:00
|
|
|
</span>
|
2021-02-06 20:20:41 +00:00
|
|
|
<span>{` -
|
2021-02-22 02:39:04 +00:00
|
|
|
${i18n.t("number_of_subscribers", {
|
2020-12-24 01:58:27 +00:00
|
|
|
count: community_view.counts.subscribers,
|
2020-09-06 16:15:25 +00:00
|
|
|
})}
|
|
|
|
`}</span>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-15 18:09:31 +00:00
|
|
|
userListing(person_view: PersonViewSafe) {
|
2020-11-18 16:27:50 +00:00
|
|
|
return [
|
|
|
|
<span>
|
2021-03-15 18:09:31 +00:00
|
|
|
<PersonListing person={person_view.person} showApubName />
|
2020-11-18 16:27:50 +00:00
|
|
|
</span>,
|
2021-02-22 02:39:04 +00:00
|
|
|
<span>{` - ${i18n.t("number_of_comments", {
|
2021-03-15 18:09:31 +00:00
|
|
|
count: person_view.counts.comment_count,
|
2020-11-18 16:27:50 +00:00
|
|
|
})}`}</span>,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-04-23 21:48:31 +00:00
|
|
|
communityFilter() {
|
|
|
|
return (
|
|
|
|
<div class="form-group col-sm-6">
|
|
|
|
<label class="col-form-label" htmlFor="community-filter">
|
|
|
|
{i18n.t("community")}
|
|
|
|
</label>
|
|
|
|
<div>
|
|
|
|
<select
|
|
|
|
class="form-control"
|
|
|
|
id="community-filter"
|
|
|
|
value={this.state.communityId}
|
|
|
|
>
|
|
|
|
<option value="0">{i18n.t("all")}</option>
|
|
|
|
{this.state.communities.map(cv => (
|
2021-04-26 20:06:16 +00:00
|
|
|
<option value={cv.community.id}>{communitySelectName(cv)}</option>
|
2021-04-23 21:48:31 +00:00
|
|
|
))}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
creatorFilter() {
|
|
|
|
return (
|
|
|
|
<div class="form-group col-sm-6">
|
|
|
|
<label class="col-form-label" htmlFor="creator-filter">
|
|
|
|
{capitalizeFirstLetter(i18n.t("creator"))}
|
|
|
|
</label>
|
|
|
|
<div>
|
|
|
|
<select
|
|
|
|
class="form-control"
|
|
|
|
id="creator-filter"
|
|
|
|
value={this.state.creatorId}
|
|
|
|
>
|
|
|
|
<option value="0">{i18n.t("all")}</option>
|
|
|
|
{this.state.creator && (
|
|
|
|
<option value={this.state.creator.person.id}>
|
2021-04-26 20:06:16 +00:00
|
|
|
{personSelectName(this.state.creator)}
|
2021-04-23 21:48:31 +00:00
|
|
|
</option>
|
|
|
|
)}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
resultsCount(): number {
|
|
|
|
let res = this.state.searchResponse;
|
2021-08-23 20:18:11 +00:00
|
|
|
let resObj = this.state.resolveObjectResponse;
|
|
|
|
let resObjCount =
|
|
|
|
resObj.post || resObj.person || resObj.community || resObj.comment
|
|
|
|
? 1
|
|
|
|
: 0;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
res.posts.length +
|
|
|
|
res.comments.length +
|
|
|
|
res.communities.length +
|
2021-08-23 20:18:11 +00:00
|
|
|
res.users.length +
|
|
|
|
resObjCount
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-16 19:40:56 +00:00
|
|
|
handlePageChange(page: number) {
|
|
|
|
this.updateUrl({ page });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
search() {
|
|
|
|
let form: SearchForm = {
|
|
|
|
q: this.state.q,
|
|
|
|
type_: this.state.type_,
|
|
|
|
sort: this.state.sort,
|
2021-04-23 21:48:31 +00:00
|
|
|
listing_type: this.state.listingType,
|
2020-09-06 16:15:25 +00:00
|
|
|
page: this.state.page,
|
|
|
|
limit: fetchLimit,
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(false),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
2021-04-23 21:48:31 +00:00
|
|
|
if (this.state.communityId !== 0) {
|
|
|
|
form.community_id = this.state.communityId;
|
|
|
|
}
|
|
|
|
if (this.state.creatorId !== 0) {
|
|
|
|
form.creator_id = this.state.creatorId;
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2021-08-23 20:18:11 +00:00
|
|
|
let resolveObjectForm: ResolveObject = {
|
|
|
|
q: this.state.q,
|
|
|
|
auth: authField(false),
|
|
|
|
};
|
|
|
|
|
2021-02-22 02:39:04 +00:00
|
|
|
if (this.state.q != "") {
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.search(form));
|
2021-08-23 20:18:11 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.resolveObject(resolveObjectForm));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-23 21:48:31 +00:00
|
|
|
setupCommunityFilter() {
|
|
|
|
if (isBrowser()) {
|
|
|
|
let selectId: any = document.getElementById("community-filter");
|
|
|
|
if (selectId) {
|
|
|
|
this.communityChoices = new Choices(selectId, choicesConfig);
|
|
|
|
this.communityChoices.passedElement.element.addEventListener(
|
|
|
|
"choice",
|
|
|
|
(e: any) => {
|
|
|
|
this.handleCommunityFilterChange(Number(e.detail.choice.value));
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
|
|
|
this.communityChoices.passedElement.element.addEventListener(
|
|
|
|
"search",
|
|
|
|
debounce(async (e: any) => {
|
|
|
|
let communities = (await fetchCommunities(e.detail.value))
|
|
|
|
.communities;
|
|
|
|
let choices = communities.map(cv => communityToChoice(cv));
|
|
|
|
choices.unshift({ value: "0", label: i18n.t("all") });
|
|
|
|
this.communityChoices.setChoices(choices, "value", "label", true);
|
|
|
|
}, 400),
|
|
|
|
false
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setupCreatorFilter() {
|
|
|
|
if (isBrowser()) {
|
|
|
|
let selectId: any = document.getElementById("creator-filter");
|
|
|
|
if (selectId) {
|
|
|
|
this.creatorChoices = new Choices(selectId, choicesConfig);
|
|
|
|
this.creatorChoices.passedElement.element.addEventListener(
|
|
|
|
"choice",
|
|
|
|
(e: any) => {
|
|
|
|
this.handleCreatorFilterChange(Number(e.detail.choice.value));
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
|
|
|
this.creatorChoices.passedElement.element.addEventListener(
|
|
|
|
"search",
|
|
|
|
debounce(async (e: any) => {
|
|
|
|
let creators = (await fetchUsers(e.detail.value)).users;
|
|
|
|
let choices = creators.map(pvs => personToChoice(pvs));
|
|
|
|
choices.unshift({ value: "0", label: i18n.t("all") });
|
|
|
|
this.creatorChoices.setChoices(choices, "value", "label", true);
|
|
|
|
}, 400),
|
|
|
|
false
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
handleSortChange(val: SortType) {
|
|
|
|
this.updateUrl({ sort: val, page: 1 });
|
|
|
|
}
|
|
|
|
|
|
|
|
handleTypeChange(i: Search, event: any) {
|
|
|
|
i.updateUrl({
|
|
|
|
type_: SearchType[event.target.value],
|
|
|
|
page: 1,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-23 21:48:31 +00:00
|
|
|
handleListingTypeChange(val: ListingType) {
|
|
|
|
this.updateUrl({
|
|
|
|
listingType: val,
|
|
|
|
page: 1,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCommunityFilterChange(communityId: number) {
|
|
|
|
this.updateUrl({
|
|
|
|
communityId,
|
|
|
|
page: 1,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCreatorFilterChange(creatorId: number) {
|
|
|
|
this.updateUrl({
|
|
|
|
creatorId,
|
|
|
|
page: 1,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
handleSearchSubmit(i: Search, event: any) {
|
|
|
|
event.preventDefault();
|
|
|
|
i.updateUrl({
|
|
|
|
q: i.state.searchText,
|
|
|
|
type_: i.state.type_,
|
2021-04-23 21:48:31 +00:00
|
|
|
listingType: i.state.listingType,
|
|
|
|
communityId: i.state.communityId,
|
|
|
|
creatorId: i.state.creatorId,
|
2020-09-06 16:15:25 +00:00
|
|
|
sort: i.state.sort,
|
|
|
|
page: i.state.page,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleQChange(i: Search, event: any) {
|
|
|
|
i.setState({ searchText: event.target.value });
|
|
|
|
}
|
|
|
|
|
|
|
|
updateUrl(paramUpdates: UrlParams) {
|
|
|
|
const qStr = paramUpdates.q || this.state.q;
|
2020-10-07 10:39:07 +00:00
|
|
|
const qStrEncoded = encodeURIComponent(qStr);
|
2020-09-06 16:15:25 +00:00
|
|
|
const typeStr = paramUpdates.type_ || this.state.type_;
|
2021-04-23 21:48:31 +00:00
|
|
|
const listingTypeStr = paramUpdates.listingType || this.state.listingType;
|
2020-09-06 16:15:25 +00:00
|
|
|
const sortStr = paramUpdates.sort || this.state.sort;
|
2021-04-23 21:48:31 +00:00
|
|
|
const communityId =
|
|
|
|
paramUpdates.communityId == 0
|
|
|
|
? 0
|
|
|
|
: paramUpdates.communityId || this.state.communityId;
|
|
|
|
const creatorId =
|
|
|
|
paramUpdates.creatorId == 0
|
|
|
|
? 0
|
|
|
|
: paramUpdates.creatorId || this.state.creatorId;
|
2020-09-06 16:15:25 +00:00
|
|
|
const page = paramUpdates.page || this.state.page;
|
|
|
|
this.props.history.push(
|
2021-04-23 21:48:31 +00:00
|
|
|
`/search/q/${qStrEncoded}/type/${typeStr}/sort/${sortStr}/listing_type/${listingTypeStr}/community_id/${communityId}/creator_id/${creatorId}/page/${page}`
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
parseMessage(msg: any) {
|
2020-09-06 16:15:25 +00:00
|
|
|
console.log(msg);
|
2020-12-24 01:58:27 +00:00
|
|
|
let op = wsUserOp(msg);
|
2020-09-06 16:15:25 +00:00
|
|
|
if (msg.error) {
|
2021-08-23 20:18:11 +00:00
|
|
|
if (msg.error != "couldnt_find_object") {
|
|
|
|
toast(i18n.t(msg.error), "danger");
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
resolveObjectResponse: {
|
|
|
|
comment: null,
|
|
|
|
community: null,
|
|
|
|
person: null,
|
|
|
|
post: null,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.Search) {
|
|
|
|
let data = wsJsonToRes<SearchResponse>(msg).data;
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.searchResponse = data;
|
|
|
|
this.state.loading = false;
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
this.setState(this.state);
|
2021-02-02 18:36:59 +00:00
|
|
|
restoreScrollPosition(this.context);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.CreateCommentLike) {
|
|
|
|
let data = wsJsonToRes<CommentResponse>(msg).data;
|
|
|
|
createCommentLikeRes(
|
|
|
|
data.comment_view,
|
|
|
|
this.state.searchResponse.comments
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.CreatePostLike) {
|
|
|
|
let data = wsJsonToRes<PostResponse>(msg).data;
|
|
|
|
createPostLikeFindRes(data.post_view, this.state.searchResponse.posts);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2021-04-23 21:48:31 +00:00
|
|
|
} else if (op == UserOperation.ListCommunities) {
|
|
|
|
let data = wsJsonToRes<ListCommunitiesResponse>(msg).data;
|
|
|
|
this.state.communities = data.communities;
|
|
|
|
this.setState(this.state);
|
|
|
|
this.setupCommunityFilter();
|
2021-08-23 20:18:11 +00:00
|
|
|
} else if (op == UserOperation.ResolveObject) {
|
|
|
|
let data = wsJsonToRes<ResolveObjectResponse>(msg).data;
|
|
|
|
this.state.resolveObjectResponse = data;
|
|
|
|
this.setState(this.state);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|