Retrigger data initialization
Retrigger data initialization process.
This commit is contained in:
@@ -25,9 +25,13 @@ const WelcomeDialog: React.FC<WelcomeDialogProps> = ({ open, onClose }) => {
|
||||
// 다이얼로그 열릴 때 localStorage 값 확인
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
try {
|
||||
const savedValue = localStorage.getItem('dontShowWelcome');
|
||||
console.log('저장된 dontShowWelcome 값:', savedValue);
|
||||
console.log('WelcomeDialog - 저장된 dontShowWelcome 값:', savedValue);
|
||||
setDontShowAgain(savedValue === 'true');
|
||||
} catch (error) {
|
||||
console.error('WelcomeDialog - localStorage 읽기 오류:', error);
|
||||
}
|
||||
}
|
||||
}, [open]);
|
||||
|
||||
@@ -35,22 +39,25 @@ const WelcomeDialog: React.FC<WelcomeDialogProps> = ({ open, onClose }) => {
|
||||
try {
|
||||
// 체크박스가 체크되어 있으면 localStorage에 저장
|
||||
if (dontShowAgain) {
|
||||
// 세션 스토리지와 로컬 스토리지 모두에 저장 (이중 보호)
|
||||
localStorage.setItem('dontShowWelcome', 'true');
|
||||
console.log('dontShowWelcome 값이 true로 저장되었습니다');
|
||||
sessionStorage.setItem('dontShowWelcome', 'true');
|
||||
console.log('WelcomeDialog - dontShowWelcome 값이 true로 저장되었습니다');
|
||||
|
||||
// 확인을 위한 즉시 재확인
|
||||
const savedValue = localStorage.getItem('dontShowWelcome');
|
||||
console.log('저장 직후 확인된 값:', savedValue);
|
||||
console.log('WelcomeDialog - 저장 직후 확인된 값:', savedValue);
|
||||
|
||||
// 토스트 메시지로 사용자에게 알림
|
||||
toast.success('환영 메시지가 다시 표시되지 않도록 설정되었습니다');
|
||||
} else {
|
||||
// 체크 해제 시 null이 아닌 'false' 문자열로 명시적 저장
|
||||
// 체크 해제 시 명시적 'false' 저장
|
||||
localStorage.setItem('dontShowWelcome', 'false');
|
||||
console.log('dontShowWelcome 값이 false로 저장되었습니다');
|
||||
sessionStorage.setItem('dontShowWelcome', 'false');
|
||||
console.log('WelcomeDialog - dontShowWelcome 값이 false로 저장되었습니다');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('localStorage 저장 중 오류 발생:', error);
|
||||
console.error('WelcomeDialog - localStorage 저장 중 오류 발생:', error);
|
||||
}
|
||||
|
||||
// 부모 컴포넌트에 상태 전달
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import { BudgetData, Transaction } from './types';
|
||||
import { DEFAULT_CATEGORY_BUDGETS, getInitialBudgetData } from './budgetUtils';
|
||||
|
||||
@@ -125,6 +124,10 @@ export const clearAllBudgetData = (): void => {
|
||||
export const resetAllData = (): void => {
|
||||
console.log('완전 초기화 시작 - resetAllData');
|
||||
|
||||
// dontShowWelcome 설정 값 백업
|
||||
const dontShowWelcomeValue = localStorage.getItem('dontShowWelcome');
|
||||
console.log('resetAllData - dontShowWelcome 백업 값:', dontShowWelcomeValue);
|
||||
|
||||
// 모든 관련 데이터 키 목록 (분석 페이지의 데이터 포함)
|
||||
const dataKeys = [
|
||||
'transactions',
|
||||
@@ -144,7 +147,7 @@ export const resetAllData = (): void => {
|
||||
'weeklyBudget', // 주간 예산
|
||||
'monthlyBudget', // 월간 예산
|
||||
'chartData', // 차트 데이터
|
||||
'dontShowWelcome' // 환영 메시지 표시 여부
|
||||
// 'dontShowWelcome' 키는 삭제 목록에서 제외
|
||||
];
|
||||
|
||||
// 모든 관련 데이터 키 삭제
|
||||
@@ -161,7 +164,7 @@ export const resetAllData = (): void => {
|
||||
// 추가적으로 사용자 기기에 저장된 모든 데이터 검사 (역순으로 루프)
|
||||
for (let i = localStorage.length - 1; i >= 0; i--) {
|
||||
const key = localStorage.key(i);
|
||||
if (key && (
|
||||
if (key && key !== 'dontShowWelcome' && ( // dontShowWelcome 키는 제외
|
||||
key.includes('expense') ||
|
||||
key.includes('budget') ||
|
||||
key.includes('transaction') ||
|
||||
@@ -172,7 +175,6 @@ export const resetAllData = (): void => {
|
||||
key.includes('month') ||
|
||||
key.includes('sync') ||
|
||||
key.includes('total') ||
|
||||
key.includes('welcome') ||
|
||||
key.includes('visited')
|
||||
)) {
|
||||
console.log(`추가 데이터 삭제: ${key}`);
|
||||
@@ -190,5 +192,15 @@ export const resetAllData = (): void => {
|
||||
}));
|
||||
localStorage.setItem('categoryBudgets', JSON.stringify(DEFAULT_CATEGORY_BUDGETS));
|
||||
|
||||
// dontShowWelcome 값 복원 (백업한 값이 있는 경우)
|
||||
if (dontShowWelcomeValue) {
|
||||
console.log('resetAllData - dontShowWelcome 값 복원:', dontShowWelcomeValue);
|
||||
localStorage.setItem('dontShowWelcome', dontShowWelcomeValue);
|
||||
|
||||
// 복원 확인
|
||||
const restoredValue = localStorage.getItem('dontShowWelcome');
|
||||
console.log('resetAllData - 복원 후 dontShowWelcome 값:', restoredValue);
|
||||
}
|
||||
|
||||
console.log('모든 데이터가 초기화되었습니다.');
|
||||
};
|
||||
|
||||
@@ -38,6 +38,10 @@ const Index = () => {
|
||||
const initializeAllData = () => {
|
||||
console.log('모든 데이터 초기화 시작');
|
||||
|
||||
// 현재 dontShowWelcome 값 백업
|
||||
const dontShowWelcomeValue = localStorage.getItem('dontShowWelcome');
|
||||
console.log('Index - 초기화 전 dontShowWelcome 값:', dontShowWelcomeValue);
|
||||
|
||||
// 여러번 초기화 실행
|
||||
for (let i = 0; i < 3; i++) {
|
||||
// 모든 데이터 완전히 삭제 및 초기화
|
||||
@@ -53,6 +57,16 @@ const Index = () => {
|
||||
resetBudgetData();
|
||||
}
|
||||
|
||||
// 초기화 후 dontShowWelcome 값 확인
|
||||
const afterResetValue = localStorage.getItem('dontShowWelcome');
|
||||
console.log('Index - 초기화 후 dontShowWelcome 값:', afterResetValue);
|
||||
|
||||
// 값이 유지되지 않았다면 복원
|
||||
if (dontShowWelcomeValue && afterResetValue !== dontShowWelcomeValue) {
|
||||
console.log('Index - dontShowWelcome 값 복원:', dontShowWelcomeValue);
|
||||
localStorage.setItem('dontShowWelcome', dontShowWelcomeValue);
|
||||
}
|
||||
|
||||
console.log('모든 데이터 초기화 완료');
|
||||
return true;
|
||||
};
|
||||
@@ -97,40 +111,57 @@ const Index = () => {
|
||||
|
||||
// 환영 다이얼로그 표시 여부 결정 (데이터 초기화 후)
|
||||
const checkWelcomeDialogState = () => {
|
||||
// 현재 세션에서 이미 환영 메시지를 닫았는지 확인
|
||||
const sessionClosed = sessionStorage.getItem('welcomeClosedThisSession') === 'true';
|
||||
|
||||
if (sessionClosed) {
|
||||
console.log('Index - 이번 세션에서 이미 환영 메시지를 닫았습니다');
|
||||
setShowWelcome(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const dontShowWelcome = localStorage.getItem('dontShowWelcome');
|
||||
console.log('Index 페이지 로딩 시 dontShowWelcome 값:', dontShowWelcome);
|
||||
console.log('Index - 페이지 로딩 시 dontShowWelcome 값:', dontShowWelcome);
|
||||
|
||||
// 명시적으로 'true' 문자열인 경우에만 숨김 처리
|
||||
if (dontShowWelcome === 'true') {
|
||||
console.log('환영 메시지 표시하지 않음 (저장된 설정)');
|
||||
console.log('Index - 환영 메시지 표시하지 않음 (저장된 설정)');
|
||||
setShowWelcome(false);
|
||||
} else {
|
||||
console.log('환영 메시지 표시함');
|
||||
console.log('Index - 환영 메시지 표시함');
|
||||
setShowWelcome(true);
|
||||
}
|
||||
};
|
||||
|
||||
checkWelcomeDialogState();
|
||||
// 0.5초 후 환영 메시지 표시 상태 확인 (데이터 초기화가 완료된 후)
|
||||
const timeoutId = setTimeout(checkWelcomeDialogState, 500);
|
||||
|
||||
// 방문 기록 저장 (초기화 후에 저장)
|
||||
localStorage.setItem('hasVisitedBefore', 'true');
|
||||
|
||||
return () => clearTimeout(timeoutId);
|
||||
}, [isInitialized, resetBudgetData]);
|
||||
|
||||
// 환영 팝업 닫기
|
||||
const handleCloseWelcome = (dontShowAgain: boolean) => {
|
||||
setShowWelcome(false);
|
||||
|
||||
// 이번 세션에서 닫았음을 기록
|
||||
sessionStorage.setItem('welcomeClosedThisSession', 'true');
|
||||
|
||||
// 사용자가 더 이상 보지 않기를 선택한 경우
|
||||
if (dontShowAgain) {
|
||||
localStorage.setItem('dontShowWelcome', 'true');
|
||||
console.log('환영 팝업 더 이상 표시하지 않기 설정됨:', dontShowAgain);
|
||||
sessionStorage.setItem('dontShowWelcome', 'true');
|
||||
console.log('Index - 환영 팝업 더 이상 표시하지 않기 설정됨:', dontShowAgain);
|
||||
|
||||
// 설정 확인
|
||||
const savedValue = localStorage.getItem('dontShowWelcome');
|
||||
console.log('설정 후 dontShowWelcome 저장값:', savedValue);
|
||||
console.log('Index - 설정 후 dontShowWelcome 저장값:', savedValue);
|
||||
} else {
|
||||
// 체크하지 않은 경우 명시적으로 false 저장
|
||||
localStorage.setItem('dontShowWelcome', 'false');
|
||||
sessionStorage.setItem('dontShowWelcome', 'false');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user