diff --git a/src/shared/components/community/communities.tsx b/src/shared/components/community/communities.tsx index 03254a184..4d6a107fd 100644 --- a/src/shared/components/community/communities.tsx +++ b/src/shared/components/community/communities.tsx @@ -58,6 +58,13 @@ function getListingTypeFromQuery(listingType?: string): ListingType { function getSortTypeFromQuery(type?: string): SortType { return type ? (type as SortType) : "TopMonth"; } +function getCommunitiesQueryParams() { + return getQueryParams({ + listingType: getListingTypeFromQuery, + sort: getSortTypeFromQuery, + page: getPageFromString, + }); +} export class Communities extends Component { private isoData = setIsoData(this.context); @@ -107,7 +114,7 @@ export class Communities extends Component { ); case "success": { - const { listingType, sort, page } = this.getCommunitiesQueryParams(); + const { listingType, sort, page } = getCommunitiesQueryParams(); return (

@@ -265,7 +272,7 @@ export class Communities extends Component { listingType: urlListingType, sort: urlSort, page: urlPage, - } = this.getCommunitiesQueryParams(); + } = getCommunitiesQueryParams(); const queryParams: QueryParams = { listingType: listingType ?? urlListingType, @@ -300,8 +307,9 @@ export class Communities extends Component { handleSearchSubmit(i: Communities, event: any) { event.preventDefault(); const searchParamEncoded = encodeURIComponent(i.state.searchText); + const { listingType } = getCommunitiesQueryParams(); i.context.router.history.push( - `/search?q=${searchParamEncoded}&type=Communities`, + `/search?q=${searchParamEncoded}&type=Communities&listingType=${listingType}`, ); } @@ -327,14 +335,6 @@ export class Communities extends Component { }; } - getCommunitiesQueryParams() { - return getQueryParams({ - listingType: getListingTypeFromQuery, - sort: getSortTypeFromQuery, - page: getPageFromString, - }); - } - async handleFollow(data: { i: Communities; communityId: number; @@ -351,7 +351,7 @@ export class Communities extends Component { async refetch() { this.setState({ listCommunitiesResponse: { state: "loading" } }); - const { listingType, sort, page } = this.getCommunitiesQueryParams(); + const { listingType, sort, page } = getCommunitiesQueryParams(); this.setState({ listCommunitiesResponse: await HttpService.client.listCommunities({