Add React frontend for energy trading system
Implements React + TypeScript UI with Vite and Tailwind CSS. Features dashboard with real-time WebSocket updates, backtesting page, model management interface, trading controls, and settings. Includes state management with Zustand, API integration with Axios/TanStack Query, and interactive charts with Recharts.
This commit is contained in:
21
frontend/src/hooks/useWebSocket.ts
Normal file
21
frontend/src/hooks/useWebSocket.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { useEffect } from 'react';
|
||||
import { webSocketService } from '@/services/websocket';
|
||||
import type { WebSocketEventType } from '@/services/types';
|
||||
|
||||
export function useWebSocket() {
|
||||
useEffect(() => {
|
||||
webSocketService.connect();
|
||||
return () => webSocketService.disconnect();
|
||||
}, []);
|
||||
|
||||
const subscribe = <T = unknown>(
|
||||
eventType: WebSocketEventType,
|
||||
handler: (data: T) => void
|
||||
): (() => void) => {
|
||||
return webSocketService.subscribe<T>(eventType, handler);
|
||||
};
|
||||
|
||||
const isConnected = webSocketService.getConnectionStatus();
|
||||
|
||||
return { subscribe, isConnected };
|
||||
}
|
||||
Reference in New Issue
Block a user