Skip to content

Commit

Permalink
Show dest or dept station on StationTimeTable based on selection (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
viliket authored Sep 14, 2023
1 parent f6585d4 commit 3310d41
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"no_results": "No results.",
"train": "Train",
"train_details": "Train details",
"from": "From",
"destination": "Destination",
"departure": "Departure",
"departures": "Departures",
Expand Down
1 change: 1 addition & 0 deletions public/locales/fi/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"no_results": "Ei tuloksia.",
"train": "Juna",
"train_details": "Junan tiedot",
"from": "Lähtöasema",
"destination": "Määränpää",
"departure": "Lähtee",
"departures": "Lähtevät",
Expand Down
6 changes: 5 additions & 1 deletion src/components/StationTimeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ function StationTimeTable({
<TableHead>
<TableRow>
<TableCell>{t('train')}</TableCell>
<TableCell>{t('destination')}</TableCell>
<TableCell>
{timeTableType === TimeTableRowType.Departure
? t('destination')
: t('from')}
</TableCell>
<TableCell align="center">
{timeTableType === TimeTableRowType.Departure
? t('departure')
Expand Down
19 changes: 15 additions & 4 deletions src/components/StationTimeTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import {
TrainByStationFragment,
} from '../graphql/generated/digitraffic';
import getTimeTableRowForStation from '../utils/getTimeTableRowForStation';
import { getTrainDestinationStationName } from '../utils/train';
import {
getTrainDepartureStation,
getTrainDestinationStation,
getTrainStationName,
} from '../utils/train';

import TimeTableRowTime from './TimeTableRowTime';
import VehicleTrackingIcon from './VehicleTrackingIcon';
Expand All @@ -41,7 +45,14 @@ function StationTimeTableRow({
const trainName = train.commuterLineid
? train.commuterLineid
: train.trainType.name + train.trainNumber;
const destinationStationName = getTrainDestinationStationName(train);
const deptOrDestStation =
timeTableType === TimeTableRowType.Departure
? getTrainDestinationStation(train)
: getTrainDepartureStation(train);
const deptOrDestStationName = deptOrDestStation
? getTrainStationName(deptOrDestStation)
: null;

const stationRow = getTimeTableRowForStation(
stationCode,
train,
Expand Down Expand Up @@ -94,12 +105,12 @@ function StationTimeTableRow({
<TableCell>
<Link
component={RouterLink}
href={`/${destinationStationName}`}
href={`/${deptOrDestStationName}`}
color="inherit"
underline="none"
onClick={handleStationClick}
>
{destinationStationName}
{deptOrDestStationName}
</Link>
</TableCell>
<TableCell align="center">
Expand Down

0 comments on commit 3310d41

Please sign in to comment.