Fix type errors in sync settings

This commit addresses several TypeScript errors in the sync settings component and related utility functions. It corrects type definitions for the sync result, ensures correct usage of the `setLastSyncTime` function, and fixes toast variants.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-16 10:13:54 +00:00
parent b0177ba5cd
commit f2a941c3da
3 changed files with 20 additions and 9 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, trySyncAllData } from "@/utils/syncUtils";
import { isSyncEnabled, setSyncEnabled, syncAllData, getLastSyncTime, trySyncAllData, SyncResult } from "@/utils/syncUtils";
import { toast } from "@/hooks/useToast.wrapper";
import { useAuth } from "@/contexts/auth";
import { useNavigate } from "react-router-dom";
@@ -59,7 +59,7 @@ const SyncSettings = () => {
toast({
title: "동기화 일부 완료",
description: "일부 데이터만 동기화되었습니다. 다시 시도해보세요.",
variant: "warning"
variant: "destructive"
});
} else {
toast({
@@ -115,13 +115,13 @@ const SyncSettings = () => {
toast({
title: "다운로드만 성공",
description: "서버 데이터를 가져왔지만, 업로드에 실패했습니다.",
variant: "warning"
variant: "destructive"
});
} else if (result.uploadSuccess) {
toast({
title: "업로드만 성공",
description: "로컬 데이터를 업로드했지만, 다운로드에 실패했습니다.",
variant: "warning"
variant: "destructive"
});
}
setLastSync(getLastSyncTime());

View File

@@ -13,11 +13,12 @@ export const getLastSyncTime = (): string | null => {
/**
* 마지막 동기화 시간 설정
* @param customValue 설정할 특정 값 (옵션)
*/
export const setLastSyncTime = (): void => {
export const setLastSyncTime = (customValue?: string): void => {
try {
const now = new Date().toISOString();
localStorage.setItem('lastSyncTime', now);
const value = customValue || new Date().toISOString();
localStorage.setItem('lastSyncTime', value);
} catch (error) {
console.error('마지막 동기화 시간 업데이트 중 오류:', error);
}

View File

@@ -49,8 +49,18 @@ export const syncAllData = async (userId: string): Promise<void> => {
}
};
// trySyncAllData의 반환 타입 명시적 정의
// 동기화 결과를 위한 인터페이스 정의
export interface SyncResult {
success: boolean;
partial?: boolean;
downloadSuccess?: boolean;
uploadSuccess?: boolean;
error?: any;
}
// 안전하게 동기화 시도하는 함수 개선
export const trySyncAllData = async (userId: string): Promise<{ success: boolean, error?: any }> => {
export const trySyncAllData = async (userId: string): Promise<SyncResult> => {
if (!userId || !isSyncEnabled()) return { success: true };
let downloadSuccess = false;
@@ -93,7 +103,7 @@ export const trySyncAllData = async (userId: string): Promise<{ success: boolean
}
// 하나라도 성공했으면 부분 성공으로 간주
const result = {
const result: SyncResult = {
success: downloadSuccess || uploadSuccess,
partial: (downloadSuccess && !uploadSuccess) || (!downloadSuccess && uploadSuccess),
downloadSuccess,