Skip to content

Commit

Permalink
Fix implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-vasconcelos committed Feb 4, 2025
1 parent e14ee79 commit eef4acf
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions frontend/app/(views)/(website)/stops/[stop_id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { StopsDetail } from '@/components/stops/StopsDetail';
import { StopsDetailContextProvider } from '@/contexts/StopsDetail.context';
import { Routes } from '@/utils/routes';
import { type Stop } from '@carrismetropolitana/api-types/network';
import { type Line, type Stop } from '@carrismetropolitana/api-types/network';
import { type Metadata } from 'next';

/* * */
Expand All @@ -22,17 +22,24 @@ export async function generateMetadata({ params }): Promise<Metadata> {
const allStopsResponse = await fetch(`${Routes.API}/stops`);
const allStopsData: Stop[] = await allStopsResponse.json();

const allLinesResponse = await fetch(`${Routes.API}/lines`);
const allLinesData: Line[] = await allLinesResponse.json();

//
// C. Transform data

const stopData = allStopsData.find(item => item.id === stop_id);
const stopIds = allStopsData.flatMap(item => item.line_ids);
const goesTrough = allStopsData.find(item => item.line_ids && item.line_ids.some(id => stopIds.includes(id)));
const linesAtThisStopString = allLinesData
.filter(item => stopData?.line_ids.includes(item.id))
.sort((a, b) => a.id.localeCompare(b.id))
.map(item => item.short_name)
.join(', ');

//
// D. Render components

return {
description: `Horários em tempo real na paragem #${stopData?.id}. Esta paragem cruza as linhas ${goesTrough?.line_ids}`,
description: `Horários planeados e em tempo real na paragem #${stopData?.id}. Nesta paragem passam as linhas ${linesAtThisStopString}.`,
title: stopData?.long_name,
};

Expand Down

0 comments on commit eef4acf

Please sign in to comment.