mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-12-26 18:54:12 +00:00
fix: Make search screen able to change type, listing type, and sort when there is no query (#966)
This commit is contained in:
parent
07e7e1eb87
commit
fe0ebbeec1
|
@ -236,14 +236,20 @@ export class Search extends Component<any, SearchState> {
|
||||||
this.setupCreatorFilter();
|
this.setupCreatorFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
static getDerivedStateFromProps(props: any): SearchProps {
|
static getDerivedStateFromProps(
|
||||||
|
props: any,
|
||||||
|
prevState: SearchState
|
||||||
|
): SearchProps {
|
||||||
return {
|
return {
|
||||||
q: Search.getSearchQueryFromProps(props.match.params.q),
|
q: Search.getSearchQueryFromProps(props.match.params.q),
|
||||||
type_: Search.getSearchTypeFromProps(props.match.params.type),
|
type_:
|
||||||
sort: Search.getSortTypeFromProps(props.match.params.sort),
|
prevState.type_ ??
|
||||||
listingType: Search.getListingTypeFromProps(
|
Search.getSearchTypeFromProps(props.match.params.type),
|
||||||
props.match.params.listing_type
|
sort:
|
||||||
),
|
prevState.sort ?? Search.getSortTypeFromProps(props.match.params.sort),
|
||||||
|
listingType:
|
||||||
|
prevState.listingType ??
|
||||||
|
Search.getListingTypeFromProps(props.match.params.listing_type),
|
||||||
communityId: Search.getCommunityIdFromProps(
|
communityId: Search.getCommunityIdFromProps(
|
||||||
props.match.params.community_id
|
props.match.params.community_id
|
||||||
),
|
),
|
||||||
|
@ -878,21 +884,27 @@ export class Search extends Component<any, SearchState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSortChange(val: SortType) {
|
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) {
|
handleTypeChange(i: Search, event: any) {
|
||||||
i.updateUrl({
|
const updateObj = {
|
||||||
type_: SearchType[event.target.value],
|
type_: SearchType[event.target.value],
|
||||||
page: 1,
|
page: 1,
|
||||||
});
|
};
|
||||||
|
i.setState(updateObj);
|
||||||
|
i.updateUrl(updateObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleListingTypeChange(val: ListingType) {
|
handleListingTypeChange(val: ListingType) {
|
||||||
this.updateUrl({
|
const updateObj = {
|
||||||
listingType: val,
|
listingType: val,
|
||||||
page: 1,
|
page: 1,
|
||||||
});
|
};
|
||||||
|
this.setState(updateObj);
|
||||||
|
this.updateUrl(updateObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleCommunityFilterChange(communityId: number) {
|
handleCommunityFilterChange(communityId: number) {
|
||||||
|
|
Loading…
Reference in a new issue