BUGFIX: Refactor map loading to use a dedicated loading component and improve dynamic import handling

This commit is contained in:
2025-09-16 16:35:25 +02:00
parent 029b091b10
commit e4a4261a0e

View File

@@ -9,6 +9,20 @@ import Button from "@/components/ui/Button";
import { mapLayers } from "@/components/ui/mapLayers"; import { mapLayers } from "@/components/ui/mapLayers";
import { formatProjectStatus } from "@/lib/utils"; import { formatProjectStatus } from "@/lib/utils";
// Loading component that can access translations
function MapLoadingComponent({ t }) {
return (
<div className="w-full h-96 bg-gray-100 animate-pulse rounded-lg flex items-center justify-center">
<span className="text-gray-500">{t ? t('map.loadingMap') : 'Loading map...'}</span>
</div>
);
}
// Dynamically import the map component to avoid SSR issues
const DynamicMap = dynamic(() => import("@/components/ui/LeafletMap"), {
ssr: false,
});
function ProjectsMapPageContent() { function ProjectsMapPageContent() {
const searchParams = useSearchParams(); const searchParams = useSearchParams();
const router = useRouter(); const router = useRouter();
@@ -29,15 +43,16 @@ function ProjectsMapPageContent() {
const [showLayerPanel, setShowLayerPanel] = useState(true); const [showLayerPanel, setShowLayerPanel] = useState(true);
const [currentTool, setCurrentTool] = useState("move"); // Current map tool const [currentTool, setCurrentTool] = useState("move"); // Current map tool
// Dynamically import the map component to avoid SSR issues // Wrapper component for the map with proper loading state
const DynamicMap = dynamic(() => import("@/components/ui/LeafletMap"), { const MapWrapper = React.useMemo(() => {
ssr: false, return function MapWrapperComponent(props) {
loading: () => ( return (
<div className="w-full h-96 bg-gray-100 animate-pulse rounded-lg flex items-center justify-center"> <Suspense fallback={<MapLoadingComponent t={t} />}>
<span className="text-gray-500">{t('map.loadingMap')}</span> <DynamicMap {...props} />
</div> </Suspense>
), );
}); };
}, [t]);
// Status configuration with colors and labels // Status configuration with colors and labels
const statusConfig = { const statusConfig = {
@@ -920,7 +935,7 @@ function ProjectsMapPageContent() {
</div> </div>
) : ( ) : (
<div className="absolute inset-0"> <div className="absolute inset-0">
<DynamicMap <MapWrapper
center={mapCenter} center={mapCenter}
zoom={mapZoom} zoom={mapZoom}
markers={markers} markers={markers}