Skip to content

Commit

Permalink
chore: remove mgate functionality (#1004)
Browse files Browse the repository at this point in the history
* chore: remove mgate functionality

* chore: unneccesary swcWorkarounds

* chore: remove even more legacy hafas

* chore: remove rest of legacy hafas

* chore: last traces of old hafas

* fix: routing Jetzt for url with 0

* fix: metrics
  • Loading branch information
marudor authored Jan 14, 2025
1 parent 7d5c7dd commit 58f9a99
Show file tree
Hide file tree
Showing 130 changed files with 549 additions and 5,302 deletions.
3 changes: 2 additions & 1 deletion app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ const vinxiConfig = defineConfig({
maxAge: 60 * 60 * 24 * 360,
},
],
plugins: ['./src/server/admin/nitroPlugin.ts'],
plugins: ['./src/server/admin/index.ts'],
commonJS: {
include: ['dom-helpers', 'maplibre-gl'],
},
experimental: {
legacyExternals: true,
asyncContext: true,
},
},
tsr: {
Expand Down
8 changes: 8 additions & 0 deletions cypress/e2e/routing/routing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ describe('Routing', () => {
);
});

it('with start, destination & time = 0', () => {
cy.visit('/routing/8000105/8002549/0');
searchInput('routingStartSearch', 'Frankfurt(Main)Hbf');
searchInput('routingDestinationSearch', 'Hamburg Hbf');
searchInput('addVia', '');
cy.findByTestId('routingDatePicker').should('contain.value', 'Jetzt');
});

