전체적인 리팩토링
This commit is contained in:
39
features/layout/stores/market-indices-store.ts
Normal file
39
features/layout/stores/market-indices-store.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @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<MarketIndicesState>((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 }),
|
||||
}));
|
||||
Reference in New Issue
Block a user