Fix budget synchronization issue

Ensure budget data is also synchronized when syncing with cloud after local data deletion.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-16 10:30:38 +00:00
parent 8b7defb576
commit dab1a9cb84
3 changed files with 8 additions and 3 deletions

View File

@@ -1,4 +1,3 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { Switch } from "@/components/ui/switch"; import { Switch } from "@/components/ui/switch";
import { Label } from "@/components/ui/label"; import { Label } from "@/components/ui/label";

View File

@@ -42,12 +42,17 @@ export const downloadBudgets = async (userId: string): Promise<void> => {
* 예산 데이터 조회 * 예산 데이터 조회
*/ */
async function fetchBudgetData(userId: string) { 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 const { data, error } = await supabase
.from('budgets') .from('budgets')
.select('*') .select('*')
.eq('user_id', userId) .eq('user_id', userId)
.order('created_at', { ascending: false }) .eq('month', currentMonth)
.limit(1); // 가장 최근 데이터 .eq('year', currentYear);
if (error) { if (error) {
console.error('예산 데이터 조회 실패:', error); console.error('예산 데이터 조회 실패:', error);

View File

@@ -1,3 +1,4 @@
import { isSyncEnabled, setSyncEnabled, getLastSyncTime, setLastSyncTime, initSyncSettings } from './sync/syncSettings'; import { isSyncEnabled, setSyncEnabled, getLastSyncTime, setLastSyncTime, initSyncSettings } from './sync/syncSettings';
import { uploadTransactions, downloadTransactions, deleteTransactionFromServer } from './sync/transactionSync'; import { uploadTransactions, downloadTransactions, deleteTransactionFromServer } from './sync/transactionSync';
import { uploadBudgets, downloadBudgets } from './sync/budget'; import { uploadBudgets, downloadBudgets } from './sync/budget';