Commit ec6d245e authored by Alexey Petrik's avatar Alexey Petrik

48128

parent b868c4c0
Pipeline #14057 failed with stages
in 2 minutes and 47 seconds
......@@ -15,6 +15,8 @@ import { Route } from '../enums';
import { getSearchInfoFromFS } from '../store/fastSearchInfo/selectors';
import { startFastSearch } from '../store/fastSearchInfo/actions';
import { trimSlashes } from '../utils';
import { FastSearch } from '../services/parsers/fastSearch';
import { ISO_DATE_LENGTH } from '../utils';
interface OwnProps {
route: Route;
......@@ -128,6 +130,19 @@ class SearchForm extends React.Component<Props, State> {
}
const mapStateToProps = (state: RootState): StateProps => {
if (getRoute(state) === Route.SearchFormInit) {
var fastSearch = new FastSearch(state.router.location.pathname).parse(),
searchFormConfig: ComponentProps = {};
searchFormConfig.defaultDepartureAirport = fastSearch.segments[0].departureIATA;
searchFormConfig.defaultArrivalAirport = fastSearch.segments[0].arrivalIATA;
searchFormConfig.defaultDepartureDate = fastSearch.segments[0].departureDate.format().substr(0, ISO_DATE_LENGTH);
if (fastSearch.segments.length > 1) {
searchFormConfig.defaultReturnDate = fastSearch.segments[1].departureDate.format().substr(0, ISO_DATE_LENGTH);
}
searchFormConfig.defaultPassengers = fastSearch.passengers;
searchFormConfig.disableCaching = true;
state.config.searchForm = searchFormConfig;
}
return {
location: state.router.location,
searchFormConfig: getSearchFormConfig(state),
......
......@@ -77,7 +77,8 @@ export enum Route {
Initial,
Results,
ResultsWithIds,
FastSearch
FastSearch,
SearchFormInit
}
export enum FastSearchParsingState {
......
......@@ -28,7 +28,7 @@ export class FastSearch {
fastSearchString = '';
constructor(location: string) {
this.fastSearchString = location.substr(9);
this.fastSearchString = location.replace('/search/', '').replace('/results/', '');
}
isIATANext(): boolean {
......
......@@ -595,6 +595,9 @@ export const getRoute = createSelector(
else if (/\/results\/((?:[A-ZА-Я]{3}[A-ZА-Я]{3}\d{8,16})+)((?:[A-Z]{3}[1-9])+)?((?:-[a-zA-Z=\d\+]+)+)?(?:\/?\?.*)?$/.test(location)) {
return Route.FastSearch;
}
else if (/\/search\/((?:[A-ZА-Я]{3}[A-ZА-Я]{3}\d{8,16})+)((?:[A-Z]{3}[1-9])+)?((?:-[a-zA-Z=\d\+]+)+)?(?:\/?\?.*)?$/.test(location)) {
return Route.SearchFormInit;
}
else if (location === '/results') {
return Route.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