From c49ca9e1958622600f615c276d599d70aa6ccda5 Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 Date: Sat, 2 Sep 2023 14:22:41 -0400 Subject: [PATCH] Fix communities search bug (#2108) Co-authored-by: Dessalines --- .../components/community/communities.tsx | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/shared/components/community/communities.tsx b/src/shared/components/community/communities.tsx index 03254a18..4d6a107f 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({