|
|
@@ -9,18 +9,14 @@ import { ActiveType } from "./components/stock-chart/src/types/index.ts";
|
|
|
export function StockMain() {
|
|
|
const chartRef = useRef<StockChartRef>(null);
|
|
|
const [searchParams] = useSearchParams();
|
|
|
+ const codeFromUrl = searchParams.get('code');
|
|
|
+ const [stockCode, setStockCode] = useState(codeFromUrl || undefined);//|| '001339'
|
|
|
+ const classroom = searchParams.get('classroom');
|
|
|
const {
|
|
|
- connect,
|
|
|
- disconnect,
|
|
|
pushExamData,
|
|
|
error,
|
|
|
isConnected
|
|
|
- } = useStockSocket();
|
|
|
- const codeFromUrl = searchParams.get('code');
|
|
|
- const [stockCode, setStockCode] = useState(codeFromUrl || '001339' || undefined);//
|
|
|
- const classroom = searchParams.get('classroom');
|
|
|
-// const { connected } = useSocketRoom(classroom);
|
|
|
-// const { sendNextQuestion } = useQuestionManagement(classroom);
|
|
|
+ } = useStockSocket(classroom);
|
|
|
|
|
|
const {
|
|
|
stockData: fullStockData,
|
|
|
@@ -52,19 +48,6 @@ export function StockMain() {
|
|
|
}
|
|
|
}, [moveToNextDay, updateCurrentDate, profitSummary, pushExamData]);
|
|
|
|
|
|
-// useEffect(() => {
|
|
|
-// const currentDate = profitSummary.dailyStats.date;
|
|
|
-// if (classroom && connected && currentDate && lastSentDateRef.current !== currentDate) {
|
|
|
-// lastSentDateRef.current = currentDate;
|
|
|
-// sendNextQuestion({
|
|
|
-// date: currentDate,
|
|
|
-// price: profitSummary.dailyStats.close
|
|
|
-// }).catch(() => {
|
|
|
-// message.error('发送题目失败');
|
|
|
-// });
|
|
|
-// }
|
|
|
-// }, [classroom, connected, profitSummary.dailyStats, sendNextQuestion]);
|
|
|
-
|
|
|
useEffect(() => {
|
|
|
const currentDate = profitSummary.dailyStats.date;
|
|
|
if (classroom && isConnected && currentDate ) {
|
|
|
@@ -110,14 +93,6 @@ export function StockMain() {
|
|
|
chartRef.current?.clearDrawings();
|
|
|
}, []);
|
|
|
|
|
|
- // 管理socket连接生命周期
|
|
|
- useEffect(() => {
|
|
|
- connect();
|
|
|
- return () => {
|
|
|
- disconnect();
|
|
|
- };
|
|
|
- }, [connect, disconnect]);
|
|
|
-
|
|
|
// 错误处理
|
|
|
useEffect(() => {
|
|
|
if (error) {
|
|
|
@@ -171,7 +146,7 @@ export function StockMain() {
|
|
|
|
|
|
return (
|
|
|
<div className="flex flex-col h-screen bg-gray-900">
|
|
|
- {!isConnected && (
|
|
|
+ {!isConnected && classroom && (
|
|
|
<div className="bg-yellow-600 text-white text-center py-1 text-sm">
|
|
|
正在尝试连接答题卡服务...
|
|
|
</div>
|