보안 점검 및 대시보드 문구 수정
This commit is contained in:
56
features/trade/store/use-trade-navigation-store.ts
Normal file
56
features/trade/store/use-trade-navigation-store.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
"use client";
|
||||
|
||||
import { create } from "zustand";
|
||||
import type { DashboardStockSearchItem } from "@/features/trade/types/trade.types";
|
||||
|
||||
/**
|
||||
* @file features/trade/store/use-trade-navigation-store.ts
|
||||
* @description 대시보드 -> 트레이드 이동 시 URL 쿼리 없이 종목 선택 상태를 1회 전달합니다.
|
||||
*/
|
||||
|
||||
export interface TradeNavigationTarget {
|
||||
symbol: string;
|
||||
name: string;
|
||||
market: DashboardStockSearchItem["market"];
|
||||
requestedAt: number;
|
||||
}
|
||||
|
||||
interface TradeNavigationStoreState {
|
||||
pendingTarget: TradeNavigationTarget | null;
|
||||
}
|
||||
|
||||
interface TradeNavigationStoreActions {
|
||||
setPendingTarget: (target: Omit<TradeNavigationTarget, "requestedAt">) => void;
|
||||
consumePendingTarget: () => TradeNavigationTarget | null;
|
||||
clearPendingTarget: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 트레이드 화면 진입 시 사용할 종목 이동 상태 store
|
||||
* @remarks UI 흐름: Dashboard 종목 클릭 -> setPendingTarget -> /trade 이동 -> TradeContainer consumePendingTarget -> 종목 로드
|
||||
* @see features/dashboard/components/StockDetailPreview.tsx setPendingTarget 호출
|
||||
* @see features/trade/components/TradeContainer.tsx consumePendingTarget 호출
|
||||
*/
|
||||
export const useTradeNavigationStore = create<
|
||||
TradeNavigationStoreState & TradeNavigationStoreActions
|
||||
>()((set, get) => ({
|
||||
pendingTarget: null,
|
||||
|
||||
setPendingTarget: (target) =>
|
||||
set({
|
||||
pendingTarget: {
|
||||
...target,
|
||||
requestedAt: Date.now(),
|
||||
},
|
||||
}),
|
||||
|
||||
consumePendingTarget: () => {
|
||||
const target = get().pendingTarget;
|
||||
if (!target) return null;
|
||||
|
||||
set({ pendingTarget: null });
|
||||
return target;
|
||||
},
|
||||
|
||||
clearPendingTarget: () => set({ pendingTarget: null }),
|
||||
}));
|
||||
Reference in New Issue
Block a user