탭 지표 자동추가

This commit is contained in:
Macbook
2026-05-27 13:24:05 +09:00
parent f22abbdc19
commit f7aac535d8
7 changed files with 182 additions and 11 deletions
@@ -34,6 +34,7 @@ export function loadCustomTabs(): IndicatorCustomTab[] {
export function saveCustomTabs(tabs: IndicatorCustomTab[]): void {
localStorage.setItem(STORAGE_KEY, JSON.stringify(tabs));
window.dispatchEvent(new CustomEvent('gc-indicator-custom-tabs-changed'));
}
export function createCustomTab(name: string, indicatorTypes: string[]): IndicatorCustomTab {
+56
View File
@@ -0,0 +1,56 @@
import { INDICATOR_REGISTRY } from './indicatorRegistry';
import { MAIN_INDICATOR_TYPES } from './indicatorMainTab';
import type { IndicatorCustomTab } from './indicatorCustomTabsStorage';
export type IndicatorTabApplySource =
| { kind: 'main' }
| { kind: 'custom'; tab: IndicatorCustomTab };
export function resolveIndicatorTabApplyTypes(source: IndicatorTabApplySource): string[] {
if (source.kind === 'main') {
return [...MAIN_INDICATOR_TYPES].filter(
type => INDICATOR_REGISTRY.some(d => d.type === type),
);
}
return source.tab.indicatorTypes.filter(
type => INDICATOR_REGISTRY.some(d => d.type === type),
);
}
export function resolveIndicatorTabApplyLabel(source: IndicatorTabApplySource): string {
if (source.kind === 'main') return '주요지표';
return source.tab.name;
}
/** 지표 탭 전체 적용 — 기존 보조지표 제거 후 탭 지표만 추가 (확인 없음) */
export function applyIndicatorTab(
source: IndicatorTabApplySource,
onAddMany: ((types: string[]) => void) | undefined,
onAdd?: (type: string) => void,
): boolean {
const validTypes = resolveIndicatorTabApplyTypes(source);
if (validTypes.length === 0) return false;
if (onAddMany) {
onAddMany(validTypes);
} else {
validTypes.forEach(type => onAdd?.(type));
}
return true;
}
/** 지표 탭 전체 적용 — 확인 후 적용 (지표 추가 팝업용) */
export function confirmAndApplyIndicatorTab(
source: IndicatorTabApplySource,
onAddMany: ((types: string[]) => void) | undefined,
onAdd?: (type: string) => void,
): void {
const validTypes = resolveIndicatorTabApplyTypes(source);
if (validTypes.length === 0) {
window.alert('추가할 지표가 없습니다.');
return;
}
const label = resolveIndicatorTabApplyLabel(source);
const msg = `기존 보조지표를 모두 제거하고 ${label} 탭의 지표 ${validTypes.length}개로 교체하시겠습니까?`;
if (!window.confirm(msg)) return;
applyIndicatorTab(source, onAddMany, onAdd);
}