Fix: Resolve issue with transaction display
Addresses a bug where transactions were not displayed on the transaction history page and expense amounts were showing as zero.
This commit is contained in:
@@ -10,24 +10,41 @@ export const loadTransactionsFromStorage = (): Transaction[] => {
|
||||
// 메인 스토리지에서 먼저 시도
|
||||
const storedTransactions = localStorage.getItem('transactions');
|
||||
if (storedTransactions) {
|
||||
const parsedData = JSON.parse(storedTransactions);
|
||||
console.log('트랜잭션 로드 완료, 항목 수:', parsedData.length);
|
||||
return parsedData;
|
||||
try {
|
||||
const parsedData = JSON.parse(storedTransactions);
|
||||
console.log('트랜잭션 로드 완료, 항목 수:', parsedData.length);
|
||||
|
||||
// 트랜잭션 데이터 유효성 검사
|
||||
if (Array.isArray(parsedData)) {
|
||||
return parsedData;
|
||||
} else {
|
||||
console.error('트랜잭션 데이터가 배열이 아닙니다:', typeof parsedData);
|
||||
return [];
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('트랜잭션 데이터 파싱 오류:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// 백업에서 시도
|
||||
const backupTransactions = localStorage.getItem('transactions_backup');
|
||||
if (backupTransactions) {
|
||||
const parsedBackup = JSON.parse(backupTransactions);
|
||||
console.log('백업에서 트랜잭션 복구, 항목 수:', parsedBackup.length);
|
||||
// 메인 스토리지도 복구
|
||||
localStorage.setItem('transactions', backupTransactions);
|
||||
return parsedBackup;
|
||||
try {
|
||||
const parsedBackup = JSON.parse(backupTransactions);
|
||||
console.log('백업에서 트랜잭션 복구, 항목 수:', parsedBackup.length);
|
||||
// 메인 스토리지도 복구
|
||||
localStorage.setItem('transactions', backupTransactions);
|
||||
return parsedBackup;
|
||||
} catch (e) {
|
||||
console.error('백업 트랜잭션 데이터 파싱 오류:', e);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('트랜잭션 데이터 파싱 오류:', error);
|
||||
console.error('트랜잭션 데이터 로드 중 오류:', error);
|
||||
}
|
||||
// 데이터가 없을 경우 빈 배열 반환 (샘플 데이터 생성하지 않음)
|
||||
|
||||
// 데이터가 없을 경우 빈 배열 반환
|
||||
console.log('트랜잭션 데이터 없음, 빈 배열 반환');
|
||||
return [];
|
||||
};
|
||||
|
||||
@@ -36,6 +53,8 @@ export const loadTransactionsFromStorage = (): Transaction[] => {
|
||||
*/
|
||||
export const saveTransactionsToStorage = (transactions: Transaction[]): void => {
|
||||
try {
|
||||
console.log('트랜잭션 저장 시작, 항목 수:', transactions.length);
|
||||
|
||||
// 먼저 문자열로 변환
|
||||
const dataString = JSON.stringify(transactions);
|
||||
|
||||
@@ -49,6 +68,9 @@ export const saveTransactionsToStorage = (transactions: Transaction[]): void =>
|
||||
// 스토리지 이벤트 수동 트리거 (동일 창에서도 감지하기 위함)
|
||||
try {
|
||||
window.dispatchEvent(new Event('transactionUpdated'));
|
||||
window.dispatchEvent(new CustomEvent('transactionChanged', {
|
||||
detail: { type: 'save', count: transactions.length }
|
||||
}));
|
||||
window.dispatchEvent(new StorageEvent('storage', {
|
||||
key: 'transactions',
|
||||
newValue: dataString
|
||||
@@ -88,6 +110,9 @@ export const clearAllTransactions = (): void => {
|
||||
|
||||
// 스토리지 이벤트 수동 트리거
|
||||
window.dispatchEvent(new Event('transactionUpdated'));
|
||||
window.dispatchEvent(new CustomEvent('transactionChanged', {
|
||||
detail: { type: 'clear' }
|
||||
}));
|
||||
window.dispatchEvent(new StorageEvent('storage', {
|
||||
key: 'transactions',
|
||||
newValue: emptyData
|
||||
|
||||
Reference in New Issue
Block a user