Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/api/dashboard/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function GET(request: Request) {

transformedData.forEach((status) => {
status.journey.line.appearance = getAppearanceForLine(
identifyLineByMagic(status.journey.hafasTripId, status.journey.line)
status.journey.line,
);
});

Expand Down
6 changes: 3 additions & 3 deletions src/app/api/stations/[station]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { identifyLineByMagic } from '@/helpers/identifyLineByMagic';
import { createLineAppearanceDataset } from '@/helpers/lineAppearance';
import { authOptions } from '@/pages/api/auth/[...nextauth]';
import { TraewellingSdk } from '@/traewelling-sdk';
import { transformHAFASTrip } from '@/traewelling-sdk/transformers';
import { transformTrwlDeparture } from '@/traewelling-sdk/transformers';
import { TransportType } from '@/traewelling-sdk/types';
import { AboardStation, AboardTrip } from '@/types/aboard';
import createErrorResponse from '@/utils/api/createErrorResponse';
Expand Down Expand Up @@ -84,12 +84,12 @@ export async function GET(
} as AboardStation,
times: data.meta?.times,
},
trips: data.trips.map(transformHAFASTrip),
trips: data.trips.map(transformTrwlDeparture),
};

transformedData.trips.forEach((trip) => {
trip.line.appearance = getAppearanceForLine(
identifyLineByMagic(trip.hafasId, trip.line)
trip.line,
);
});

Expand Down
5 changes: 2 additions & 3 deletions src/app/api/trips/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { getServerSession } from 'next-auth';

