diff --git a/src/shared/components/communities.tsx b/src/shared/components/communities.tsx index c52c4d32..efb92f94 100644 --- a/src/shared/components/communities.tsx +++ b/src/shared/components/communities.tsx @@ -273,7 +273,7 @@ export class Communities extends Component { handleSearchSubmit(i: Communities) { const searchParamEncoded = encodeURIComponent(i.state.searchText); i.context.router.history.push( - `/search/q/${searchParamEncoded}/type/Communities/sort/TopAll/listing_type/All/community_id/0/page/1` + `/search/q/${searchParamEncoded}/type/Communities/sort/TopAll/listing_type/All/community_id/0/creator_id/0/page/1` ); } diff --git a/src/shared/components/navbar.tsx b/src/shared/components/navbar.tsx index efab35e6..ff0f0ba9 100644 --- a/src/shared/components/navbar.tsx +++ b/src/shared/components/navbar.tsx @@ -134,7 +134,7 @@ export class Navbar extends Component { } else { const searchParamEncoded = encodeURIComponent(searchParam); this.context.router.history.push( - `/search/q/${searchParamEncoded}/type/All/sort/TopAll/listing_type/All/community_id/0/page/1` + `/search/q/${searchParamEncoded}/type/All/sort/TopAll/listing_type/All/community_id/0/creator_id/0/page/1` ); } } diff --git a/src/shared/components/search.tsx b/src/shared/components/search.tsx index 87699bd2..9f0c04ee 100644 --- a/src/shared/components/search.tsx +++ b/src/shared/components/search.tsx @@ -17,6 +17,7 @@ import { ListCommunities, ListCommunitiesResponse, GetCommunity, + GetPersonDetails, } from "lemmy-js-client"; import { WebSocketService } from "../services"; import { @@ -44,6 +45,9 @@ import { fetchCommunities, communityToChoice, hostname, + fetchUsers, + personToChoice, + capitalizeFirstLetter, } from "../utils"; import { PostListing } from "./post-listing"; import { HtmlTags } from "./html-tags"; @@ -67,6 +71,7 @@ interface SearchProps { sort: SortType; listingType: ListingType; communityId: number; + creatorId: number; page: number; } @@ -76,9 +81,11 @@ interface SearchState { sort: SortType; listingType: ListingType; communityId: number; + creatorId: number; page: number; searchResponse: SearchResponse; communities: CommunityView[]; + creator?: PersonViewSafe; loading: boolean; site: Site; searchText: string; @@ -90,12 +97,14 @@ interface UrlParams { sort?: SortType; listingType?: ListingType; communityId?: number; + creatorId?: number; page?: number; } export class Search extends Component { private isoData = setIsoData(this.context); - private choices: any; + private communityChoices: any; + private creatorChoices: any; private subscription: Subscription; private emptyState: SearchState = { q: Search.getSearchQueryFromProps(this.props.match.params.q), @@ -109,6 +118,7 @@ export class Search extends Component { communityId: Search.getCommunityIdFromProps( this.props.match.params.community_id ), + creatorId: Search.getCreatorIdFromProps(this.props.match.params.creator_id), searchResponse: { type_: null, posts: [], @@ -141,6 +151,10 @@ export class Search extends Component { return id ? Number(id) : 0; } + static getCreatorIdFromProps(id: string): number { + return id ? Number(id) : 0; + } + static getPageFromProps(page: string): number { return page ? Number(page) : 1; } @@ -163,8 +177,13 @@ export class Search extends Component { } 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[1]; + this.state.searchResponse = this.isoData.routeData[2]; this.state.loading = false; } else { this.search(); @@ -182,6 +201,7 @@ export class Search extends Component { componentDidMount() { this.setupCommunityFilter(); + this.setupCreatorFilter(); } static getDerivedStateFromProps(props: any): SearchProps { @@ -195,6 +215,7 @@ export class Search extends Component { communityId: Search.getCommunityIdFromProps( props.match.params.community_id ), + creatorId: Search.getCreatorIdFromProps(props.match.params.creator_id), page: Search.getPageFromProps(props.match.params.page), }; } @@ -215,13 +236,13 @@ export class Search extends Component { let pathSplit = req.path.split("/"); let promises: Promise[] = []; - let cId = this.getCommunityIdFromProps(pathSplit[11]); - if (cId !== 0) { - let f: GetCommunity = { - id: cId, + let communityId = this.getCommunityIdFromProps(pathSplit[11]); + if (communityId !== 0) { + let getCommunityForm: GetCommunity = { + id: communityId, }; - setOptionalAuth(f, req.auth); - promises.push(req.client.getCommunity(f)); + setOptionalAuth(getCommunityForm, req.auth); + promises.push(req.client.getCommunity(getCommunityForm)); } else { let listCommunitiesForm: ListCommunities = { type_: ListingType.All, @@ -232,16 +253,30 @@ export class Search extends Component { 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()); + } + let form: SearchForm = { q: this.getSearchQueryFromProps(pathSplit[3]), type_: this.getSearchTypeFromProps(pathSplit[5]), sort: this.getSortTypeFromProps(pathSplit[7]), listing_type: this.getListingTypeFromProps(pathSplit[9]), - page: this.getPageFromProps(pathSplit[13]), + page: this.getPageFromProps(pathSplit[15]), limit: fetchLimit, }; - if (cId !== 0) { - form.community_id = cId; + if (communityId !== 0) { + form.community_id = communityId; + } + if (creatorId !== 0) { + form.creator_id = creatorId; } setOptionalAuth(form, req.auth); @@ -259,6 +294,7 @@ export class Search extends Component { lastState.sort !== this.state.sort || lastState.listingType !== this.state.listingType || lastState.communityId !== this.state.communityId || + lastState.creatorId !== this.state.creatorId || lastState.page !== this.state.page ) { this.setState({ loading: true, searchText: this.state.q }); @@ -353,7 +389,10 @@ export class Search extends Component { hideMostComments /> - {this.state.communities.length > 0 && this.communityFilter()} +
+ {this.state.communities.length > 0 && this.communityFilter()} + {this.creatorFilter()} +
); } @@ -519,11 +558,11 @@ export class Search extends Component { communityFilter() { return ( -
-