Clear persistent data
Clear data that persists and is displayed in monthly graphs for analysis.
This commit is contained in:
@@ -92,13 +92,19 @@ export const clearAllBudgetData = (): void => {
|
|||||||
|
|
||||||
// 모든 데이터 초기화 (첫 로그인 상태)
|
// 모든 데이터 초기화 (첫 로그인 상태)
|
||||||
export const resetAllData = (): void => {
|
export const resetAllData = (): void => {
|
||||||
// 모든 관련 데이터 키 목록
|
// 모든 관련 데이터 키 목록 (분석 페이지의 데이터 포함)
|
||||||
const dataKeys = [
|
const dataKeys = [
|
||||||
'transactions',
|
'transactions',
|
||||||
'categoryBudgets',
|
'categoryBudgets',
|
||||||
'budgetData',
|
'budgetData',
|
||||||
'budget',
|
'budget',
|
||||||
'hasVisitedBefore'
|
'hasVisitedBefore',
|
||||||
|
'monthlyExpenses', // 월간 지출 데이터
|
||||||
|
'categorySpending', // 카테고리별 지출 데이터
|
||||||
|
'expenseAnalytics', // 지출 분석 데이터
|
||||||
|
'expenseHistory', // 지출 이력
|
||||||
|
'budgetHistory', // 예산 이력
|
||||||
|
'analyticsCache' // 분석 캐시 데이터
|
||||||
];
|
];
|
||||||
|
|
||||||
// 모든 관련 데이터 키 삭제
|
// 모든 관련 데이터 키 삭제
|
||||||
@@ -108,5 +114,23 @@ export const resetAllData = (): void => {
|
|||||||
clearAllTransactions();
|
clearAllTransactions();
|
||||||
clearAllCategoryBudgets();
|
clearAllCategoryBudgets();
|
||||||
clearAllBudgetData();
|
clearAllBudgetData();
|
||||||
|
|
||||||
|
// 추가적으로 사용자 기기에 저장된 모든 데이터 검사
|
||||||
|
for (let i = 0; i < localStorage.length; i++) {
|
||||||
|
const key = localStorage.key(i);
|
||||||
|
if (key && (
|
||||||
|
key.includes('expense') ||
|
||||||
|
key.includes('budget') ||
|
||||||
|
key.includes('transaction') ||
|
||||||
|
key.includes('analytics') ||
|
||||||
|
key.includes('spending') ||
|
||||||
|
key.includes('financial')
|
||||||
|
)) {
|
||||||
|
console.log(`추가 데이터 삭제: ${key}`);
|
||||||
|
localStorage.removeItem(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('모든 데이터가 초기화되었습니다.');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { formatCurrency, calculatePercentage } from '@/utils/formatters';
|
|||||||
import { useBudget } from '@/contexts/BudgetContext';
|
import { useBudget } from '@/contexts/BudgetContext';
|
||||||
import { useAuth } from '@/contexts/auth';
|
import { useAuth } from '@/contexts/auth';
|
||||||
import { resetAllData } from '@/contexts/budget/storageUtils';
|
import { resetAllData } from '@/contexts/budget/storageUtils';
|
||||||
|
import { resetAllStorageData } from '@/utils/storageUtils';
|
||||||
|
|
||||||
// 메인 컴포넌트
|
// 메인 컴포넌트
|
||||||
const Index = () => {
|
const Index = () => {
|
||||||
@@ -29,8 +30,9 @@ const Index = () => {
|
|||||||
|
|
||||||
// 화면이 처음 로드될 때 데이터 초기화
|
// 화면이 처음 로드될 때 데이터 초기화
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// 데이터를 완전히 초기화
|
// 데이터를 완전히 초기화 (두 가지 초기화 함수 모두 호출)
|
||||||
resetAllData();
|
resetAllData();
|
||||||
|
resetAllStorageData();
|
||||||
|
|
||||||
// 환영 다이얼로그 표시 여부 결정
|
// 환영 다이얼로그 표시 여부 결정
|
||||||
const dontShowWelcome = localStorage.getItem('dontShowWelcome') === 'true';
|
const dontShowWelcome = localStorage.getItem('dontShowWelcome') === 'true';
|
||||||
|
|||||||
@@ -12,42 +12,8 @@ export const loadTransactionsFromStorage = (): Transaction[] => {
|
|||||||
|
|
||||||
// 기본 샘플 데이터 생성
|
// 기본 샘플 데이터 생성
|
||||||
export const createSampleTransactions = (selectedMonth: string): Transaction[] => {
|
export const createSampleTransactions = (selectedMonth: string): Transaction[] => {
|
||||||
return [{
|
// 샘플 데이터는 생성하지 않고 빈 배열 반환 (초기 상태에서는 데이터가 없어야 함)
|
||||||
id: '1',
|
return [];
|
||||||
title: '식료품 구매',
|
|
||||||
amount: 25000,
|
|
||||||
date: `${selectedMonth} 25일, 12:30 PM`,
|
|
||||||
category: '식비',
|
|
||||||
type: 'expense'
|
|
||||||
}, {
|
|
||||||
id: '2',
|
|
||||||
title: '주유소',
|
|
||||||
amount: 50000,
|
|
||||||
date: `${selectedMonth} 24일, 3:45 PM`,
|
|
||||||
category: '교통비',
|
|
||||||
type: 'expense'
|
|
||||||
}, {
|
|
||||||
id: '4',
|
|
||||||
title: '생필품 구매',
|
|
||||||
amount: 35000,
|
|
||||||
date: `${selectedMonth} 18일, 6:00 AM`,
|
|
||||||
category: '생활비',
|
|
||||||
type: 'expense'
|
|
||||||
}, {
|
|
||||||
id: '5',
|
|
||||||
title: '월세',
|
|
||||||
amount: 650000,
|
|
||||||
date: `${selectedMonth} 15일, 10:00 AM`,
|
|
||||||
category: '생활비',
|
|
||||||
type: 'expense'
|
|
||||||
}, {
|
|
||||||
id: '6',
|
|
||||||
title: '식당',
|
|
||||||
amount: 15500,
|
|
||||||
date: `${selectedMonth} 12일, 2:15 PM`,
|
|
||||||
category: '식비',
|
|
||||||
type: 'expense'
|
|
||||||
}];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 트랜잭션 데이터 저장하기
|
// 트랜잭션 데이터 저장하기
|
||||||
@@ -64,3 +30,19 @@ export const loadBudgetFromStorage = (): number => {
|
|||||||
}
|
}
|
||||||
return 1000000; // 기본 예산
|
return 1000000; // 기본 예산
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 모든 데이터 완전히 초기화
|
||||||
|
export const resetAllStorageData = (): void => {
|
||||||
|
// 트랜잭션 초기화
|
||||||
|
localStorage.removeItem('transactions');
|
||||||
|
localStorage.setItem('transactions', JSON.stringify([]));
|
||||||
|
|
||||||
|
// 월별 지출 데이터 초기화
|
||||||
|
localStorage.removeItem('monthlyExpenses');
|
||||||
|
|
||||||
|
// 예산 초기화
|
||||||
|
localStorage.removeItem('budget');
|
||||||
|
|
||||||
|
console.log('모든 저장소 데이터가 초기화되었습니다.');
|
||||||
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user