실시간 차트 보조지표 탭 문제 수정
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import {
|
||||
getOrderedSettingsIndicatorTypes,
|
||||
loadIndicatorListOrder,
|
||||
mergeIndicatorListOrder,
|
||||
reorderIndicatorListType,
|
||||
saveIndicatorListOrder,
|
||||
} from '../utils/indicatorListOrder';
|
||||
import { getSettingsIndicatorTypes } from '../utils/indicatorSettingsList';
|
||||
|
||||
/** 보조지표 설정 목록 순서 — 드래그 정렬 + localStorage */
|
||||
export function useIndicatorListOrder(onOrderChange?: (order: string[]) => void) {
|
||||
const [listOrder, setListOrder] = useState<string[]>(() => getOrderedSettingsIndicatorTypes());
|
||||
|
||||
useEffect(() => {
|
||||
const canonical = getSettingsIndicatorTypes();
|
||||
setListOrder(prev => mergeIndicatorListOrder(prev.length ? prev : loadIndicatorListOrder(), canonical));
|
||||
}, []);
|
||||
|
||||
const persistOrder = useCallback((next: string[]) => {
|
||||
const canonical = getSettingsIndicatorTypes();
|
||||
const merged = mergeIndicatorListOrder(next, canonical);
|
||||
setListOrder(merged);
|
||||
saveIndicatorListOrder(merged);
|
||||
onOrderChange?.(merged);
|
||||
return merged;
|
||||
}, [onOrderChange]);
|
||||
|
||||
const moveType = useCallback(
|
||||
(fromType: string, toType: string, position: 'before' | 'after' = 'before') => {
|
||||
setListOrder(prev => persistOrder(reorderIndicatorListType(prev, fromType, toType, position)));
|
||||
},
|
||||
[persistOrder],
|
||||
);
|
||||
|
||||
return { listOrder, persistOrder, moveType, setListOrder };
|
||||
}
|
||||
Reference in New Issue
Block a user