테마 설정 local storage 설정하도록 수정

This commit is contained in:
Macbook
2026-06-03 11:24:38 +09:00
parent f6ae4e6c6d
commit 5ced979212
4 changed files with 69 additions and 17 deletions
+9 -7
View File
@@ -7,7 +7,7 @@
* - defaultSymbol : 기본 종목 (DEFAULT_STATE.symbol)
* - defaultTimeframe : 기본 타임프레임 (DEFAULT_STATE.timeframe)
* - defaultChartType : 기본 차트 타입
* - defaultTheme : 기본 테마
* - (테마는 DB 미사용 — localStorage, see localThemeStorage)
* - defaultLogScale : 기본 로그 스케일
* - defaultLayoutId : 기본 레이아웃 ID
* - mainChartStyle : 캔들 색상 (DEFAULT_MAIN_CHART_STYLE)
@@ -20,8 +20,7 @@
* // 기본 심볼 사용
* const symbol = settings.defaultSymbol ?? 'KRW-BTC';
*
* // 테마 변경 시 DB 에 저장
* save({ defaultTheme: newTheme });
* // 테마 변경 시 saveLocalTheme() (App.tsx)
* ```
*/
@@ -61,6 +60,7 @@ import {
type ChartPaneSeparatorOptions,
} from '../types/chartPaneSeparator';
import { migrateLocalStorageToUiPreferences } from '../utils/uiPreferencesMigrate';
import { loadLocalTheme } from '../utils/localThemeStorage';
// 전역 캐시 — 여러 컴포넌트에서 공유하여 중복 요청 방지
let _cache: AppSettingsDto | null = null;
@@ -146,7 +146,7 @@ export function resolveAppDefaults(s: AppSettingsDto) {
symbol: (s.defaultSymbol ?? 'KRW-BTC') as string,
timeframe: (s.defaultTimeframe ?? '1D') as Timeframe,
chartType: (s.defaultChartType ?? 'candlestick') as ChartType,
theme: (s.defaultTheme ?? 'dark') as Theme,
theme: loadLocalTheme(),
logScale: s.defaultLogScale ?? false,
layoutId: s.defaultLayoutId ?? '1',
mainChartStyle:(s.mainChartStyle as unknown as MainChartStyle | null) ?? DEFAULT_MAIN_CHART_STYLE,
@@ -164,7 +164,7 @@ export function resolveAppDefaults(s: AppSettingsDto) {
),
chartPaneSeparator: resolveChartPaneSeparatorOptions(
s.chartPaneSeparator as Partial<ChartPaneSeparatorOptions> | null | undefined,
(s.defaultTheme ?? 'dark') as Theme,
loadLocalTheme(),
),
tradeAlertPopup: s.tradeAlertPopup ?? true,
tradeAlertSoundEnabled: s.tradeAlertSoundEnabled ?? true,
@@ -263,7 +263,9 @@ export function useAppSettings(sessionKey = 0) {
* 낙관적 업데이트 — DB 저장 실패해도 UI 는 즉시 반영.
*/
const save = useCallback((patch: AppSettingsDto) => {
const merged = { ...(_cache ?? {}), ...patch };
const { defaultTheme: _omitTheme, ...patchWithoutTheme } = patch;
const apiPatch = 'defaultTheme' in patch ? patchWithoutTheme : patch;
const merged = { ...(_cache ?? {}), ...apiPatch };
_cache = merged;
notifyAppSettingsListeners();
setSettings(merged);
@@ -276,7 +278,7 @@ export function useAppSettings(sessionKey = 0) {
if (patch.tradeAlertTimeFormat != null) {
setTradeAlertTimeFormat(normalizeChartTimeFormat(patch.tradeAlertTimeFormat));
}
saveAppSettings(patch).then(updated => {
saveAppSettings(apiPatch).then(updated => {
if (updated) {
_cache = { ...(_cache ?? {}), ...updated };
notifyAppSettingsListeners();