Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: mab <[email protected]>
  • Loading branch information
dtrucs and mabhub committed Aug 29, 2024
1 parent 6df4974 commit 4b7da51
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react';
import L from 'leaflet';
import SVG from 'react-inlinesvg';
import { GeoJsonProperties, Geometry } from 'geojson';
Expand All @@ -12,16 +13,23 @@ type Props = {
id: string;
};

const Icon = ({ pictogramUri }: { pictogramUri: string }) => {
const Icon = React.memo(function Icon({ pictogramUri, ...props }: { pictogramUri: string }) {
if (!pictogramUri) {
return null;
}
return pictogramUri.endsWith('.svg') ? (
<SVG src={pictogramUri} className="size-6" preProcessor={optimizeAndDefineColor()} />
) : (
<Image loading="lazy" src={pictogramUri} width={16} height={16} alt="" />
);
};

if (pictogramUri.endsWith('.svg')) {
return (
<SVG
src={pictogramUri}
className="size-6"
preProcessor={optimizeAndDefineColor()}
{...props}
/>
);
}
return <Image loading="lazy" src={pictogramUri} width={16} height={16} alt="" {...props} />;
});

const MetaData = ({ properties }: { properties: GeoJsonProperties }) => {
if (properties === null || !properties.name) {
Expand All @@ -34,7 +42,7 @@ const MetaData = ({ properties }: { properties: GeoJsonProperties }) => {
<span className="flex flex-wrap items-center gap-2">
{Boolean(properties.category?.label) && (
<>
{Boolean(pictogramUri) && <Icon pictogramUri={pictogramUri} />}
<Icon pictogramUri={pictogramUri} />
<span>{properties.category.label}</span>
</>
)}
Expand Down

0 comments on commit 4b7da51

Please sign in to comment.