Fix TypeScript and Sync Errors
- Resolves TypeScript errors related to missing exports and incorrect argument counts. - Corrects re-exporting of types to comply with `isolatedModules` setting. - Addresses issues in sync-related files to ensure proper functionality.
This commit is contained in:
@@ -1,40 +1,46 @@
|
|||||||
|
|
||||||
import { toast } from '@/hooks/useToast.wrapper';
|
import { toast } from '@/hooks/useToast.wrapper';
|
||||||
import { SyncResult } from '@/utils/syncUtils';
|
import type { SyncResult } from '@/utils/syncUtils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 동기화 결과 처리 함수
|
* 동기화 결과 처리 함수
|
||||||
*/
|
*/
|
||||||
export const handleSyncResult = (result: SyncResult) => {
|
export const handleSyncResult = (result: SyncResult) => {
|
||||||
|
if (!result) {
|
||||||
|
toast({
|
||||||
|
title: "동기화 오류",
|
||||||
|
description: "동기화 결과를 처리할 수 없습니다.",
|
||||||
|
variant: "destructive"
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
if (result.downloadSuccess && result.uploadSuccess) {
|
if (result.partial) {
|
||||||
|
// 부분 성공 처리
|
||||||
|
toast({
|
||||||
|
title: "부분 동기화 완료",
|
||||||
|
description: "일부 데이터만 동기화되었습니다. 다시 시도해보세요.",
|
||||||
|
variant: "default"
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 전체 성공 처리
|
||||||
toast({
|
toast({
|
||||||
title: "동기화 완료",
|
title: "동기화 완료",
|
||||||
description: "모든 데이터가 클라우드에 동기화되었습니다.",
|
description: "모든 데이터가 성공적으로 동기화되었습니다.",
|
||||||
});
|
variant: "default"
|
||||||
} else if (result.downloadSuccess) {
|
|
||||||
toast({
|
|
||||||
title: "다운로드만 성공",
|
|
||||||
description: "서버 데이터를 가져왔지만, 업로드에 실패했습니다.",
|
|
||||||
variant: "destructive"
|
|
||||||
});
|
|
||||||
} else if (result.uploadSuccess) {
|
|
||||||
toast({
|
|
||||||
title: "업로드만 성공",
|
|
||||||
description: "로컬 데이터를 업로드했지만, 다운로드에 실패했습니다.",
|
|
||||||
variant: "destructive"
|
|
||||||
});
|
|
||||||
} else if (result.partial) {
|
|
||||||
toast({
|
|
||||||
title: "동기화 일부 완료",
|
|
||||||
description: "일부 데이터만 동기화되었습니다. 다시 시도해보세요.",
|
|
||||||
variant: "destructive"
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 데이터 변경 이벤트 발생
|
||||||
|
window.dispatchEvent(new Event('budgetDataUpdated'));
|
||||||
|
window.dispatchEvent(new Event('categoryBudgetsUpdated'));
|
||||||
|
window.dispatchEvent(new Event('transactionUpdated'));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// 실패 처리
|
||||||
toast({
|
toast({
|
||||||
title: "일부 동기화 실패",
|
title: "동기화 실패",
|
||||||
description: "일부 데이터 동기화 중 문제가 발생했습니다. 다시 시도해주세요.",
|
description: "데이터 동기화에 실패했습니다. 나중에 다시 시도해보세요.",
|
||||||
variant: "destructive"
|
variant: "destructive"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
|
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { toast } from '@/hooks/useToast.wrapper';
|
import { toast } from '@/hooks/useToast.wrapper';
|
||||||
import { trySyncAllData, SyncResult } from '@/utils/syncUtils';
|
import { trySyncAllData } from '@/utils/syncUtils';
|
||||||
import { getLastSyncTime, setLastSyncTime } from '@/utils/syncUtils';
|
import { getLastSyncTime, setLastSyncTime } from '@/utils/syncUtils';
|
||||||
import { handleSyncResult } from './syncResultHandler';
|
import { handleSyncResult } from './syncResultHandler';
|
||||||
|
import type { SyncResult } from '@/utils/syncUtils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 수동 동기화 기능을 위한 커스텀 훅
|
* 수동 동기화 기능을 위한 커스텀 훅
|
||||||
@@ -31,14 +32,11 @@ export const useManualSync = (user: any) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
setSyncing(true);
|
setSyncing(true);
|
||||||
// 안전한 동기화 함수 사용 (setSyncState를 더미 함수로 제공)
|
// 인자 수정: 콜백 함수 제거
|
||||||
const result = await trySyncAllData(userId, (state) => {
|
const result = await trySyncAllData(userId);
|
||||||
// 상태 업데이트 콜백 (필요에 따라 처리)
|
|
||||||
console.log('동기화 상태 업데이트:', state);
|
|
||||||
});
|
|
||||||
|
|
||||||
handleSyncResult(result);
|
handleSyncResult(result);
|
||||||
setLastSyncTime(getLastSyncTime());
|
setLastSyncTime(new Date().toISOString());
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('동기화 오류:', error);
|
console.error('동기화 오류:', error);
|
||||||
toast({
|
toast({
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
|
|
||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { useAuth } from '@/contexts/auth';
|
import { useAuth } from '@/contexts/auth';
|
||||||
import { toast } from '@/hooks/useToast.wrapper';
|
import { toast } from '@/hooks/useToast.wrapper';
|
||||||
import {
|
import {
|
||||||
isSyncEnabled,
|
isSyncEnabled,
|
||||||
setSyncEnabled
|
setSyncEnabled,
|
||||||
|
trySyncAllData
|
||||||
} from '@/utils/syncUtils';
|
} from '@/utils/syncUtils';
|
||||||
import { trySyncAllData } from '@/utils/syncUtils';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 동기화 토글 기능을 위한 커스텀 훅
|
* 동기화 토글 기능을 위한 커스텀 훅
|
||||||
@@ -82,7 +81,7 @@ export const useSyncToggle = () => {
|
|||||||
|
|
||||||
if (checked && user) {
|
if (checked && user) {
|
||||||
try {
|
try {
|
||||||
// 동기화 활성화 시 즉시 동기화 실행
|
// 인자 수정: 콜백 함수 제거
|
||||||
await performSync(user.id);
|
await performSync(user.id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('동기화 중 오류, 로컬 데이터 복원 시도:', error);
|
console.error('동기화 중 오류, 로컬 데이터 복원 시도:', error);
|
||||||
@@ -120,11 +119,8 @@ const performSync = async (userId: string) => {
|
|||||||
if (!userId) return;
|
if (!userId) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 안전한 동기화 함수 사용 (setSyncState를 더미 함수로 제공)
|
// 인자 수정: 콜백 함수 제거
|
||||||
const result = await trySyncAllData(userId, (state) => {
|
const result = await trySyncAllData(userId);
|
||||||
// 상태 업데이트 콜백 (필요에 따라 처리)
|
|
||||||
console.log('동기화 상태 업데이트:', state);
|
|
||||||
});
|
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('동기화 오류:', error);
|
console.error('동기화 오류:', error);
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import { supabase } from '@/lib/supabase';
|
import { supabase } from '@/lib/supabase';
|
||||||
import { uploadBudgets, downloadBudgets } from './budget';
|
import { uploadBudgets, downloadBudgets } from './budget';
|
||||||
import { uploadTransactions, downloadTransactions } from './transaction';
|
import { uploadTransactions, downloadTransactions } from './transaction';
|
||||||
@@ -17,9 +16,7 @@ export interface SyncResult {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// 모든 데이터를 동기화합니다 (업로드 우선 수행)
|
||||||
* 모든 데이터를 동기화합니다 (업로드 우선 수행)
|
|
||||||
*/
|
|
||||||
export const syncAllData = async (userId: string): Promise<SyncResult> => {
|
export const syncAllData = async (userId: string): Promise<SyncResult> => {
|
||||||
// 로컬 데이터 백업
|
// 로컬 데이터 백업
|
||||||
const backupBudgetData = localStorage.getItem('budgetData');
|
const backupBudgetData = localStorage.getItem('budgetData');
|
||||||
@@ -160,10 +157,7 @@ export const syncAllData = async (userId: string): Promise<SyncResult> => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// 서버에 대한 안전한 동기화 래퍼 - 인자 수정
|
||||||
* 서버에 대한 안전한 동기화 래퍼
|
|
||||||
* 오류 처리와 재시도 로직을 포함
|
|
||||||
*/
|
|
||||||
export const trySyncAllData = async (userId: string): Promise<SyncResult> => {
|
export const trySyncAllData = async (userId: string): Promise<SyncResult> => {
|
||||||
console.log('안전한 데이터 동기화 시도');
|
console.log('안전한 데이터 동기화 시도');
|
||||||
let attempts = 0;
|
let attempts = 0;
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
|
|
||||||
import { isSyncEnabled, getNetworkStatus, setNetworkStatus, startNetworkMonitoring,
|
import { isSyncEnabled, setSyncEnabled, initSyncSettings } from './sync/config';
|
||||||
stopNetworkMonitoring, onNetworkStatusChange, addToSyncQueue,
|
import { getLastSyncTime, setLastSyncTime } from './sync/time';
|
||||||
processPendingSyncQueue, getLastSyncTime, setLastSyncTime } from './sync/syncSettings';
|
|
||||||
import { trySyncAllData } from './sync/data';
|
import { trySyncAllData } from './sync/data';
|
||||||
import { SyncResult } from './sync/data';
|
|
||||||
import { clearCloudData } from './sync/clearCloudData';
|
import { clearCloudData } from './sync/clearCloudData';
|
||||||
import { setSyncEnabled } from './sync/config';
|
|
||||||
|
// SyncResult 타입 내보내기 수정
|
||||||
|
export type { SyncResult } from './sync/data';
|
||||||
|
|
||||||
// 모든 유틸리티 함수를 동일한 공개 API로 유지하기 위해 내보내기
|
// 모든 유틸리티 함수를 동일한 공개 API로 유지하기 위해 내보내기
|
||||||
export {
|
export {
|
||||||
isSyncEnabled,
|
isSyncEnabled,
|
||||||
setSyncEnabled,
|
setSyncEnabled,
|
||||||
getNetworkStatus,
|
|
||||||
setNetworkStatus,
|
|
||||||
startNetworkMonitoring,
|
|
||||||
stopNetworkMonitoring,
|
|
||||||
onNetworkStatusChange,
|
|
||||||
addToSyncQueue,
|
|
||||||
processPendingSyncQueue,
|
|
||||||
getLastSyncTime,
|
getLastSyncTime,
|
||||||
setLastSyncTime,
|
setLastSyncTime,
|
||||||
trySyncAllData,
|
trySyncAllData,
|
||||||
SyncResult,
|
clearCloudData,
|
||||||
clearCloudData
|
initSyncSettings
|
||||||
|
};
|
||||||
|
|
||||||
|
// App.tsx에서 사용하는 initSyncState 함수 추가
|
||||||
|
export const initSyncState = async (): Promise<void> => {
|
||||||
|
// 동기화 설정 초기화
|
||||||
|
initSyncSettings();
|
||||||
|
console.log('동기화 상태 초기화 완료');
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user