it('with start, destination, time & 1 via', () => {
cy.visit('/routing/8000105/8002549/2020-11-17T10:00:15.589Z/8000244|');
searchInput('routingStartSearch', 'Frankfurt(Main)Hbf');
Expand Down
4 changes: 1 addition & 3 deletions cypress/fixtures/details/ICE720.json
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,7 @@
"admin": "80",
"line": "41",
"transportType": "HIGH_SPEED_TRAIN",
"operator": {
"name": "DB"
}
"operator": "DB"
},
"type": "JNY",
"currentStop": {
Expand Down
5 changes: 1 addition & 4 deletions cypress/fixtures/details/S6.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
"admin": "800337",
"number": "30665",
"type": "S",
"operator": {
"name": "DB Regio AG NRW",
"icoX": 2
}
"operator": "DB Regio AG NRW"
},
"segmentStart": {
"name": "Köln-Nippes",
Expand Down
30 changes: 0 additions & 30 deletions scripts/clearCorruptCache.ts

This file was deleted.

11 changes: 5 additions & 6 deletions src/bahnde/journeyDetails/journeyDetails.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { mapFahrt } from '@/bahnde/journeyDetails/parseJourneyDetails';
import { addRandomBrowserUseragent } from '@/bahnde/randomUseragent';
import { axiosUpstreamInterceptor } from '@/server/admin';
import { Cache, CacheDatabase } from '@/server/cache';
import { CacheDatabase, getCache } from '@/server/cache';
import { logger } from '@/server/logger';
import type { ParsedSearchOnTripResponse } from '@/types/HAFAS/SearchOnTrip';
import type { JourneyResponse } from '@/types/journey';

import axios from 'axios';
import { v4 } from 'uuid';

Expand All @@ -21,13 +22,11 @@ journeyDetailsAxios.interceptors.request.use((req) => {
});
axiosUpstreamInterceptor(journeyDetailsAxios, 'bahn.de-journeyDetails');

const quickJourneyDetailsCache = new Cache<ParsedSearchOnTripResponse>(
CacheDatabase.BahnDEJourneyDetails,
);
const quickJourneyDetailsCache = getCache(CacheDatabase.BahnDEJourneyDetails);

export const bahnJourneyDetails = async (
jid: string,
): Promise<ParsedSearchOnTripResponse | undefined> => {
): Promise<JourneyResponse | undefined> => {
try {
if (await quickJourneyDetailsCache.exists(jid)) {
return quickJourneyDetailsCache.get(jid);
Expand Down
4 changes: 2 additions & 2 deletions src/bahnde/journeyDetails/parseJourneyDetails.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { mapHalt } from '@/bahnde/parsing';
import type { BahnDEFahrt } from '@/bahnde/types';
import type { ParsedSearchOnTripResponse } from '@/types/HAFAS/SearchOnTrip';
import type { JourneyResponse } from '@/types/journey';

export async function mapFahrt(
input?: BahnDEFahrt,
): Promise<ParsedSearchOnTripResponse | undefined> {
): Promise<JourneyResponse | undefined> {
if (!input) {
return undefined;
}
Expand Down
6 changes: 2 additions & 4 deletions src/bahnde/occupancy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { routing } from '@/bahnde/routing/routing';
import { searchStopPlace } from '@/server/StopPlace/search';
import { Cache, CacheDatabase } from '@/server/cache';
import { CacheDatabase, getCache } from '@/server/cache';
import { timezone } from '@/timezone';
import type {
RouteAuslastung,
Expand Down Expand Up @@ -59,9 +59,7 @@ async function getRelevantTrip(
return relevantTrip;
}

const stopOccupancyCache = new Cache<RouteAuslastung | undefined>(
CacheDatabase.HafasStopOccupancy,
);
const stopOccupancyCache = getCache(CacheDatabase.HafasStopOccupancy);

const createBaseCacheKey = (
trainNumber: string,
Expand Down
2 changes: 1 addition & 1 deletion src/bahnde/parsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import type {
BahnDERoutingAbschnitt,
} from '@/bahnde/types';
import { getStopPlaceByEva } from '@/server/StopPlace/search';
import type { CommonStopInfo } from '@/types/HAFAS';
import {
AuslastungsValue,
type RouteAuslastung,
type RouteStop,
} from '@/types/routing';
import type { CommonStopInfo } from '@/types/stopPlace';
import { tz } from '@date-fns/tz';
import { differenceInMinutes, parseISO } from 'date-fns';

Expand Down
21 changes: 6 additions & 15 deletions src/bahnde/routing/parseRouting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ import type {
} from '@/bahnde/types';
import { TransportType } from '@/external/types';
import { getStopPlaceByEva } from '@/server/StopPlace/search';
import type { HafasStation, ParsedProduct } from '@/types/HAFAS';
import type { CommonProductInfo } from '@/types/journey';
import type {
RouteJourneySegment,
RouteJourneySegmentTrain,
RouteJourneySegmentWalk,
RoutingResult,
RoutingStopPlace,
SingleRoute,
} from '@/types/routing';
import { differenceInMilliseconds, differenceInMinutes } from 'date-fns';

const mapWalkSegmentStartDestination = async (
input: BahnDERoutingAbschnitt,
prefix: 'ankunfts' | 'abfahrts',
): Promise<HafasStation> => {
): Promise<RoutingStopPlace> => {
let evaNumber = input[`${prefix}OrtExtId`];
if (evaNumber.startsWith('0')) {
evaNumber = evaNumber.substring(1);
Expand All @@ -36,35 +37,25 @@ const mapWalkSegmentStartDestination = async (
return {
name: input[`${prefix}Ort`],
evaNumber,
// TODO: make this optional
coordinates: {
lat: 0,
lng: 0,
},
};
}
return {
coordinates: {
lat: risStopPlace.position?.latitude || 0,
lng: risStopPlace.position?.longitude || 0,
},
position: risStopPlace.position,
evaNumber,
name: risStopPlace.name,
ril100: risStopPlace.ril100,
};
};

const mapProduct = (input: BahnDEVerkehrsmittel): ParsedProduct => {
const mapProduct = (input: BahnDEVerkehrsmittel): CommonProductInfo => {
return {
name: input.langText || input.mittelText || input.name,
line: input.linienNummer,
// TODO:
transportType: TransportType.Unknown,
number: input.nummer === input.linienNummer ? '0' : input.nummer,
type: input.kurzText || input.kategorie,
operator: {
name: input.zugattribute?.filter((a) => a.key === 'BEF').join(', '),
},
operator: input.zugattribute?.filter((a) => a.key === 'BEF').join(', '),
};
};

Expand Down
12 changes: 4 additions & 8 deletions src/client/Abfahrten/Components/ExtraMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ import { useCallback, useState } from 'react';
import type { FC, SyntheticEvent } from 'react';
import { FilterModal } from './FilterModal';

interface Props {
favKey: 'regionalFavs' | 'favs';
}

export const ExtraMenu: FC<Props> = ({ favKey }) => {
export const ExtraMenu: FC = () => {
const setFilterOpen = useAbfahrtenFilterOpen();
const currentStopPlace = useCurrentAbfahrtenStopPlace();
const { data: lageplan } = trpc.stopPlace.lageplan.useQuery(
Expand All @@ -31,9 +27,9 @@ export const ExtraMenu: FC<Props> = ({ favKey }) => {
staleTime: Number.POSITIVE_INFINITY,
},
);
const favs = useFavs(favKey);
const fav = useFavAction(favKey);
const unfav = useUnfavAction(favKey);
const favs = useFavs();
const fav = useFavAction();
const unfav = useUnfavAction();
const isFaved = Boolean(currentStopPlace && favs[currentStopPlace.evaNumber]);
const [anchor, setAnchor] = useState<undefined | HTMLElement>();
const toggleFav = useCallback(() => {
Expand Down
10 changes: 5 additions & 5 deletions src/client/Abfahrten/Components/FavEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const UnclickablePaper = styled(BasePaper)`

interface Props {
fav: MinimalStopPlace;
favKey?: 'regionalFavs' | 'favs';
'data-testid'?: string;
noDelete?: boolean;
}

interface FavEntryDisplayProps {
Expand Down Expand Up @@ -75,14 +75,14 @@ export const FavEntryDisplay: FC<FavEntryDisplayProps> = ({
export const FavEntry: FC<Props> = ({
fav,
'data-testid': testid = 'favEntry',
favKey,
noDelete,
}) => {
const unfav = useUnfavAction(favKey);
const unfav = useUnfavAction();
const deleteFav = useCallback(
(e: MouseEvent) => {
e.stopPropagation();
e.preventDefault();
unfav?.(fav);
unfav(fav);
},
[fav, unfav],
);
Expand All @@ -98,7 +98,7 @@ export const FavEntry: FC<Props> = ({
>
<FavEntryDisplay
text={fav.name}
deleteFav={favKey ? deleteFav : undefined}
deleteFav={noDelete ? undefined : deleteFav}
/>
</Link>
);
Expand Down
9 changes: 4 additions & 5 deletions src/client/Abfahrten/Components/FavList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ import { FavEntry, FavEntryDisplay } from './FavEntry';

interface Props {
children?: ReactNode;
favKey: 'regionalFavs' | 'favs';
mostUsed?: boolean;
}

export const FavList: FC<Props> = ({ children, favKey, mostUsed }) => {
const favs = useFavs(favKey);
export const FavList: FC<Props> = ({ children, mostUsed }) => {
const favs = useFavs();
const sortedFavs = useMemo(() => {
const values: MinimalStopPlace[] = Object.values(favs);

return values
.sort((a, b) => (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1))
.map((fav) => <FavEntry favKey={favKey} key={fav.evaNumber} fav={fav} />);
}, [favs, favKey]);
.map((fav) => <FavEntry key={fav.evaNumber} fav={fav} />);
}, [favs]);
const { updateTitle, updateDescription, updateKeywords } =
useHeaderTagsActions();

Expand Down
2 changes: 1 addition & 1 deletion src/client/Abfahrten/Components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const Header: FC<Props> = ({ regional = false }: Props) => {
<Refresh />
</IconButton>
)}
<ExtraMenu favKey={regional ? 'regionalFavs' : 'favs'} />
<ExtraMenu />
</BaseHeader>
);
};
7 changes: 6 additions & 1 deletion src/client/Abfahrten/Components/MostUsed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ export const MostUsed: FC = () => {
return (
<>
{mostUsed.map((m) => (
<FavEntry data-testid="mostUsedEntry" key={m.evaNumber} fav={m} />
<FavEntry
data-testid="mostUsedEntry"
key={m.evaNumber}
fav={m}
noDelete
/>
))}
</>
);
Expand Down
33 changes: 13 additions & 20 deletions src/client/Abfahrten/hooks/useFavs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@ import type { MinimalStopPlace } from '@/types/stopPlace';
import { useCallback } from 'react';

export type Favs = Record<string, MinimalStopPlace>;
export const useFavs = (key?: 'favs' | 'regionalFavs') => {
const [cookies] = useExpertCookies([key!]);
if (!key) {
return {};
}
const savedFavs = cookies[key];
export const useFavs = () => {
const [cookies] = useExpertCookies(['favs']);
const savedFavs = cookies.favs;

return savedFavs || {};
};

export const useFavAction = (key: 'favs' | 'regionalFavs') => {
const [_, setCookie] = useExpertCookies([key]);
const favs = useFavs(key);
export const useFavAction = () => {
const [_, setCookie] = useExpertCookies(['favs']);
const favs = useFavs();

return useCallback(
(stopPlace: MinimalStopPlace) => {
Expand All @@ -26,28 +23,24 @@ export const useFavAction = (key: 'favs' | 'regionalFavs') => {
evaNumber: stopPlace.evaNumber,
},
};
setCookie(key, newFavs);
setCookie('favs', newFavs);
return newFavs;
},
[setCookie, favs, key],
[setCookie, favs],
);
};

export const useUnfavAction = (key?: 'favs' | 'regionalFavs') => {
const [_, setCookie] = useExpertCookies([key!]);
const favs = useFavs(key);
export const useUnfavAction = () => {
const [_, setCookie] = useExpertCookies(['favs']);
const favs = useFavs();

return useCallback(
(stopPlace: MinimalStopPlace) => {
if (!key) {
return undefined;
}

delete favs[stopPlace.evaNumber];
const newFavs = { ...favs };
setCookie(key, newFavs);
setCookie('favs', newFavs);
return newFavs;
},
[key, favs, setCookie],
[favs, setCookie],
);
};
Loading

0 comments on commit 58f9a99

Please sign in to comment.