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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user