Fix welcome message and sync

- Prevent duplicate welcome messages.
- Remove sync notifications.
- Ensure automatic sync updates last sync time.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-22 06:26:05 +00:00
parent eb25423b27
commit 09894589b4
8 changed files with 173 additions and 27 deletions

View File

@@ -5,8 +5,10 @@ import { toast } from '@/hooks/useToast.wrapper';
import {
isSyncEnabled,
setSyncEnabled,
trySyncAllData
trySyncAllData,
setLastSyncTime
} from '@/utils/syncUtils';
import useNotifications from '@/hooks/useNotifications';
/**
* 동기화 토글 기능을 위한 커스텀 훅
@@ -14,6 +16,7 @@ import {
export const useSyncToggle = () => {
const [enabled, setEnabled] = useState(isSyncEnabled());
const { user } = useAuth();
const { addNotification } = useNotifications();
// 사용자 로그인 상태 변경 감지
useEffect(() => {
@@ -60,6 +63,11 @@ export const useSyncToggle = () => {
description: "데이터 동기화를 위해 로그인이 필요합니다.",
variant: "destructive"
});
addNotification(
"로그인 필요",
"데이터 동기화를 위해 로그인이 필요합니다."
);
return;
}
@@ -77,13 +85,28 @@ export const useSyncToggle = () => {
setEnabled(checked);
setSyncEnabled(checked);
// 동기화 활성화/비활성화 알림 추가
addNotification(
checked ? "동기화 활성화" : "동기화 비활성화",
checked
? "데이터가 클라우드와 동기화됩니다."
: "클라우드 동기화가 중지되었습니다."
);
// 이벤트 트리거
window.dispatchEvent(new Event('auth-state-changed'));
if (checked && user) {
try {
// 동기화 수행
await performSync(user.id);
const result = await performSync(user.id);
// 동기화 성공 시 마지막 동기화 시간 업데이트
if (result && result.success) {
const currentTime = new Date().toISOString();
console.log('동기화 활성화 후 첫 동기화 성공, 시간 업데이트:', currentTime);
setLastSyncTime(currentTime);
}
} catch (error) {
console.error('동기화 중 오류, 로컬 데이터 복원 시도:', error);
@@ -108,6 +131,11 @@ export const useSyncToggle = () => {
description: "동기화 중 문제가 발생하여 로컬 데이터가 복원되었습니다.",
variant: "destructive"
});
addNotification(
"동기화 오류",
"동기화 중 문제가 발생하여 로컬 데이터가 복원되었습니다."
);
}
}
};