38 lines
1016 B
TypeScript
38 lines
1016 B
TypeScript
/**
|
|
* 매매 시그널 알림 팝업·상세의 시간 표시 포맷 (일반설정, DB 동기화)
|
|
*/
|
|
import { useSyncExternalStore } from 'react';
|
|
import {
|
|
DEFAULT_CHART_TIME_FORMAT,
|
|
normalizeChartTimeFormat,
|
|
} from './chartTimeFormat';
|
|
|
|
export const DEFAULT_TRADE_ALERT_TIME_FORMAT = DEFAULT_CHART_TIME_FORMAT;
|
|
|
|
let _format = DEFAULT_TRADE_ALERT_TIME_FORMAT;
|
|
const _listeners = new Set<() => void>();
|
|
|
|
export function getTradeAlertTimeFormat(): string {
|
|
return _format;
|
|
}
|
|
|
|
export function setTradeAlertTimeFormat(format: string): void {
|
|
const next = normalizeChartTimeFormat(format);
|
|
if (_format === next) return;
|
|
_format = next;
|
|
_listeners.forEach(l => l());
|
|
}
|
|
|
|
export function subscribeTradeAlertTimeFormat(cb: () => void): () => void {
|
|
_listeners.add(cb);
|
|
return () => _listeners.delete(cb);
|
|
}
|
|
|
|
export function useTradeAlertTimeFormat(): string {
|
|
return useSyncExternalStore(
|
|
subscribeTradeAlertTimeFormat,
|
|
getTradeAlertTimeFormat,
|
|
() => DEFAULT_TRADE_ALERT_TIME_FORMAT,
|
|
);
|
|
}
|