export async function GET(request: Request) {
try {
const { hafasTripId, lineName, start } = getSafeURLParams({
const { hafasTripId, lineName } = getSafeURLParams({
url: request.url,
requiredParams: ['hafasTripId', 'lineName', 'start'],
requiredParams: ['hafasTripId', 'lineName'],
});

const session = await getServerSession(authOptions);
Expand All @@ -23,7 +23,6 @@ export async function GET(request: Request) {
const data = await TraewellingSdk.trains.trip({
hafasTripId,
lineName,
start,
});

return createResponse({
Expand Down
11 changes: 4 additions & 7 deletions src/app/status/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ async function getStatusData(id: string) {
async function getTripData(
hafasTripId: string,
lineName: string,
start: string
) {
try {
const trip = await TraewellingSdk.trains.trip({
hafasTripId,
lineName,
start,
});

if (!('id' in trip)) {
Expand Down Expand Up @@ -70,7 +68,6 @@ export default async function Page({ params }: StatusPageProps) {
const tripData = await getTripData(
status.journey.hafasTripId,
status.journey.line.name,
status.journey.origin.station.trwlId!.toString()
);

if ('trwlId' in tripData) {
Expand All @@ -80,20 +77,20 @@ export default async function Page({ params }: StatusPageProps) {

const arrivingAt = new Date(
status.journey.destination.arrival.planned!
).toISOString();
).getTime();
const departuringAt = new Date(
status.journey.origin.departure.planned!
).toISOString();
).getTime();

const destinationIndex = tripData.stopovers?.findLastIndex(
({ arrival, station }) =>
new Date(arrival.planned!).toISOString() === arrivingAt &&
new Date(arrival.planned!).getTime() === arrivingAt &&
station.trwlId === status.journey.destination.station.trwlId
);

const originIndex = tripData.stopovers?.findIndex(
({ departure, station }) =>
new Date(departure.planned!).toISOString() === departuringAt &&
new Date(departure.planned!).getTime() === departuringAt &&
station.trwlId === status.journey.origin.station.trwlId
);

Expand Down
5 changes: 2 additions & 3 deletions src/app/traewelling/trips/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { getServerSession } from 'next-auth';

export async function GET(request: Request) {
try {
const { hafasTripId, lineName, start } = getSafeURLParams({
const { hafasTripId, lineName } = getSafeURLParams({
url: request.url,
requiredParams: ['hafasTripId', 'lineName', 'start'],
requiredParams: ['hafasTripId', 'lineName'],
});

const session = await getServerSession(authOptions);
Expand All @@ -23,7 +23,6 @@ export async function GET(request: Request) {
const data = await TraewellingSdk.trains.trip({
hafasTripId,
lineName,
start,
});

return createResponse({
Expand Down
11 changes: 5 additions & 6 deletions src/components/CheckIn/CheckIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { useCurrentStatus } from '@/hooks/useCurrentStatus/useCurrentStatus';
import useUmami from '@/hooks/useUmami/useUmami';
import { CheckinInput } from '@/traewelling-sdk/functions/trains';
import { Station, Stop } from '@/traewelling-sdk/types';
import { Station, Stopover } from '@/traewelling-sdk/types';
import { AboardTrip } from '@/types/aboard';
import { Session } from 'next-auth';
import { useSession } from 'next-auth/react';
Expand Down Expand Up @@ -49,12 +49,12 @@ const post = async (status: CheckinInput, session?: Session | null) => {
const CheckIn = () => {
const { data: session } = useSession();
const [departureTime, setDepartureTime] = useState<string>();
const [destination, setDestination] = useState<Stop>();
const [destination, setDestination] = useState<Stopover>();
const [error, setError] = useState<string>();
const [isOpen, setIsOpen] = useState(false);
const [message, setMessage] = useState('');
const [origin, setOrigin] =
useState<Pick<Station, 'id' | 'ibnr' | 'name' | 'rilIdentifier'>>();
useState<Station>();
const [query, setQuery] = useState('');
const [step, setStep] = useState<CheckInStep>('origin');
const [travelType, setTravelType] = useState(0);
Expand All @@ -73,10 +73,9 @@ const CheckIn = () => {
body: message,
business: travelType,
departure: trip?.departure?.planned!,
destination: destination!.evaIdentifier,
ibnr: true,
destination: destination!.id,
lineName: trip!.line.name,
start: trip?.departureStation?.ibnr!,
start: trip?.departureStation?.trwlId ?? -1,
tripId: trip!.hafasId!,
visibility: visibility,
},
Expand Down
6 changes: 3 additions & 3 deletions src/components/CheckIn/DestinationStep/DestinationStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const DestinationStep = () => {
trip?.hafasId ?? '',
trip?.line.name ?? '',
trip?.departure?.planned ?? '',
trip?.departureStation?.evaId?.toString() ?? ''
trip?.departureStation?.trwlId ?? -1,
);

const schedule = parseSchedule({
Expand Down Expand Up @@ -101,11 +101,11 @@ const DestinationStep = () => {
{stops.map((stop, index) => (
<li key={index}>
<Stop
arrivalAt={stop.arrival ?? stop.departure}
arrivalAt={stop.arrivalReal ?? stop.arrivalPlanned ?? stop.departureReal ?? stop.departurePlanned}
isCancelled={stop.cancelled}
isDelayed={
stop.isArrivalDelayed ||
(!stop.arrival && stop.isDepartureDelayed)
(!stop.arrivalReal && stop.isDepartureDelayed)
}
name={stop.name}
onClick={() => setDestination(stop)}
Expand Down
7 changes: 6 additions & 1 deletion src/components/CheckIn/FinalStep/FinalStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
MdOutlineGroups,
MdOutlineLockOpen,
MdOutlineLockPerson,
MdShield,
MdSwapCalls,
MdWorkOutline,
} from 'react-icons/md';
Expand Down Expand Up @@ -61,6 +62,10 @@ const VISIBILITIES = [
icon: <MdFingerprint size={18} />,
name: 'Nur angemeldete Personen',
},
{
icon: <MdShield size={18} />,
name: 'Nur vertrauten Personen',
},
];

const FinalStep = () => {
Expand All @@ -80,7 +85,7 @@ const FinalStep = () => {
} = useContext(CheckInContext);

const arrivalSchedule = parseSchedule({
actual: destination?.arrival,
actual: destination?.arrivalReal,
planned: destination?.arrivalPlanned!,
});

Expand Down
8 changes: 4 additions & 4 deletions src/components/CheckIn/OriginStep/OriginStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ const OriginStep = () => {
{stations && stations.length > 0 && (
<ul className={styles.stationList}>
{stations.map((station) => (
<li key={station.ibnr}>
<li key={station.id}>
<Station
name={station.name}
onClick={() => setOrigin(station)}
query={query}
rilIdentifier={station.rilIdentifier}
rilIdentifier={station.identifiers.filter(id => id.type === 'de_db_ril100')[0]?.identifier}
/>
</li>
))}
Expand Down Expand Up @@ -71,11 +71,11 @@ const OriginStep = () => {
{recentStations && recentStations.length > 0 && (
<ul className={styles.stationList}>
{recentStations.map((station) => (
<li key={station.ibnr}>
<li key={station.id}>
<Station
name={station.name}
onClick={() => setOrigin(station)}
rilIdentifier={station.rilIdentifier}
rilIdentifier={station.identifiers.filter(id => id.type === 'de_db_ril100')[0]?.identifier}
/>
</li>
))}
Expand Down
7 changes: 1 addition & 6 deletions src/components/CheckIn/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ const Search = () => {
simpleEvent('nearby_clicked');

const station = (await response.json()) as NearbyResponse;
setOrigin({
id: station.id,
ibnr: station.ibnr,
name: station.name,
rilIdentifier: station.rilIdentifier,
});
setOrigin(station);
});
};

Expand Down
4 changes: 2 additions & 2 deletions src/components/CheckIn/TripStep/TripStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const TripStep = () => {
}
}, [departures]);

const servesMethod = (method: AboardMethod) => servedMethods.includes(method);
const servesMethod = (method: AboardMethod) => servedMethods.length === 0 || servedMethods.includes(method);

const handleOnEarlierClick = () => {
if (isLoading) {
Expand Down Expand Up @@ -110,7 +110,7 @@ const TripStep = () => {
<span>{origin?.name}</span>
</button>

{servedMethods.length > 1 && (
{servedMethods && servedMethods.length > 1 && (
<section className={styles.filters}>
{(servesMethod('national') || servesMethod('national-express')) && (
<FilterButton
Expand Down
6 changes: 6 additions & 0 deletions src/components/CheckIn/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export const METHOD_ICONS: Record<
subway: ProductIcon.Subway,
taxi: ProductIcon.Other,
tram: ProductIcon.Tram,
aerial: ProductIcon.Other, // TODO: Add icon
airplane: ProductIcon.Other, // TODO: Add icon
funicular: ProductIcon.Other, // TODO: Add icon
_: ProductIcon.Other,
};

export const PRODUCT_ICONS: Record<
Expand All @@ -34,4 +38,6 @@ export const PRODUCT_ICONS: Record<
subway: ProductIcon.Subway,
taxi: ProductIcon.Other,
tram: ProductIcon.Tram,
freightTrain: ProductIcon.Other,
plane: ProductIcon.Other, // TODO: Add icon
};
12 changes: 5 additions & 7 deletions src/components/CheckIn/types.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import { Station, Stop } from '@/traewelling-sdk/types';
import { Station, Stopover } from '@/traewelling-sdk/types';
import { AboardStatus, AboardTrip } from '@/types/aboard';

export type CheckInContextValue = {
checkIn: () => void;
currentStatus: AboardStatus | null | undefined;
departureTime: string | undefined;
destination: Stop | undefined;
destination: Stopover | undefined;
error: string | undefined; // TODO: Temporary solution
goBack: () => void;
isOpen: boolean;
message: string;
origin: Pick<Station, 'id' | 'ibnr' | 'name' | 'rilIdentifier'> | undefined;
origin: Station | undefined;
query: string;
setDepartureTime: (value: string | undefined) => void;
setDestination: (value: Stop | undefined) => void;
setDestination: (value: Stopover | undefined) => void;
setIsOpen: (value: boolean) => void;
setMessage: (value: string) => void;
setOrigin: (
value: Pick<Station, 'id' | 'ibnr' | 'name' | 'rilIdentifier'> | undefined
) => void;
setOrigin: (value: Station | undefined) => void;
setQuery: (value: string) => void;
setTravelType: (value: number) => void;
setTrip: (value: AboardTrip | undefined) => void;
Expand Down
6 changes: 3 additions & 3 deletions src/components/Profile/Statuses/Statuses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const Statuses = ({ username }: { username: string }) => {
return (
<div>
{statuses?.map(
({ id, username, profilePicture, body, likes, liked, train }) => {
({ id, user, body, likes, liked, checkin }) => {
return (
<div key={id}>
<div>{username}</div>
<div>{train.lineName}</div>
<div>{user.username}</div>
<div>{checkin.lineName}</div>
<div>{body}</div>
<div>{likes}</div>
<div>{liked && '❤️'}</div>
Expand Down
8 changes: 4 additions & 4 deletions src/components/TripSelector/TripSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ const Trip = ({ onClick, requestedStationName, trip }: TripProps) => {

const isTimeDocked = isCancelled || departsFromDeviatingStation;

const fr = trip.hafasId?.match(/#FR#(\d+)#/)?.[1];
const to = trip.hafasId?.match(/#TO#(\d+)#/)?.[1];
// const fr = trip.hafasId?.match(/#FR#(\d+)#/)?.[1];
// const to = trip.hafasId?.match(/#TO#(\d+)#/)?.[1];

return (
<ThemeProvider appearance={trip.line.appearance}>
Expand Down Expand Up @@ -129,9 +129,9 @@ const Trip = ({ onClick, requestedStationName, trip }: TripProps) => {
)}
</div>
</button>
<p className={styles.stationIds}>
{/*<p className={styles.stationIds}>
{fr}, {to}
</p>
</p>*/}
</ThemeProvider>
);
};
12 changes: 12 additions & 0 deletions src/helpers/getLineTheme/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,16 @@ export const PRODUCT_THEMES: Record<HAFASProductType, Required<Theme>> = {
contrast: '#FFFFFF',
contrastRGB: '255, 255, 255',
},
freightTrain: {
accent: '#415A77',
accentRGB: '65, 90, 119',
contrast: '#FFFFFF',
contrastRGB: '255, 255, 255',
},
plane: { // TODO: Create proper color scheme
accent: '#A3007C',
accentRGB: '163, 0, 124',
contrast: '#FFFFFF',
contrastRGB: '255, 255, 255',
},
};
8 changes: 4 additions & 4 deletions src/helpers/getStopsAfter.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Stop } from '@/traewelling-sdk/types';
import { Stopover } from '@/traewelling-sdk/types';

export const getStopsAfter = (
plannedDeparture: string,
stationId: string,
stops: Stop[]
stationId: number,
stops: Stopover[]
) => {
const after = new Date(plannedDeparture).toISOString();

const startingAt = stops.findIndex(
({ departurePlanned, id }) =>
after === new Date(departurePlanned!).toISOString() &&
stationId === id.toString()
stationId === id
);

return stops.slice(typeof startingAt === 'undefined' ? 0 : startingAt + 1);
Expand Down
Loading