Commit 90517472 authored by Andrey Kizimov's avatar Andrey Kizimov

remove filters when user returns to first leg

parent caa8f66a
Pipeline #285 passed with stages
in 3 minutes and 38 seconds
......@@ -18,6 +18,7 @@ import MediaQuery from 'react-responsive';
import { ScreenMaxSize } from '../enums';
import autobind from 'autobind-decorator';
import { ResultLegs } from './ResultLegs';
import { removeAllFilters } from '../store/filters/actions';
interface StateProps {
isRT: boolean;
......@@ -29,18 +30,28 @@ interface StateProps {
flightSearchActive: boolean;
}
interface DispatchProps {
removeAllFilters: typeof removeAllFilters;
}
interface State {
selectedLeg: number;
}
class Results extends React.Component<StateProps, State> {
class Results extends React.Component<StateProps & DispatchProps, State> {
state: State = {
selectedLeg: 0
};
@autobind
setLeg(leg: number): void {
this.setState({ selectedLeg: leg });
if (leg < this.props.legs.length) {
if (leg === 0) {
this.props.removeAllFilters();
}
this.setState({ selectedLeg: leg });
}
}
renderNoFlights(): React.ReactNode {
......@@ -53,14 +64,15 @@ class Results extends React.Component<StateProps, State> {
}
render(): React.ReactNode {
const { currentLeg, hasAnyFlights, hasAnyVisibleFlights, isRT, flightSearchActive, legs } = this.props;
const isMultipleLegs = legs.length > 1;
const { currentLeg, hasAnyFlights, hasAnyVisibleFlights, isRT, flightSearchActive, legs } = this.props,
isMultipleLegs = legs.length > 1,
visibleLeg = legs[this.state.selectedLeg];
return <div className="results__inner">
{hasAnyFlights ? <>
{isMultipleLegs && <SelectedFlights selectedLeg={this.setLeg}/>}
<Filters isRT={isRT} currentLeg={currentLeg} withSearch={flightSearchActive}/>
<Filters isRT={isRT} currentLeg={visibleLeg} withSearch={flightSearchActive}/>
{hasAnyVisibleFlights && <Sortings/>}
......@@ -81,7 +93,7 @@ class Results extends React.Component<StateProps, State> {
}
}
export default connect<StateProps>({
export default connect<StateProps, DispatchProps>({
isRT: isRT,
isLoading: getIsLoading,
hasAnyFlights: hasAnyFlights,
......@@ -89,4 +101,6 @@ export default connect<StateProps>({
currentLeg: getCurrentLeg,
legs: getLegs,
flightSearchActive: flightSearchIsActive
}, {
removeAllFilters
})(Results);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment