@autobusal/routes-order 1.37.4 → 1.37.6

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.
@@ -1,10 +1,14 @@
1
1
  import { TFunction } from 'i18next';
2
2
  import Facts from '../Facts/Facts';
3
3
  import Faq from '../Faq/Faq';
4
+ import Availability from '../Availability/Availability';
5
+ import AvailabilitySchema from '../Availability/Schema';
4
6
  import Schedule from '../Schedule/Schedule';
5
7
  import Links from '../Links/Links';
6
8
  import Schema from './Schema';
7
9
  import { useGetFacts } from '../Facts/services';
10
+ import { useGetAvailability } from '../Availability/services';
11
+ import { prepare } from '../Availability/service';
8
12
  import buildQuestions from '../Facts/questions';
9
13
  import { stopped } from '../Facts/service';
10
14
  import { Nav, Anchor, Anchored } from './styles';
@@ -17,6 +21,7 @@ interface Props {
17
21
 
18
22
  const TRIPS = 'trips';
19
23
  const FACTS = 'facts';
24
+ const AVAILABILITY = 'availability';
20
25
  const SCHEDULE = 'schedule';
21
26
  const FAQ = 'faq';
22
27
  const LINKS = 'links';
@@ -36,12 +41,25 @@ const LINKS = 'links';
36
41
  * response, and letting each fetch its own would have doubled what the
37
42
  * prerender crawl costs on every pair in the sitemap.
38
43
  *
44
+ * Edited: Claude - Date: 2026-09-16
45
+ *
46
+ * TWO fetches now, and the second one is not a regression of the paragraph
47
+ * above. The next-30-days section needs live seat counts, and the facts
48
+ * payload is cached for six hours precisely because nothing in it moves -
49
+ * folding one into the other would either publish stale seat counts or
50
+ * throw away a cache that every pair page depends on. It stays one request
51
+ * per page rather than one per departure, and it renders NOTHING when it
52
+ * fails, so a page whose second call never answers is exactly the page it
53
+ * was yesterday.
54
+ *
39
55
  * The nav renders only when there is more than the wizard to navigate to -
40
56
  * a bar whose only link is "Trips" is furniture.
41
57
  */
42
58
  const Sections = ({ from, to, t }: Props): (JSX.Element | null) => {
43
59
  const { data } = useGetFacts(from, to);
44
60
 
61
+ const { data: dates } = useGetAvailability(from, to);
62
+
45
63
  const facts = data?.facts;
46
64
 
47
65
  const links = data?.links ?? { from: [], to: [], reverse: null };
@@ -66,6 +84,19 @@ const Sections = ({ from, to, t }: Props): (JSX.Element | null) => {
66
84
  // that happen to agree today.
67
85
  const questions = buildQuestions(facts, t);
68
86
 
87
+ /**
88
+ * Edited: Claude - Date: 2026-09-16
89
+ *
90
+ * Prepared once, here, and handed to the section AND to its structured
91
+ * data - the same arrangement `questions` above is in, for the same
92
+ * reason. Null when the endpoint did not answer, answered with nothing,
93
+ * or answered with a window in which no coach runs; every consumer below
94
+ * is gated on that single value, so there is no arrangement in which the
95
+ * nav offers a link to a section that rendered nothing, or the markup
96
+ * describes departures the page does not list.
97
+ */
98
+ const availability = prepare(dates, t);
99
+
69
100
  /**
70
101
  * Edited: Claude - Date: 2026-08-21
71
102
  *
@@ -108,6 +139,10 @@ const Sections = ({ from, to, t }: Props): (JSX.Element | null) => {
108
139
  <Anchor href={ `#${ TRIPS }` }>{ t('routes_order.sections.trips') }</Anchor>
109
140
  <Anchor href={ `#${ FACTS }` }>{ t('routes_order.sections.facts') }</Anchor>
110
141
 
142
+ { availability && (
143
+ <Anchor href={ `#${ AVAILABILITY }` }>{ t('routes_order.sections.availability') }</Anchor>
144
+ ) }
145
+
111
146
  { schedule.length > 0 && (
112
147
  <Anchor href={ `#${ SCHEDULE }` }>{ t('routes_order.sections.schedule') }</Anchor>
113
148
  ) }
@@ -122,12 +157,34 @@ const Sections = ({ from, to, t }: Props): (JSX.Element | null) => {
122
157
  show - same facts, same numbers, same operators. */ }
123
158
  <Schema facts={ facts } questions={ questions } t={ t } />
124
159
 
160
+ { /* Edited: Claude - Date: 2026-09-16
161
+ One BusTrip per dated departure, alongside the pair-level one
162
+ above rather than instead of it: that one describes the journey,
163
+ these describe the actual coaches on actual days. Built from the
164
+ same prepared array the section renders. */ }
165
+ { availability && <AvailabilitySchema data={ availability } t={ t } /> }
166
+
125
167
  <Anchored>
126
168
  <Facts id={ FACTS } facts={ facts } t={ t } />
127
169
  </Anchored>
128
170
 
129
171
  { dead && onward }
130
172
 
173
+ { /* Edited: Claude - Date: 2026-09-16
174
+ ABOVE the timetable, because a reader who has a date in mind is
175
+ answered here and a reader who does not is answered below. The
176
+ timetable is the pattern - what runs, in the abstract; this is
177
+ the next thirty days of it, with fares and seats. Renders nothing
178
+ at all when the endpoint gives us nothing, which is also what
179
+ happens on a pair that has stopped running: the notice in the
180
+ facts block above has already said so, and thirty rows of "no
181
+ departures" underneath it would be a wall, not an answer. */ }
182
+ { availability && (
183
+ <Anchored>
184
+ <Availability id={ AVAILABILITY } data={ availability } t={ t } />
185
+ </Anchored>
186
+ ) }
187
+
131
188
  <Anchored>
132
189
  <Schedule id={ SCHEDULE } from={ facts.from } to={ facts.to } rows={ schedule } t={ t } />
133
190
  </Anchored>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobusal/routes-order",
3
- "version": "1.37.4",
3
+ "version": "1.37.6",
4
4
  "author": "Ferjolt Ozuni",
5
5
  "type": "module",
6
6
  "main": "index.ts",