Improve data reset flow

The settings page was reloading slowly after a data reset. This commit addresses the issue by preventing the unnecessary reload after the reset operation.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-18 02:07:27 +00:00
parent 00727c8ab6
commit 0be5154e02
4 changed files with 46 additions and 46 deletions

View File

@@ -4,7 +4,7 @@ import { clearAllCategoryBudgets } from './categoryStorage';
import { clearAllBudgetData } from './budgetStorage';
import { DEFAULT_CATEGORY_BUDGETS } from '../budgetUtils';
import { getInitialBudgetData } from '../budgetUtils';
import { toast } from '@/components/ui/use-toast';
import { toast } from '@/hooks/useToast.wrapper';
/**
* 모든 데이터 초기화 (첫 로그인 상태)
@@ -60,12 +60,17 @@ export const resetAllData = (): void => {
localStorage.setItem('categoryBudgets_backup', JSON.stringify(DEFAULT_CATEGORY_BUDGETS));
localStorage.setItem('transactions_backup', JSON.stringify([]));
// 이벤트 발생시켜 데이터 로드 트리거
// 이벤트 발생시켜 데이터 로드 트리거 - 이벤트 순서 최적화
try {
window.dispatchEvent(new Event('transactionUpdated'));
window.dispatchEvent(new Event('budgetDataUpdated'));
window.dispatchEvent(new Event('categoryBudgetsUpdated'));
window.dispatchEvent(new StorageEvent('storage'));
// 한 번에 모든 이벤트 발생
const events = [
new Event('transactionUpdated'),
new Event('budgetDataUpdated'),
new Event('categoryBudgetsUpdated'),
new StorageEvent('storage')
];
events.forEach(event => window.dispatchEvent(event));
} catch (e) {
console.error('이벤트 발생 오류:', e);
}