Fix: Use correct safeStorage methods
The `safeStorage` object in `budgetUtils.ts` defines `get`, `set`, and `remove` methods, but the `budgetStorage.ts` file is using `getItem`, `setItem`, and `removeItem`. This commit updates `budgetStorage.ts` to use the correct methods from `safeStorage`.
This commit is contained in:
@@ -40,7 +40,7 @@ export const saveBudgetDataToStorage = (budgetData: BudgetData): void => {
|
||||
// 이전 예산과 비교하여 변경 여부 확인
|
||||
let hasChanged = true;
|
||||
try {
|
||||
const oldData = safeStorage.get('budgetData');
|
||||
const oldData = safeStorage.getItem('budgetData');
|
||||
if (oldData) {
|
||||
// 월간 예산이 동일하면 변경되지 않은 것으로 판단
|
||||
hasChanged = oldData.monthly.targetAmount !== budgetData.monthly.targetAmount;
|
||||
@@ -50,12 +50,12 @@ export const saveBudgetDataToStorage = (budgetData: BudgetData): void => {
|
||||
}
|
||||
|
||||
// 로컬 스토리지에 저장
|
||||
safeStorage.set('budgetData', budgetData);
|
||||
safeStorage.setItem('budgetData', budgetData);
|
||||
console.log('예산 데이터 저장 완료', budgetData);
|
||||
|
||||
// 중요: 즉시 자동 백업 (데이터 손실 방지)
|
||||
safeStorage.set('budgetData_backup', budgetData);
|
||||
safeStorage.set('lastBudgetSaveTime', new Date().toISOString());
|
||||
safeStorage.setItem('budgetData_backup', budgetData);
|
||||
safeStorage.setItem('lastBudgetSaveTime', new Date().toISOString());
|
||||
|
||||
// 이벤트 발생 (단일 이벤트로 통합)
|
||||
const event = new CustomEvent('budgetChanged', {
|
||||
@@ -87,13 +87,13 @@ export const saveBudgetDataToStorage = (budgetData: BudgetData): void => {
|
||||
*/
|
||||
export const clearAllBudgetData = (): void => {
|
||||
try {
|
||||
safeStorage.remove('budgetData');
|
||||
safeStorage.remove('budgetData_backup');
|
||||
localStorage.removeItem('budgetData');
|
||||
localStorage.removeItem('budgetData_backup');
|
||||
|
||||
// 기본값으로 재설정
|
||||
const initialData = getInitialBudgetData();
|
||||
safeStorage.set('budgetData', initialData);
|
||||
safeStorage.set('budgetData_backup', initialData);
|
||||
safeStorage.setItem('budgetData', initialData);
|
||||
safeStorage.setItem('budgetData_backup', initialData);
|
||||
|
||||
console.log('예산 데이터가 초기화되었습니다.');
|
||||
|
||||
|
||||
@@ -13,6 +13,39 @@ const PRESERVE_KEYS = [
|
||||
'supabase-auth',
|
||||
];
|
||||
|
||||
/**
|
||||
* 안전한 로컬 스토리지 작업을 위한 유틸리티 객체
|
||||
*/
|
||||
export const safeStorage = {
|
||||
setItem: (key: string, value: any) => {
|
||||
try {
|
||||
localStorage.setItem(key, JSON.stringify(value));
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.error(`스토리지 저장 오류 (${key}):`, err);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
getItem: (key: string, defaultValue: any = null) => {
|
||||
try {
|
||||
const item = localStorage.getItem(key);
|
||||
return item ? JSON.parse(item) : defaultValue;
|
||||
} catch (err) {
|
||||
console.error(`스토리지 로드 오류 (${key}):`, err);
|
||||
return defaultValue;
|
||||
}
|
||||
},
|
||||
removeItem: (key: string) => {
|
||||
try {
|
||||
localStorage.removeItem(key);
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.error(`스토리지 삭제 오류 (${key}):`, err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 모든 로컬 스토리지 데이터 초기화 (보존할 항목 제외)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user