From 9f861534955bb3dab3455adebc975444060ec0e8 Mon Sep 17 00:00:00 2001
From: ttmx <git@tteles.dev>
Date: Mon, 20 May 2024 10:35:35 +0000
Subject: [PATCH] Fix pdfs with only 2 stops

---
 .../schedule/[line_id]/[direction_id]/[stop_id]/page.tsx  | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/renderer/app/schedule/[line_id]/[direction_id]/[stop_id]/page.tsx b/renderer/app/schedule/[line_id]/[direction_id]/[stop_id]/page.tsx
index 0587872..c386459 100644
--- a/renderer/app/schedule/[line_id]/[direction_id]/[stop_id]/page.tsx
+++ b/renderer/app/schedule/[line_id]/[direction_id]/[stop_id]/page.tsx
@@ -30,7 +30,7 @@ export default async function Page({ params }:{params:{line_id:string, stop_id:s
 	const secondaryPatternsPromise = Promise.all(timetable.secondaryPatterns.map(patternId => fetch(`${API_URL}/patterns/${patternId}`).then(patternRes => patternRes.json())));
 	// console.log(patternURL, timetable.secondaryPatterns.map(patternId => `${API_URL}/patterns/${patternId}`));
 
-	const [pattern, secondaryPatterns]:[	Pattern, Pattern[] ] = await Promise.all([patternRes, secondaryPatternsPromise]);
+	const [pattern, secondaryPatterns]:[ Pattern, Pattern[] ] = await Promise.all([patternRes, secondaryPatternsPromise]);
 	if (!pattern.path || !pattern.path[1] || !pattern.path[1].stop) {
 		console.error(patternURL, 'pattern.path[1].stop is undefined, pattern:', pattern);
 		return;
@@ -154,8 +154,10 @@ export default async function Page({ params }:{params:{line_id:string, stop_id:s
 			accumulatedDelay = 0;
 		}
 	}
-	delays[delays.length - 1].span += 1;
-	delays[delays.length - 1].delay += lastStop.delay;
+	if (delays.length > 0) {
+		delays[delays.length - 1].span += 1;
+		delays[delays.length - 1].delay += lastStop.delay;
+	}
 
 	for (let stopIndex in renderedStops) {
 		const stop = renderedStops[stopIndex];