From dab1a9cb845e17c7f85c34f2ed605eab3834d18e Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sun, 16 Mar 2025 10:30:38 +0000 Subject: [PATCH] Fix budget synchronization issue Ensure budget data is also synchronized when syncing with cloud after local data deletion. --- src/components/SyncSettings.tsx | 1 - src/utils/sync/budget/downloadBudget.ts | 9 +++++++-- src/utils/syncUtils.ts | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/SyncSettings.tsx b/src/components/SyncSettings.tsx index 06a06f5..5137604 100644 --- a/src/components/SyncSettings.tsx +++ b/src/components/SyncSettings.tsx @@ -1,4 +1,3 @@ - import React, { useState, useEffect } from 'react'; import { Switch } from "@/components/ui/switch"; import { Label } from "@/components/ui/label"; diff --git a/src/utils/sync/budget/downloadBudget.ts b/src/utils/sync/budget/downloadBudget.ts index 49b8b3f..3c204e2 100644 --- a/src/utils/sync/budget/downloadBudget.ts +++ b/src/utils/sync/budget/downloadBudget.ts @@ -42,12 +42,17 @@ export const downloadBudgets = async (userId: string): Promise => { * 예산 데이터 조회 */ async function fetchBudgetData(userId: string) { + // 현재 월/년도 가져오기 + const now = new Date(); + const currentMonth = now.getMonth() + 1; // 0-11 -> 1-12 + const currentYear = now.getFullYear(); + const { data, error } = await supabase .from('budgets') .select('*') .eq('user_id', userId) - .order('created_at', { ascending: false }) - .limit(1); // 가장 최근 데이터 + .eq('month', currentMonth) + .eq('year', currentYear); if (error) { console.error('예산 데이터 조회 실패:', error); diff --git a/src/utils/syncUtils.ts b/src/utils/syncUtils.ts index 7b879bf..6d1c5f7 100644 --- a/src/utils/syncUtils.ts +++ b/src/utils/syncUtils.ts @@ -1,3 +1,4 @@ + import { isSyncEnabled, setSyncEnabled, getLastSyncTime, setLastSyncTime, initSyncSettings } from './sync/syncSettings'; import { uploadTransactions, downloadTransactions, deleteTransactionFromServer } from './sync/transactionSync'; import { uploadBudgets, downloadBudgets } from './sync/budget';