import React from 'react'; import { ConnectionStatus } from '../hooks/useRealTimeData'; interface StatusIndicatorProps { isConnected: boolean; connectionStatus?: ConnectionStatus; dataSource: 'websocket' | 'polling'; lastUpdate?: string; className?: string; error?: string | null; retryCount?: Map; } const StatusIndicator: React.FC = ({ isConnected, connectionStatus, dataSource, lastUpdate, className = '', error, retryCount }) => { const getStatusColor = () => { if (connectionStatus) { switch (connectionStatus) { case 'connected': return 'text-green-600'; case 'connecting': return 'text-yellow-600'; case 'retrying': return 'text-orange-600'; case 'error': case 'disconnected': return 'text-red-600'; default: return 'text-gray-600'; } } if (!isConnected) return 'text-red-600'; return dataSource === 'websocket' ? 'text-green-600' : 'text-yellow-600'; }; const getStatusText = () => { if (connectionStatus) { switch (connectionStatus) { case 'connected': return '연결됨'; case 'connecting': return '연결 중...'; case 'retrying': return '재시도 중...'; case 'error': return '연결 오류'; case 'disconnected': return '연결 끊김'; default: return '알 수 없음'; } } if (!isConnected) return '연결 끊김'; return dataSource === 'websocket' ? '실시간 연결' : '폴링 모드'; }; const getStatusIcon = () => { if (connectionStatus) { switch (connectionStatus) { case 'connected': return ( ); case 'connecting': case 'retrying': return ( ); case 'error': case 'disconnected': return ( ); default: return ( ); } } if (dataSource === 'websocket') { return ( ); } return ( ); }; const getDataSourceText = () => { return dataSource === 'websocket' ? 'WebSocket' : '폴링'; }; const getRetryInfo = () => { if (!retryCount || retryCount.size === 0) return null; const totalRetries = Array.from(retryCount.values()).reduce((sum, count) => sum + count, 0); if (totalRetries === 0) return null; return (
재시도: {totalRetries}회
); }; return (
{/* 연결 상태 */}
{getStatusIcon()} {getStatusText()}
{/* 데이터 소스 */}
{getDataSourceText()}
{/* 재시도 정보 */} {getRetryInfo()} {/* 마지막 업데이트 */} {lastUpdate && (
마지막 업데이트: {new Date(lastUpdate).toLocaleTimeString()}
)} {/* 에러 메시지 */} {error && (
{error}
)}
); }; export default StatusIndicator;