Update last sync time

Ensure the last sync time is updated after adding a budget.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-22 06:18:55 +00:00
parent 0d49c4b8ae
commit eb25423b27
5 changed files with 110 additions and 43 deletions

View File

@@ -46,7 +46,9 @@ export const useManualSync = (user: any) => {
// 동기화 시간 업데이트
if (result.success) {
setLastSyncTime(new Date().toISOString());
const currentTime = new Date().toISOString();
console.log('수동 동기화 성공, 시간 업데이트:', currentTime);
setLastSyncTime(currentTime);
}
return result;

View File

@@ -54,17 +54,35 @@ export const useSyncStatus = () => {
// 동기화 시간이 변경될 때 상태 업데이트
useEffect(() => {
const updateLastSyncTime = () => {
setLastSync(getLastSyncTime());
console.log('useSyncStatus 훅 초기화, 현재 마지막 동기화 시간:', lastSync);
const updateLastSyncTime = (event?: Event | CustomEvent) => {
const newTime = getLastSyncTime();
console.log('마지막 동기화 시간 업데이트됨:', newTime, event instanceof CustomEvent ? `(이벤트 상세: ${JSON.stringify(event.detail)})` : '');
setLastSync(newTime);
};
// 이벤트 리스너 등록
// 이벤트 리스너 등록 - 커스텀 이벤트 사용
window.addEventListener('syncTimeUpdated', updateLastSyncTime);
// 스토리지 이벤트도 모니터링
const handleStorageChange = (event: StorageEvent) => {
if (event.key === 'lastSync' || event.key === null) {
console.log('스토리지 변경 감지 (lastSync):', event.newValue);
updateLastSyncTime();
}
};
window.addEventListener('storage', handleStorageChange);
// 초기 상태 업데이트
updateLastSyncTime();
return () => {
window.removeEventListener('syncTimeUpdated', updateLastSyncTime);
window.removeEventListener('storage', handleStorageChange);
};
}, []);
}, [lastSync]);
return {
lastSync,

View File

@@ -13,6 +13,15 @@ export const useSyncSettings = () => {
const { enabled, setEnabled, handleSyncToggle } = useSyncToggle();
const { syncing, handleManualSync } = useManualSync(user);
const { lastSync, formatLastSyncTime } = useSyncStatus();
// 콘솔에 상태 기록
useEffect(() => {
console.log(`[동기화설정] 상태 변경:
- 활성화: ${enabled ? '예' : '아니오'}
- 진행중: ${syncing ? '예' : '아니오'}
- 마지막동기화: ${lastSync || '없음'}
- 사용자: ${user ? '로그인됨' : '로그인안됨'}`);
}, [enabled, syncing, lastSync, user]);
return {
enabled,