import React, { useState, useEffect } from 'react'; import Sidebar from './Sidebar.tsx'; import Header from './Header.tsx'; import Dashboard from './Dashboard.tsx'; import SrsDocument from './SrsDocument.tsx'; import AuthPage from './auth/AuthPage.tsx'; import MobileAppPage from './MobileAppPage.tsx'; import LocationManagementPage from './LocationManagementPage.tsx'; import CameraManagementPage from './CameraManagementPage.tsx'; import ChickenCountingPage from './ChickenCountingPage.tsx'; import DataManagementPage from './counting/DataManagementPage.tsx'; import FeedSackCountingPage from './FeedSackCountingPage.tsx'; import BehaviorAnalysisPage from './BehaviorAnalysisPage.tsx'; import WeightMonitoringPageRevamped from './WeightMonitoringPageRevamped.tsx'; import IotDeviceManagementPage from './IotDeviceManagementPage.tsx'; import NetworkManagementPage from './NetworkManagementPage.tsx'; import BatchProcessPage from './BatchProcessPage.tsx'; import UserManagementPage from './UserManagementPage.tsx'; import ProfilePage from './ProfilePage.tsx'; import MultiCoopWeightPage from './MultiCoopWeightPage.tsx'; import FeedWastagePage from './FeedWastagePage.tsx'; import FeedSchedulingPage from './FeedSchedulingPage.tsx'; import FcrDashboardPage from './FcrDashboardPage.tsx'; import EefDashboardPage from './EefDashboardPage.tsx'; import PrdDocument from './PrdDocument.tsx'; import TodoDocument from './TodoDocument.tsx'; import ErpIntegrationPage from './ErpIntegrationPage.tsx'; import VetVisitPage from './VetVisitPage.tsx'; import OcrProcessingPage from './OcrProcessingPage.tsx'; import CycleTimeline from './CycleTimeline.tsx'; import WeightStandardPage from './WeightStandardPage.tsx'; import CobbStandardPage from './CobbStandardPage.tsx'; import SlidesPage from './SlidesPage.tsx'; import IotPanelPage from './IotPanelPage.tsx'; import SettingsPage from './SettingsPage.tsx'; import { useAppContext } from '../context/AppContext.tsx'; import { View } from '../types.ts'; import { Kandang } from '../types/counting.ts'; import { apiClient } from '../services/apiService.ts'; interface AppContentProps { selectedKandangId: number | null; setSelectedKandangId: (id: number | null) => void; selectedArea: string; setSelectedArea: (area: string) => void; kandangs: Kandang[]; setKandangs: (kandangs: Kandang[]) => void; } const AppContent: React.FC = ({ selectedKandangId, setSelectedKandangId, selectedArea, setSelectedArea, kandangs, setKandangs, }) => { const { currentUser, kpis, isLoadingData, cycleData } = useAppContext(); const [view, setView] = useState('dashboard'); const [isSidebarCollapsed, setIsSidebarCollapsed] = useState(false); const [isTimelineVisible, setIsTimelineVisible] = useState(false); const toggleSidebar = () => { setIsSidebarCollapsed(!isSidebarCollapsed); }; const toggleTimelineVisibility = () => { setIsTimelineVisible((prev) => !prev); }; // Fetch kandangs when cycle changes OR when view changes (to pick up updates) useEffect(() => { const loadKandangs = async () => { if (!cycleData?.id) return; try { const data = await apiClient.getKandangsByCycle(cycleData.id); setKandangs(data); } catch (error) { console.error('Failed to load kandangs:', error); } }; loadKandangs(); }, [cycleData?.id, view, setKandangs]); // Added 'view' dependency to reload when navigating // Auto-select first kandang when kandangs load useEffect(() => { const firstKandang = kandangs[0]; if (firstKandang && selectedKandangId === null) { setSelectedKandangId(firstKandang.id); } }, [kandangs, selectedKandangId, setSelectedKandangId]); if (!currentUser) { return ; } const renderView = () => { switch (view) { case 'dashboard': return ( ); case 'srs': return ; case 'prd': return ; case 'todo': return ; case 'mobileApp': return ; case 'locationManagement': return ; case 'cameraManagement': return ; case 'chickenCounting': return ; case 'dataManagement': return ; case 'feedSackCounting': return ; case 'behaviorAnalysis': return ; case 'weightMonitoring': return ; case 'weightStandard': return ; case 'cobbStandard': return ; case 'iotDeviceManagement': return ; case 'iotPanel': return ; case 'kandangSettings': return ; case 'networkManagement': return ; case 'batchProcess': return ; case 'userManagement': return ; case 'profile': return ; case 'multiCoopWeight': return ; case 'feedWastage': return ; case 'feedScheduling': return ; case 'fcrDashboard': return ; case 'eefDashboard': return ; case 'erpIntegration': return ; case 'vetVisit': return ; case 'ocrProcessing': return ; case 'slides': return ; default: return ( ); } }; return (
{isTimelineVisible && view !== 'slides' && (
)}
{renderView()}
{/* Global Loading Overlay */} {isLoadingData && (
{/* Spinning loader */}

Memuat Data...

Mohon tunggu sebentar

)}
); }; export default AppContent;