Fundamental_Analysis/frontend/src/app/report/[symbol]/components/StockChart.tsx
Lv, Qi 4fef6bf35b refactor: 拆分 ReportPage 为组件和 Hooks
- 将庞大的 page.tsx 拆分为多个独立组件 (components/)
- 提取业务逻辑到 Hooks (hooks/)
- 提取工具函数到 utils.ts
- 优化代码结构和可维护性
2025-11-19 06:51:46 +08:00

58 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { CheckCircle } from 'lucide-react';
import { Spinner } from '@/components/ui/spinner';
import { TradingViewWidget } from '@/components/TradingViewWidget';
interface StockChartProps {
unifiedSymbol: string;
marketParam: string;
realtime: any;
realtimeLoading: boolean;
realtimeError: any;
}
export function StockChart({
unifiedSymbol,
marketParam,
realtime,
realtimeLoading,
realtimeError,
}: StockChartProps) {
return (
<div className="space-y-4">
<h2 className="text-lg font-medium"> TradingView</h2>
<div className="flex items-center justify-between text-sm mb-4">
<div className="flex items-center gap-3">
<CheckCircle className="size-4 text-green-600" />
<div className="text-muted-foreground">
- {unifiedSymbol}
</div>
</div>
<div className="text-xs text-muted-foreground">
{realtimeLoading ? (
<span className="inline-flex items-center gap-2"><Spinner className="size-3" /> </span>
) : realtimeError ? (
<span className="text-red-500"></span>
) : (() => {
const priceRaw = realtime?.price;
const priceNum = typeof priceRaw === 'number' ? priceRaw : Number(priceRaw);
const tsRaw = realtime?.ts;
const tsDate = tsRaw == null ? null : new Date(typeof tsRaw === 'number' ? tsRaw : String(tsRaw));
const tsText = tsDate && !isNaN(tsDate.getTime()) ? `${tsDate.toLocaleString()}` : '';
if (Number.isFinite(priceNum)) {
return <span> {priceNum.toLocaleString()} {tsText}</span>;
}
return <span></span>;
})()}
</div>
</div>
<TradingViewWidget
symbol={unifiedSymbol}
market={marketParam}
height={500}
/>
</div>
);
}