From: SleeplessOne1917 Date: Mon, 27 Mar 2023 01:56:49 +0000 (-0400) Subject: fix: Make search screen able to change type, listing type, and sort when there is... X-Git-Url: http://these/git/%22https:/www.exeterceilidhs.net/%22%7B%7D/static/%7BmarkdownHelpUrl%7D?a=commitdiff_plain;h=fe0ebbeec1d8422ab1812cadf06550da97ad0573;p=lemmy-ui.git fix: Make search screen able to change type, listing type, and sort when there is no query (#966) --- diff --git a/src/shared/components/search.tsx b/src/shared/components/search.tsx index b96e1c5..e36c9ad 100644 --- a/src/shared/components/search.tsx +++ b/src/shared/components/search.tsx @@ -236,14 +236,20 @@ export class Search extends Component { this.setupCreatorFilter(); } - static getDerivedStateFromProps(props: any): SearchProps { + static getDerivedStateFromProps( + props: any, + prevState: SearchState + ): SearchProps { return { q: Search.getSearchQueryFromProps(props.match.params.q), - type_: Search.getSearchTypeFromProps(props.match.params.type), - sort: Search.getSortTypeFromProps(props.match.params.sort), - listingType: Search.getListingTypeFromProps( - props.match.params.listing_type - ), + type_: + prevState.type_ ?? + Search.getSearchTypeFromProps(props.match.params.type), + sort: + prevState.sort ?? Search.getSortTypeFromProps(props.match.params.sort), + listingType: + prevState.listingType ?? + Search.getListingTypeFromProps(props.match.params.listing_type), communityId: Search.getCommunityIdFromProps( props.match.params.community_id ), @@ -878,21 +884,27 @@ export class Search extends Component { } handleSortChange(val: SortType) { - this.updateUrl({ sort: val, page: 1 }); + const updateObj = { sort: val, page: 1 }; + this.setState(updateObj); + this.updateUrl(updateObj); } handleTypeChange(i: Search, event: any) { - i.updateUrl({ + const updateObj = { type_: SearchType[event.target.value], page: 1, - }); + }; + i.setState(updateObj); + i.updateUrl(updateObj); } handleListingTypeChange(val: ListingType) { - this.updateUrl({ + const updateObj = { listingType: val, page: 1, - }); + }; + this.setState(updateObj); + this.updateUrl(updateObj); } handleCommunityFilterChange(communityId: number) {