Skip to content

Commit

Permalink
chore: remove mgate functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
marudor committed Jan 13, 2025
1 parent 7d5c7dd commit 3afeb53
Show file tree
Hide file tree
Showing 82 changed files with 290 additions and 4,482 deletions.
30 changes: 0 additions & 30 deletions scripts/clearCorruptCache.ts

This file was deleted.

6 changes: 2 additions & 4 deletions src/bahnde/journeyDetails/journeyDetails.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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 axios from 'axios';
Expand All @@ -21,9 +21,7 @@ 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,
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
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],
);
};
1 change: 0 additions & 1 deletion src/client/Common/Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const setCookieOptions: CookieSetOptions = {

export interface WebConfigMap extends CommonConfig, RoutingSettings {
readonly selectedDetail: string;
readonly regionalFavs: Favs;
readonly favs: Favs;
readonly rfavs: RoutingFavs;
readonly defaultFilter: string[];
Expand Down
26 changes: 0 additions & 26 deletions src/client/Routing/Components/Search/BC100Disclaimer.tsx

This file was deleted.

38 changes: 0 additions & 38 deletions src/client/Routing/Components/Search/NetzcardDisclaimer.tsx

This file was deleted.

Loading

0 comments on commit 3afeb53

Please sign in to comment.