Fix data persistence issue
Addresses a bug where budget and expense data were not persisting correctly, leading to data loss when navigating between pages.
This commit is contained in:
@@ -31,6 +31,11 @@ export const saveBudgetDataToStorage = (budgetData: BudgetData): void => {
|
||||
try {
|
||||
localStorage.setItem('budgetData', JSON.stringify(budgetData));
|
||||
console.log('예산 데이터 저장 완료');
|
||||
|
||||
// 스토리지 이벤트 수동 트리거 (동일 창에서도 감지하기 위함)
|
||||
window.dispatchEvent(new StorageEvent('storage', {
|
||||
key: 'budgetData'
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('예산 데이터 저장 오류:', error);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,11 @@ export const saveCategoryBudgetsToStorage = (categoryBudgets: Record<string, num
|
||||
try {
|
||||
localStorage.setItem('categoryBudgets', JSON.stringify(categoryBudgets));
|
||||
console.log('카테고리 예산 저장 완료:', categoryBudgets);
|
||||
|
||||
// 스토리지 이벤트 수동 트리거 (동일 창에서도 감지하기 위함)
|
||||
window.dispatchEvent(new StorageEvent('storage', {
|
||||
key: 'categoryBudgets'
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('카테고리 예산 저장 오류:', error);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,11 @@ export const saveTransactionsToStorage = (transactions: Transaction[]): void =>
|
||||
try {
|
||||
localStorage.setItem('transactions', JSON.stringify(transactions));
|
||||
console.log('트랜잭션 저장 완료, 항목 수:', transactions.length);
|
||||
|
||||
// 스토리지 이벤트 수동 트리거 (동일 창에서도 감지하기 위함)
|
||||
window.dispatchEvent(new StorageEvent('storage', {
|
||||
key: 'transactions'
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('트랜잭션 저장 오류:', error);
|
||||
}
|
||||
@@ -37,6 +42,11 @@ export const clearAllTransactions = (): void => {
|
||||
// 빈 배열을 저장하여 확실히 초기화
|
||||
localStorage.setItem('transactions', JSON.stringify([]));
|
||||
console.log('모든 트랜잭션이 삭제되었습니다.');
|
||||
|
||||
// 스토리지 이벤트 수동 트리거
|
||||
window.dispatchEvent(new StorageEvent('storage', {
|
||||
key: 'transactions'
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('트랜잭션 삭제 오류:', error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user