Skip to content

Commit

Permalink
perf(components): ⚡ Use next/dynamic to dynamically load components
Browse files Browse the repository at this point in the history
  • Loading branch information
Nudelsuppe42 committed Jan 21, 2024
1 parent 1bc2d43 commit 63b30d6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Binary file removed public/fonts/Inter.var.latin.woff2
Binary file not shown.
11 changes: 11 additions & 0 deletions src/components/dynamic/Map.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import dynamic from 'next/dynamic';

export const DynamicMap = dynamic(() => import('../map/Map'), {
ssr: false,
});
export const DynamicClaimDrawer = dynamic(() =>
import('../map/ClaimDrawer').then((mod) => mod.ClaimDrawer),
);
export const DynamicMapContextMenu = dynamic(() =>
import('../map/MapContextMenu').then((mod) => mod.MapContextMenu),
);
11 changes: 8 additions & 3 deletions src/pages/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { Spotlight, spotlight } from '@mantine/spotlight';
import { IconPin, IconSearch } from '@tabler/icons-react';
import { useEffect, useState } from 'react';
import { ContextMenu, useContextMenu } from '../../components/ContextMenu';
import {
DynamicClaimDrawer,
DynamicMap,
DynamicMapContextMenu,
} from '../../components/dynamic/Map';
import Map, { mapClickEvent, mapCopyCoordinates, mapCursorHover } from '../../components/map/Map';

import mapboxgl from 'mapbox-gl';
Expand Down Expand Up @@ -90,7 +95,7 @@ const MapPage: NextPage = () => {
title="Map"
description="Explore the progress that has been made in the BuildTheEarth Project."
>
<ClaimDrawer open={opened} setOpen={setOpened} id={selected} map={map} t={t} />
<DynamicClaimDrawer open={opened} setOpen={setOpened} id={selected} map={map} t={t} />
<Spotlight
filter={(query, actions) => actions}
actions={searchActions}
Expand All @@ -113,14 +118,14 @@ const MapPage: NextPage = () => {
}
}}
/>
<MapContextMenu
<DynamicMapContextMenu
contextMenuInfo={state}
setContextMenuInfo={setState}
oLat={clientPos.lat}
oLng={clientPos.lng}
/>
<div style={{ height: '96vh', width: '100%', position: 'relative' }}>
<Map
<DynamicMap
src={`${process.env.NEXT_PUBLIC_API_URL}/claims/geojson?active=true`}
onContextMenu={contextHandler}
onMapLoaded={(map) => {
Expand Down

0 comments on commit 63b30d6

Please sign in to comment.