Refactor useSyncSettings hook
Refactors the useSyncSettings hook into smaller, more manageable modules to improve code organization and maintainability. The functionality of the hook remains unchanged.
This commit is contained in:
31
src/hooks/sync/useSyncStatus.ts
Normal file
31
src/hooks/sync/useSyncStatus.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { getLastSyncTime } from '@/utils/syncUtils';
|
||||
|
||||
/**
|
||||
* 동기화 상태와 마지막 동기화 시간을 관리하는 커스텀 훅
|
||||
*/
|
||||
export const useSyncStatus = () => {
|
||||
const [lastSync, setLastSync] = useState<string | null>(getLastSyncTime());
|
||||
|
||||
// 마지막 동기화 시간 정기적으로 업데이트
|
||||
useEffect(() => {
|
||||
const intervalId = setInterval(() => {
|
||||
setLastSync(getLastSyncTime());
|
||||
}, 10000); // 10초마다 업데이트
|
||||
|
||||
return () => clearInterval(intervalId);
|
||||
}, []);
|
||||
|
||||
// 마지막 동기화 시간 포맷팅
|
||||
const formatLastSyncTime = () => {
|
||||
if (!lastSync) return "아직 동기화된 적 없음";
|
||||
|
||||
if (lastSync === '부분-다운로드') return "부분 동기화 (다운로드만)";
|
||||
|
||||
const date = new Date(lastSync);
|
||||
return `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`;
|
||||
};
|
||||
|
||||
return { lastSync, formatLastSyncTime };
|
||||
};
|
||||
Reference in New Issue
Block a user