Fix communities search bug (#2108)

Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
This commit is contained in:
SleeplessOne1917 2023-09-02 14:22:41 -04:00 committed by GitHub
parent 38ec8c0b06
commit c49ca9e195
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -58,6 +58,13 @@ function getListingTypeFromQuery(listingType?: string): ListingType {
function getSortTypeFromQuery(type?: string): SortType {
return type ? (type as SortType) : "TopMonth";
}
function getCommunitiesQueryParams() {
return getQueryParams<CommunitiesProps>({
listingType: getListingTypeFromQuery,
sort: getSortTypeFromQuery,
page: getPageFromString,
});
}
export class Communities extends Component<any, CommunitiesState> {
private isoData = setIsoData<CommunitiesData>(this.context);
@ -107,7 +114,7 @@ export class Communities extends Component<any, CommunitiesState> {
</h5>
);
case "success": {
const { listingType, sort, page } = this.getCommunitiesQueryParams();
const { listingType, sort, page } = getCommunitiesQueryParams();
return (
<div>
<h1 className="h4 mb-4">
@ -265,7 +272,7 @@ export class Communities extends Component<any, CommunitiesState> {
listingType: urlListingType,
sort: urlSort,
page: urlPage,
} = this.getCommunitiesQueryParams();
} = getCommunitiesQueryParams();
const queryParams: QueryParams<CommunitiesProps> = {
listingType: listingType ?? urlListingType,
@ -300,8 +307,9 @@ export class Communities extends Component<any, CommunitiesState> {
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<any, CommunitiesState> {
};
}
getCommunitiesQueryParams() {
return getQueryParams<CommunitiesProps>({
listingType: getListingTypeFromQuery,
sort: getSortTypeFromQuery,
page: getPageFromString,
});
}
async handleFollow(data: {
i: Communities;
communityId: number;
@ -351,7 +351,7 @@ export class Communities extends Component<any, CommunitiesState> {
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({