diff --git a/frontend/src/pages/Facility3DViewerPage.tsx b/frontend/src/pages/Facility3DViewerPage.tsx index 683c519..5921690 100644 --- a/frontend/src/pages/Facility3DViewerPage.tsx +++ b/frontend/src/pages/Facility3DViewerPage.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState, Suspense, useRef, useMemo } from 'react'; +import { useEffect, useState, Suspense, useRef, useMemo, Component, ReactNode } from 'react'; import { Canvas, useFrame } from '@react-three/fiber'; import { OrbitControls, Text, Instances, Instance, Html } from '@react-three/drei'; import { layoutApi, Floor3DData } from '../lib/layoutApi'; @@ -17,49 +17,211 @@ const COLORS = { ROOM_WALL: '#374151', // gray-700 }; -function PlantInstances({ positions, onPlantClick }: { positions: any[], onPlantClick: (p: any) => void }) { - if (!positions || positions.length === 0) return null; +// Define State interface +interface ErrorBoundaryState { + hasError: boolean; + error: Error | null; +} - const plants = positions.filter(p => p.plant); - const emptySlots = positions.filter(p => !p.plant); +class ErrorBoundary extends Component<{ children: ReactNode }, ErrorBoundaryState> { + constructor(props: { children: ReactNode }) { + super(props); + this.state = { hasError: false, error: null }; + } + + static getDerivedStateFromError(error: Error): ErrorBoundaryState { + return { hasError: true, error }; + } + + render() { + if (this.state.hasError) { + console.error("3D Viewer Error Caught:", this.state.error); + return ( + +
{this.state.error?.message}
++ {floorData ? `${floorData.floor.name} • ${floorData.stats.occupiedPositions} Plants` : 'Loading...'} +
+{status}
+