/** * @file features/layout/stores/market-indices-store.ts * @description 시장 지수(KOSPI, KOSDAQ) 데이터 상태 관리를 위한 Zustand 스토어 * * @description [주요 책임] * - 지수 데이터, 로딩 상태, 에러 정보, 마지막 fetch 시각을 저장 * - 상태를 업데이트하는 액션(setIndices, setLoading, setError)을 제공 */ import type { DomesticMarketIndexResult } from "@/lib/kis/dashboard"; import { create } from "zustand"; interface MarketIndicesState { indices: DomesticMarketIndexResult[]; isLoading: boolean; error: Error | null; fetchedAt: string | null; setIndices: (data: { indices: DomesticMarketIndexResult[]; fetchedAt: string; }) => void; setLoading: (isLoading: boolean) => void; setError: (error: Error | null) => void; } export const useMarketIndicesStore = create((set) => ({ indices: [], isLoading: false, error: null, fetchedAt: null, setIndices: (data) => set({ indices: data.indices, fetchedAt: data.fetchedAt, isLoading: false, error: null, }), setLoading: (isLoading) => set({ isLoading }), setError: (error) => set({ error, isLoading: false }), }));