82 lines
2.9 KiB
TypeScript
82 lines
2.9 KiB
TypeScript
import { getUiPreferences, patchUiPreferences } from './uiPreferencesDb';
|
|
import {
|
|
normalizeStartCandleType,
|
|
STRATEGY_CANDLE_TYPE_OPTIONS,
|
|
} from './strategyStartNodes';
|
|
import {
|
|
DEFAULT_TRADE_NOTIFICATION_GRID_PRESET,
|
|
normalizeTradeNotificationGridPreset,
|
|
type TradeNotificationGridPresetId,
|
|
} from './tradeNotificationGridPresets';
|
|
|
|
export type TradeNotificationListLayout = 'list' | 'grid';
|
|
|
|
/** 알림 목록 정렬 */
|
|
export type TradeNotificationListSort = 'market' | 'newest' | 'oldest';
|
|
|
|
export function loadTradeNotificationListLayout(): TradeNotificationListLayout {
|
|
const v = getUiPreferences().tradeNotifications?.listLayout;
|
|
return v === 'grid' ? 'grid' : 'list';
|
|
}
|
|
|
|
export function saveTradeNotificationListLayout(layout: TradeNotificationListLayout): void {
|
|
patchUiPreferences({ tradeNotifications: { listLayout: layout } });
|
|
}
|
|
|
|
export function loadTradeNotificationGridPreset(): TradeNotificationGridPresetId {
|
|
return normalizeTradeNotificationGridPreset(
|
|
getUiPreferences().tradeNotifications?.gridPreset ?? DEFAULT_TRADE_NOTIFICATION_GRID_PRESET,
|
|
);
|
|
}
|
|
|
|
export function saveTradeNotificationGridPreset(preset: TradeNotificationGridPresetId): void {
|
|
patchUiPreferences({ tradeNotifications: { gridPreset: preset } });
|
|
}
|
|
|
|
export function loadTradeNotificationListSort(): TradeNotificationListSort {
|
|
const v = getUiPreferences().tradeNotifications?.listSort;
|
|
if (v === 'market' || v === 'oldest') return v;
|
|
return 'newest';
|
|
}
|
|
|
|
export function saveTradeNotificationListSort(sort: TradeNotificationListSort): void {
|
|
patchUiPreferences({ tradeNotifications: { listSort: sort } });
|
|
}
|
|
|
|
export type TradeNotificationReadFilter = 'all' | 'unread';
|
|
|
|
export const TRADE_NOTIFICATION_READ_FILTER_OPTIONS: {
|
|
value: TradeNotificationReadFilter;
|
|
label: string;
|
|
}[] = [
|
|
{ value: 'all', label: '전체' },
|
|
{ value: 'unread', label: '미확인' },
|
|
];
|
|
|
|
export const TRADE_NOTIFICATION_SORT_OPTIONS: {
|
|
value: TradeNotificationListSort;
|
|
label: string;
|
|
}[] = [
|
|
{ value: 'market', label: '종목순' },
|
|
{ value: 'newest', label: '최신시간순' },
|
|
{ value: 'oldest', label: '이전시간순' },
|
|
];
|
|
|
|
/** 알림 목록 시간봉 필터 — '' = 전체 */
|
|
export type TradeNotificationCandleFilter = '' | (typeof STRATEGY_CANDLE_TYPE_OPTIONS)[number]['value'];
|
|
|
|
export function loadTradeNotificationCandleFilter(): TradeNotificationCandleFilter {
|
|
const raw = getUiPreferences().tradeNotifications?.candleFilter;
|
|
if (raw == null || raw === '') return '';
|
|
const n = normalizeStartCandleType(raw);
|
|
return STRATEGY_CANDLE_TYPE_OPTIONS.some(o => o.value === n)
|
|
? (n as TradeNotificationCandleFilter)
|
|
: '';
|
|
}
|
|
|
|
export function saveTradeNotificationCandleFilter(filter: TradeNotificationCandleFilter): void {
|
|
patchUiPreferences({ tradeNotifications: { candleFilter: filter || '' } });
|
|
}
|
|
|
|
export { STRATEGY_CANDLE_TYPE_OPTIONS as TRADE_NOTIFICATION_CANDLE_FILTER_OPTIONS };
|