digitransit-ui/app/component/itinerary/ItineraryPageContainer.js
Vesa Meskanen 3f2fa2ae0b feat: move all itinerary page related components to a dedicated folder
Also:
- Move generic Toggle to componentfolder root
- Remove dead styles
- Refactor some componets
2024-04-22 08:49:15 +03:00

47 lines
1.4 KiB
JavaScript

import React, { useEffect, useState, lazy, Suspense } from 'react';
import { ReactRelayContext } from 'react-relay';
import { connectToStores } from 'fluxible-addons-react';
import Loading from '../Loading';
import withBreakpoint from '../../util/withBreakpoint';
import { getMapLayerOptions } from '../../util/mapLayerUtils';
const ItineraryPage = lazy(() => import('./ItineraryPage'));
const ItineraryPageWithBreakpoint = withBreakpoint(props => (
<ReactRelayContext.Consumer>
{({ environment }) => (
<ItineraryPage {...props} relayEnvironment={environment} />
)}
</ReactRelayContext.Consumer>
));
const ItineraryPageWithStores = connectToStores(
ItineraryPageWithBreakpoint,
['MapLayerStore'],
({ getStore }) => ({
mapLayers: getStore('MapLayerStore').getMapLayers({
notThese: ['stop', 'citybike', 'vehicles'],
}),
mapLayerOptions: getMapLayerOptions({
lockedMapLayers: ['vehicles', 'citybike', 'stop'],
selectedMapLayers: ['vehicles'],
}),
}),
);
export default function ItineraryPageContainer(props) {
const [isClient, setClient] = useState(false);
useEffect(() => {
// To prevent SSR from rendering something https://reactjs.org/docs/react-dom.html#hydrate
setClient(true);
});
if (!isClient) {
return <Loading />;
}
return (
<Suspense fallback={<Loading />}>
<ItineraryPageWithStores {...props} />
</Suspense>
);
}