Fix sync error after login

Addresses an issue where a sync error occurs after the user logs in.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-16 10:02:27 +00:00
parent bdf1584095
commit 67fc6be649
3 changed files with 101 additions and 18 deletions

View File

@@ -3,7 +3,7 @@ import React, { useState, useEffect } from 'react';
import { Switch } from "@/components/ui/switch";
import { Label } from "@/components/ui/label";
import { CloudUpload, RefreshCw, AlertCircle } from "lucide-react";
import { isSyncEnabled, setSyncEnabled, syncAllData, getLastSyncTime } from "@/utils/syncUtils";
import { isSyncEnabled, setSyncEnabled, syncAllData, getLastSyncTime, trySyncAllData } from "@/utils/syncUtils";
import { toast } from "@/hooks/useToast.wrapper";
import { useAuth } from "@/contexts/auth";
import { useNavigate } from "react-router-dom";
@@ -51,12 +51,22 @@ const SyncSettings = () => {
// 동기화 활성화 시 즉시 동기화 실행
try {
setSyncing(true);
await syncAllData(user.id);
toast({
title: "동기화 설정 완료",
description: "모든 데이터가 클라우드에 동기화되었습니다.",
});
setLastSync(getLastSyncTime());
// 안전한 동기화 함수 사용
const result = await trySyncAllData(user.id);
if (result.success) {
toast({
title: "동기화 설정 완료",
description: "모든 데이터가 클라우드에 동기화되었습니다.",
});
setLastSync(getLastSyncTime());
} else {
toast({
title: "동기화 일부 완료",
description: "일부 데이터가 동기화되지 않았습니다. 나중에 다시 시도해주세요.",
variant: "destructive"
});
}
} catch (error) {
toast({
title: "동기화 오류",
@@ -84,12 +94,22 @@ const SyncSettings = () => {
try {
setSyncing(true);
await syncAllData(user.id);
toast({
title: "동기화 완료",
description: "모든 데이터가 클라우드에 동기화되었습니다.",
});
setLastSync(getLastSyncTime());
// 안전한 동기화 함수 사용
const result = await trySyncAllData(user.id);
if (result.success) {
toast({
title: "동기화 완료",
description: "모든 데이터가 클라우드에 동기화되었습니다.",
});
setLastSync(getLastSyncTime());
} else {
toast({
title: "일부 동기화 실패",
description: "일부 데이터 동기화 중 문제가 발생했습니다.",
variant: "destructive"
});
}
} catch (error) {
toast({
title: "동기화 오류",