Refactors the useSyncSettings hook into smaller, more manageable modules to improve code organization and maintainability. The functionality of the hook remains unchanged.
32 lines
968 B
TypeScript
32 lines
968 B
TypeScript
|
|
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 };
|
|
};
|