지표탭 추가
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
* ```
|
||||
*/
|
||||
|
||||
import { useEffect, useRef, useCallback } from 'react';
|
||||
import { useEffect, useRef, useCallback, useState } from 'react';
|
||||
import { getIndicatorDef, mergePlotDefs, normalizeHLines, PlotDef, HLineDef } from '../utils/indicatorRegistry';
|
||||
import { createDefaultSmaParams, createDefaultSmaPlots, normalizeSmaConfig } from '../utils/smaConfig';
|
||||
import { normalizeIchimokuConfig, mergeIchimokuPlots } from '../utils/ichimokuConfig';
|
||||
@@ -61,6 +61,7 @@ function ensureLoaded(): Promise<AllSettings> {
|
||||
_loadPromise = loadIndicatorSettings().then(data => {
|
||||
_cache = (data as AllSettings) ?? {};
|
||||
_loadPromise = null;
|
||||
notifyIndicatorSettingsChanged();
|
||||
return _cache;
|
||||
});
|
||||
return _loadPromise;
|
||||
@@ -72,11 +73,25 @@ function ensureVisualLoaded(): Promise<VisualCache> {
|
||||
_visualLoadPromise = loadIndicatorVisualSettings().then(data => {
|
||||
_visualCache = (data as VisualCache) ?? {};
|
||||
_visualLoadPromise = null;
|
||||
notifyIndicatorSettingsChanged();
|
||||
return _visualCache;
|
||||
});
|
||||
return _visualLoadPromise;
|
||||
}
|
||||
|
||||
type SettingsListener = () => void;
|
||||
const _settingsListeners = new Set<SettingsListener>();
|
||||
|
||||
function notifyIndicatorSettingsChanged() {
|
||||
_settingsListeners.forEach(fn => fn());
|
||||
}
|
||||
|
||||
/** 보조지표 설정 변경 구독 (전략편집기 DEF 동기화 등) */
|
||||
export function subscribeIndicatorSettings(listener: SettingsListener): () => void {
|
||||
_settingsListeners.add(listener);
|
||||
return () => { _settingsListeners.delete(listener); };
|
||||
}
|
||||
|
||||
/** 캐시를 강제로 무효화 (테스트 또는 로그아웃 시) */
|
||||
export function invalidateIndicatorSettingsCache() {
|
||||
_cache = null;
|
||||
@@ -88,15 +103,21 @@ export function invalidateIndicatorSettingsCache() {
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
export function useIndicatorSettings(sessionKey = 0) {
|
||||
const [settingsRevision, setSettingsRevision] = useState(0);
|
||||
|
||||
// 로그인/로그아웃 시 지표 설정 재로드
|
||||
useEffect(() => {
|
||||
invalidateIndicatorSettingsCache();
|
||||
ensureLoaded().catch(err =>
|
||||
console.error('[useIndicatorSettings] params load failed', err)
|
||||
);
|
||||
ensureVisualLoaded().catch(err =>
|
||||
console.error('[useIndicatorSettings] visual load failed', err)
|
||||
);
|
||||
const unsub = subscribeIndicatorSettings(() => setSettingsRevision(r => r + 1));
|
||||
Promise.all([
|
||||
ensureLoaded().catch(err =>
|
||||
console.error('[useIndicatorSettings] params load failed', err),
|
||||
),
|
||||
ensureVisualLoaded().catch(err =>
|
||||
console.error('[useIndicatorSettings] visual load failed', err),
|
||||
),
|
||||
]).then(() => setSettingsRevision(r => r + 1));
|
||||
return unsub;
|
||||
}, [sessionKey]);
|
||||
|
||||
// ── 파라미터 ────────────────────────────────────────────────────────────
|
||||
@@ -135,6 +156,7 @@ export function useIndicatorSettings(sessionKey = 0) {
|
||||
saveIndicatorSettings(type, params as ParamMap).catch(err =>
|
||||
console.error(`[useIndicatorSettings] saveParams failed for ${type}`, err)
|
||||
);
|
||||
notifyIndicatorSettingsChanged();
|
||||
},
|
||||
[]
|
||||
);
|
||||
@@ -146,6 +168,7 @@ export function useIndicatorSettings(sessionKey = 0) {
|
||||
saveAllIndicatorSettings(allParams).catch(err =>
|
||||
console.error('[useIndicatorSettings] saveAll failed', err)
|
||||
);
|
||||
notifyIndicatorSettingsChanged();
|
||||
},
|
||||
[]
|
||||
);
|
||||
@@ -222,9 +245,10 @@ export function useIndicatorSettings(sessionKey = 0) {
|
||||
saveIndicatorVisualSettings(type, visual as { plots?: unknown[]; hlines?: unknown[]; cloudColors?: IchimokuCloudColors }).catch(err =>
|
||||
console.error(`[useIndicatorSettings] saveVisual failed for ${type}`, err)
|
||||
);
|
||||
notifyIndicatorSettingsChanged();
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
return { getParams, saveParams, saveAll, getVisualConfig, saveVisual };
|
||||
return { getParams, saveParams, saveAll, getVisualConfig, saveVisual, settingsRevision };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user