feat(home+search): KOSPI/KOSDAQ 인덱스 카드 + 검색결과 미니 sparkline

- Sparkline 컴포넌트를 PriceHero 내부에서 web/components/Sparkline.tsx 로 분리·재사용
- /api/markets/indices: macro_daily 의 kospi/kosdaq N일 시계열 + 최신값/전일대비
- 홈 IndicesPanel: 두 인덱스 카드(현재값/등락/우측 sparkline)
- /api/symbols/search?with_sparkline=true: 결과 한 번에 최근 30 종가 batch 조회
- SearchBox 결과 행에 mini sparkline + 현재가/등락률 인라인 표시

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
claude-owner
2026-05-28 14:46:13 +09:00
parent 66a28cc7ca
commit ae4f07d675
8 changed files with 330 additions and 71 deletions

View File

@@ -33,6 +33,10 @@ export type Symbol = {
market: string;
sector: string | null;
is_seed: boolean;
// with_sparkline=true 일 때만 채워짐.
sparkline?: number[];
close?: number | null;
pct_change?: number | null;
};
export type SymbolSearch = {
@@ -205,6 +209,22 @@ export type ThemeDetailResponse = {
items: Mover[];
};
export type IndexPoint = { date: string; value: number };
export type IndexSeries = {
key: "kospi" | "kosdaq";
name: string;
points: IndexPoint[];
latest: number | null;
prev: number | null;
pct_change: number | null;
};
export type IndicesResponse = {
days: number;
indices: IndexSeries[];
};
async function getJson<T>(path: string, init?: RequestInit): Promise<T> {
const res = await fetch(`${API_BASE}${path}`, {
...init,
@@ -222,9 +242,9 @@ async function getJson<T>(path: string, init?: RequestInit): Promise<T> {
}
export const api = {
search: (q: string, seedOnly = false, limit = 20) =>
search: (q: string, seedOnly = false, limit = 20, withSparkline = false) =>
getJson<SymbolSearch>(
`/api/symbols/search?q=${encodeURIComponent(q)}&limit=${limit}&seed_only=${seedOnly}`,
`/api/symbols/search?q=${encodeURIComponent(q)}&limit=${limit}&seed_only=${seedOnly}&with_sparkline=${withSparkline}`,
),
getSymbol: (code: string) => getJson<Symbol>(`/api/symbols/${encodeURIComponent(code)}`),
getChart: (code: string, days = 180, interval: ChartInterval = "1d") =>
@@ -258,6 +278,7 @@ export const api = {
getJson<RelatedResponse>(
`/api/markets/related/${encodeURIComponent(code)}?limit=${limit}`,
),
indices: (days = 60) => getJson<IndicesResponse>(`/api/markets/indices?days=${days}`),
themesIndex: () => getJson<ThemesIndexResponse>(`/api/themes`),
themeDetail: (slug: string, limit = 30) =>
getJson<ThemeDetailResponse>(