This commit is contained in:
MarkLo 2025-12-23 11:12:03 +08:00
parent 06bf068875
commit 50ef9df44c
1 changed files with 23 additions and 7 deletions

View File

@ -27,7 +27,7 @@ import {
DialogHeader, DialogHeader,
DialogTitle, DialogTitle,
} from "@/components/ui/dialog"; } from "@/components/ui/dialog";
import { Trash2, Eye, RefreshCw, TrendingUp, CloudOff, FileText, Download } from "lucide-react"; import { Trash2, Eye, RefreshCw, TrendingUp, FileText, Download } from "lucide-react";
import { import {
getReportsByMarketType, getReportsByMarketType,
deleteReport, deleteReport,
@ -35,7 +35,7 @@ import {
type SavedReport, type SavedReport,
} from "@/lib/reports-db"; } from "@/lib/reports-db";
import { getCloudReports, deleteCloudReport, saveCloudReport, isCloudSyncEnabled } from "@/lib/user-api"; import { getCloudReports, deleteCloudReport, saveCloudReport, isCloudSyncEnabled } from "@/lib/user-api";
import { LoginPrompt } from "@/components/auth/login-button"; // import { LoginPrompt } from "@/components/auth/login-button";
import { PendingTaskRecovery } from "@/components/PendingTaskRecovery"; import { PendingTaskRecovery } from "@/components/PendingTaskRecovery";
// Analyst definitions for download // Analyst definitions for download
@ -424,13 +424,29 @@ export default function HistoryPage() {
setDeleting(true); setDeleting(true);
try { try {
// If this is cloud data, delete from cloud
const cloudId = (reportToDelete as any).cloudId; const cloudId = (reportToDelete as any).cloudId;
if (isCloudData && cloudId) {
// IMPORTANT: Delete from BOTH cloud AND local to prevent re-sync issues
// 1. If cloud ID exists, delete from cloud
if (cloudId) {
console.log("🗑️ Deleting from cloud:", cloudId);
await deleteCloudReport(cloudId); await deleteCloudReport(cloudId);
} else if (reportToDelete.id) { }
// Delete from local IndexedDB
await deleteReport(reportToDelete.id); // 2. Always try to delete from local IndexedDB as well
// Find matching local report by ticker + analysis_date
try {
const localReports = await getReportsByMarketType(reportToDelete.market_type);
const matchingLocal = localReports.find(
r => r.ticker === reportToDelete.ticker &&
r.analysis_date === reportToDelete.analysis_date
);
if (matchingLocal && matchingLocal.id) {
console.log("🗑️ Deleting from local IndexedDB:", matchingLocal.id);
await deleteReport(matchingLocal.id);
}
} catch (localError) {
console.warn("Could not delete local copy:", localError);
} }
// Refresh reports and counts // Refresh reports and counts