@autobusal/routes-search 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/RoutesSearch.tsx +30 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
**The date picker follows the departure city.** Choosing a "from" city now sets the picker's floor to that city's timezone, and a pre-filled form (a shared link, or the search form kept on the results page) sets it on mount rather than waiting for a keystroke.
|
|
6
|
+
|
|
7
|
+
An unknown city *clears* the zone rather than keeping the last one — silently flooring a new search on the previous journey's clock is the subtler version of the same bug.
|
|
8
|
+
|
|
3
9
|
All notable changes to `@autobusal/routes-search` are documented here. This
|
|
4
10
|
project adheres to [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
|
|
5
11
|
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
package/RoutesSearch.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
1
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
2
2
|
import { TFunction } from 'i18next';
|
|
3
3
|
import { useForm } from 'react-hook-form';
|
|
4
4
|
import { FaArrowUp, FaHistory } from 'react-icons/fa';
|
|
5
5
|
import { AiOutlineSearch } from 'react-icons/ai';
|
|
6
|
-
import { Button, Autocomplete, Calendar, Passengers } from '@autobusal/common';
|
|
6
|
+
import { Button, Autocomplete, Calendar, Passengers, setDepartureZone } from '@autobusal/common';
|
|
7
7
|
import { Display, createDate } from '@autobusal/utilities';
|
|
8
8
|
import { getCities } from './utilities';
|
|
9
9
|
import { Options, Columns, Column, Item, Title, Action } from './styles';
|
|
@@ -36,6 +36,33 @@ const RoutesSearch = ({ type, from, to, departure, _return, adultsNo, childrenNo
|
|
|
36
36
|
|
|
37
37
|
const { data: CitiesData } = useGetSuggestions();
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Tell the date picker which clock this journey starts on.
|
|
41
|
+
*
|
|
42
|
+
* Edited: Ferjolt Ozuni - Date: 2026-08-03
|
|
43
|
+
*
|
|
44
|
+
* The picker used to floor on the buyer's device, then on our server's
|
|
45
|
+
* date - both wrong for the same reason: neither has anything to do with
|
|
46
|
+
* where the coach leaves from. Somebody in Shanghai at 06:00 on the 5th
|
|
47
|
+
* looking at an Italian coach leaving on the evening of the 4th had that
|
|
48
|
+
* day greyed out and could not ask for a seat the server would have sold.
|
|
49
|
+
*
|
|
50
|
+
* The value carries an optional stop (`slug:id`), so only the slug is
|
|
51
|
+
* matched. An unknown city clears the zone rather than keeping the last
|
|
52
|
+
* one, which would silently floor a new search on the old journey's clock.
|
|
53
|
+
*/
|
|
54
|
+
const onDeparture = useCallback((value: string): void => {
|
|
55
|
+
const slug = String(value).split(':')[0];
|
|
56
|
+
|
|
57
|
+
setDepartureZone(CitiesData.find(city => city.slug === slug)?.country?.timezone ?? null);
|
|
58
|
+
}, [CitiesData]);
|
|
59
|
+
|
|
60
|
+
// the form can also arrive pre-filled - from a shared link, or the search
|
|
61
|
+
// form kept on the results page - so the zone cannot wait for a keystroke
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
onDeparture(from);
|
|
64
|
+
}, [from, onDeparture]);
|
|
65
|
+
|
|
39
66
|
const onClick = (type: ('departure' | 'return')): void => {
|
|
40
67
|
setSelected(type);
|
|
41
68
|
};
|
|
@@ -110,7 +137,7 @@ const RoutesSearch = ({ type, from, to, departure, _return, adultsNo, childrenNo
|
|
|
110
137
|
validation="required"
|
|
111
138
|
t={ t }
|
|
112
139
|
refs={ register }
|
|
113
|
-
onUpdate={ setValue }
|
|
140
|
+
onUpdate={ (_, value) => { setValue('from', value); onDeparture(String(value)); } }
|
|
114
141
|
/>
|
|
115
142
|
|
|
116
143
|
{ Display(errors.from) }
|