59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
/** 지표 추가 팝업 — 사용자 정의 탭 (DB) */
|
|
import { getUiPreferences, patchUiPreferences } from './uiPreferencesDb';
|
|
|
|
export interface IndicatorCustomTab {
|
|
id: string;
|
|
name: string;
|
|
/** INDICATOR_REGISTRY type 목록 (표시 순서) */
|
|
indicatorTypes: string[];
|
|
}
|
|
|
|
function newId(): string {
|
|
return `tab-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`;
|
|
}
|
|
|
|
export function loadCustomTabs(): IndicatorCustomTab[] {
|
|
return getUiPreferences().indicator?.customTabs ?? [];
|
|
}
|
|
|
|
export function saveCustomTabs(tabs: IndicatorCustomTab[]): void {
|
|
patchUiPreferences({ indicator: { customTabs: tabs } });
|
|
window.dispatchEvent(new CustomEvent('gc-indicator-custom-tabs-changed'));
|
|
}
|
|
|
|
export function createCustomTab(name: string, indicatorTypes: string[]): IndicatorCustomTab {
|
|
const tab: IndicatorCustomTab = {
|
|
id: newId(),
|
|
name: name.trim(),
|
|
indicatorTypes: [...new Set(indicatorTypes)],
|
|
};
|
|
const tabs = loadCustomTabs();
|
|
tabs.push(tab);
|
|
saveCustomTabs(tabs);
|
|
return tab;
|
|
}
|
|
|
|
export function updateCustomTab(
|
|
id: string,
|
|
patch: Partial<Pick<IndicatorCustomTab, 'name' | 'indicatorTypes'>>,
|
|
): IndicatorCustomTab | null {
|
|
const tabs = loadCustomTabs();
|
|
const idx = tabs.findIndex(t => t.id === id);
|
|
if (idx < 0) return null;
|
|
const next: IndicatorCustomTab = {
|
|
...tabs[idx],
|
|
...patch,
|
|
name: patch.name != null ? patch.name.trim() : tabs[idx].name,
|
|
indicatorTypes: patch.indicatorTypes != null
|
|
? [...patch.indicatorTypes]
|
|
: tabs[idx].indicatorTypes,
|
|
};
|
|
tabs[idx] = next;
|
|
saveCustomTabs(tabs);
|
|
return next;
|
|
}
|
|
|
|
export function deleteCustomTab(id: string): void {
|
|
saveCustomTabs(loadCustomTabs().filter(t => t.id !== id));
|
|
}
|