"use client"; import Link from "next/link"; import { useEffect, useState } from "react"; import { MetricsPanel } from "../../components/MetricsPanel"; import { NewsList } from "../../components/NewsList"; import { PredictionPanel } from "../../components/PredictionPanel"; import { StockChart } from "../../components/StockChart"; import { api, type ChartPayload, type LatestPredictionResponse, } from "../../lib/api"; export default function CodePage({ params }: { params: { code: string } }) { const { code } = params; const [chart, setChart] = useState(null); const [prediction, setPrediction] = useState(null); const [err, setErr] = useState(null); const [days, setDays] = useState(180); useEffect(() => { let alive = true; setErr(null); setChart(null); api .getChart(code, days) .then((c) => { if (alive) setChart(c); }) .catch((e) => { if (alive) setErr(e instanceof Error ? e.message : String(e)); }); return () => { alive = false; }; }, [code, days]); useEffect(() => { let alive = true; api .latestPrediction(code) .then((r) => { if (alive && r.found) setPrediction(r); }) .catch(() => { // 예측 이력 없는 경우는 무시. }); return () => { alive = false; }; }, [code]); return (
← 검색으로
{chart && (

{chart.name}{" "} {chart.code} · {chart.market}

)} {err &&
차트 로딩 실패: {err}
} {chart && ( <>
)}
); }