Refactor useSyncToggle hook

Splits the useSyncToggle hook into smaller, more manageable modules for improved code organization and maintainability.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-22 13:45:17 +00:00
parent 6af72b9150
commit e6bc5a8ddc
4 changed files with 155 additions and 105 deletions

View File

@@ -0,0 +1,45 @@
import { checkNetworkStatus } from '@/utils/network/checker';
import { toast } from '@/hooks/useToast.wrapper';
/**
* 동기화를 위한 네트워크 상태 확인
*/
export const checkSyncNetworkStatus = async (): Promise<boolean> => {
// 기본 네트워크 상태 확인 - navigator.onLine 우선 사용
const navigatorOnline = navigator.onLine;
console.log(`[동기화] 기본 네트워크 상태 확인: ${navigatorOnline ? '온라인' : '오프라인'}`);
if (!navigatorOnline) {
return false;
}
// 강화된 네트워크 확인 시도 (실패해도 계속 진행)
try {
const isOnline = await checkNetworkStatus();
console.log(`[동기화] 강화된 네트워크 확인 결과: ${isOnline ? '온라인' : '오프라인'}`);
return isOnline;
} catch (error) {
// 네트워크 확인 실패해도 navigator.onLine이 true면 진행
console.warn('[동기화] 강화된 네트워크 확인 실패, 기본 상태 사용:', error);
return navigatorOnline;
}
};
/**
* 네트워크 오류 시 알림 표시
*/
export const showNetworkErrorNotification = (
addNotification: (title: string, message: string) => void
) => {
const title = "네트워크 연결 필요";
const description = "동기화를 위해 인터넷 연결이 필요합니다.";
toast({
title,
description,
variant: "destructive"
});
addNotification(title, description);
};