Spaces:
Sleeping
Sleeping
Commit ·
7690d42
1
Parent(s): a2ef75b
Add Recycle Bin (Papelera) and 30-day soft delete recovery system
Browse files- App.tsx +33 -6
- components/TrashModal.tsx +270 -0
- package-lock.json +7 -7
- services/firebase.ts +50 -1
- types.ts +2 -0
App.tsx
CHANGED
|
@@ -10,7 +10,8 @@ import { subscribeToStyleConfig } from './services/codeStyleService';
|
|
| 10 |
import { BulkCategoryModal } from './components/BulkCategoryModal';
|
| 11 |
import { ConfirmModal } from './components/ConfirmModal';
|
| 12 |
import { MoveToFolderModal } from './components/MoveToFolderModal';
|
| 13 |
-
import {
|
|
|
|
| 14 |
|
| 15 |
const App: React.FC = () => {
|
| 16 |
const [items, setItems] = useState<DataItem[]>([]);
|
|
@@ -81,6 +82,7 @@ const App: React.FC = () => {
|
|
| 81 |
|
| 82 |
const [showConfirmDelete, setShowConfirmDelete] = useState(false);
|
| 83 |
const [showMoveToFolder, setShowMoveToFolder] = useState(false);
|
|
|
|
| 84 |
|
| 85 |
const ITEMS_PER_PAGE = 20;
|
| 86 |
|
|
@@ -306,8 +308,11 @@ const App: React.FC = () => {
|
|
| 306 |
return () => unsubscribe();
|
| 307 |
}, []);
|
| 308 |
|
|
|
|
|
|
|
|
|
|
| 309 |
const filteredItems = useMemo(() => {
|
| 310 |
-
const inFolder =
|
| 311 |
|
| 312 |
if (!searchQuery.trim()) {
|
| 313 |
const sorted = [...inFolder];
|
|
@@ -369,8 +374,8 @@ const App: React.FC = () => {
|
|
| 369 |
return score;
|
| 370 |
};
|
| 371 |
|
| 372 |
-
// 1. Score ALL items in the database regardless of folder
|
| 373 |
-
const allScored =
|
| 374 |
.map(item => ({ item, score: getScore(item) }))
|
| 375 |
.filter(entry => entry.score > 0);
|
| 376 |
|
|
@@ -389,7 +394,7 @@ const App: React.FC = () => {
|
|
| 389 |
break;
|
| 390 |
}
|
| 391 |
seenIds.add(currentItem.id);
|
| 392 |
-
const parent =
|
| 393 |
if (!parent) {
|
| 394 |
valid = false; // Broken link or orphaned item, ignore
|
| 395 |
break;
|
|
@@ -431,7 +436,7 @@ const App: React.FC = () => {
|
|
| 431 |
|
| 432 |
return scoredItems.map(entry => entry.item);
|
| 433 |
|
| 434 |
-
}, [
|
| 435 |
|
| 436 |
// Reset to first page when search or sort changes
|
| 437 |
useEffect(() => {
|
|
@@ -738,6 +743,21 @@ const App: React.FC = () => {
|
|
| 738 |
)}
|
| 739 |
</Button>
|
| 740 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 741 |
<div className="relative">
|
| 742 |
<Button
|
| 743 |
variant="secondary"
|
|
@@ -1297,6 +1317,13 @@ const App: React.FC = () => {
|
|
| 1297 |
}
|
| 1298 |
}}
|
| 1299 |
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1300 |
</div>
|
| 1301 |
);
|
| 1302 |
};
|
|
|
|
| 10 |
import { BulkCategoryModal } from './components/BulkCategoryModal';
|
| 11 |
import { ConfirmModal } from './components/ConfirmModal';
|
| 12 |
import { MoveToFolderModal } from './components/MoveToFolderModal';
|
| 13 |
+
import { TrashModal } from './components/TrashModal';
|
| 14 |
+
import { Folder, Trash2, RotateCcw } from 'lucide-react';
|
| 15 |
|
| 16 |
const App: React.FC = () => {
|
| 17 |
const [items, setItems] = useState<DataItem[]>([]);
|
|
|
|
| 82 |
|
| 83 |
const [showConfirmDelete, setShowConfirmDelete] = useState(false);
|
| 84 |
const [showMoveToFolder, setShowMoveToFolder] = useState(false);
|
| 85 |
+
const [isTrashOpen, setIsTrashOpen] = useState(false);
|
| 86 |
|
| 87 |
const ITEMS_PER_PAGE = 20;
|
| 88 |
|
|
|
|
| 308 |
return () => unsubscribe();
|
| 309 |
}, []);
|
| 310 |
|
| 311 |
+
const activeItems = useMemo(() => items.filter(i => !i.isDeleted), [items]);
|
| 312 |
+
const deletedItems = useMemo(() => items.filter(i => i.isDeleted === true), [items]);
|
| 313 |
+
|
| 314 |
const filteredItems = useMemo(() => {
|
| 315 |
+
const inFolder = activeItems.filter(i => (i.parentId || null) === currentFolderId);
|
| 316 |
|
| 317 |
if (!searchQuery.trim()) {
|
| 318 |
const sorted = [...inFolder];
|
|
|
|
| 374 |
return score;
|
| 375 |
};
|
| 376 |
|
| 377 |
+
// 1. Score ALL active items in the database regardless of folder
|
| 378 |
+
const allScored = activeItems
|
| 379 |
.map(item => ({ item, score: getScore(item) }))
|
| 380 |
.filter(entry => entry.score > 0);
|
| 381 |
|
|
|
|
| 394 |
break;
|
| 395 |
}
|
| 396 |
seenIds.add(currentItem.id);
|
| 397 |
+
const parent = activeItems.find(i => i.id === currentItem.parentId);
|
| 398 |
if (!parent) {
|
| 399 |
valid = false; // Broken link or orphaned item, ignore
|
| 400 |
break;
|
|
|
|
| 436 |
|
| 437 |
return scoredItems.map(entry => entry.item);
|
| 438 |
|
| 439 |
+
}, [activeItems, searchQuery, sortOrder, currentFolderId]);
|
| 440 |
|
| 441 |
// Reset to first page when search or sort changes
|
| 442 |
useEffect(() => {
|
|
|
|
| 743 |
)}
|
| 744 |
</Button>
|
| 745 |
|
| 746 |
+
<Button
|
| 747 |
+
variant="secondary"
|
| 748 |
+
onClick={() => setIsTrashOpen(true)}
|
| 749 |
+
className="bg-surface border border-white/5 hover:bg-surfaceHover !px-3 sm:!px-4 justify-center flex items-center gap-2 relative transition-all hover:scale-105 active:scale-95"
|
| 750 |
+
title="Papelera de Reciclaje"
|
| 751 |
+
>
|
| 752 |
+
<Trash2 size={18} className={deletedItems.length > 0 ? "text-red-400" : "text-gray-400"} />
|
| 753 |
+
<span className="hidden sm:inline font-medium">Papelera</span>
|
| 754 |
+
{deletedItems.length > 0 && (
|
| 755 |
+
<span className="ml-1 text-xs px-1.5 py-0.5 rounded-full bg-red-500/20 text-red-300 font-bold border border-red-500/30">
|
| 756 |
+
{deletedItems.length}
|
| 757 |
+
</span>
|
| 758 |
+
)}
|
| 759 |
+
</Button>
|
| 760 |
+
|
| 761 |
<div className="relative">
|
| 762 |
<Button
|
| 763 |
variant="secondary"
|
|
|
|
| 1317 |
}
|
| 1318 |
}}
|
| 1319 |
/>
|
| 1320 |
+
|
| 1321 |
+
<TrashModal
|
| 1322 |
+
isOpen={isTrashOpen}
|
| 1323 |
+
onClose={() => setIsTrashOpen(false)}
|
| 1324 |
+
deletedItems={deletedItems}
|
| 1325 |
+
allFolders={items.filter(i => i.isFolder)}
|
| 1326 |
+
/>
|
| 1327 |
</div>
|
| 1328 |
);
|
| 1329 |
};
|
components/TrashModal.tsx
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useState } from 'react';
|
| 2 |
+
import { DataItem } from '../types';
|
| 3 |
+
import { Trash2, RotateCcw, X, Folder, AlertTriangle, RefreshCw, Layers } from 'lucide-react';
|
| 4 |
+
import { restoreItem, restoreAllItems, permanentlyDeleteItem, emptyTrash } from '../services/firebase';
|
| 5 |
+
|
| 6 |
+
interface TrashModalProps {
|
| 7 |
+
isOpen: boolean;
|
| 8 |
+
onClose: () => void;
|
| 9 |
+
deletedItems: DataItem[];
|
| 10 |
+
allFolders: DataItem[];
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
export const TrashModal: React.FC<TrashModalProps> = ({ isOpen, onClose, deletedItems, allFolders }) => {
|
| 14 |
+
const [loadingAction, setLoadingAction] = useState<string | null>(null);
|
| 15 |
+
const [showConfirmEmpty, setShowConfirmEmpty] = useState(false);
|
| 16 |
+
|
| 17 |
+
if (!isOpen) return null;
|
| 18 |
+
|
| 19 |
+
// Filter items deleted in the last 30 days
|
| 20 |
+
const THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1000;
|
| 21 |
+
const now = Date.now();
|
| 22 |
+
const validDeletedItems = deletedItems.filter(item => {
|
| 23 |
+
if (!item.deletedAt) return true;
|
| 24 |
+
return (now - item.deletedAt) <= THIRTY_DAYS_MS;
|
| 25 |
+
});
|
| 26 |
+
|
| 27 |
+
const getFolderName = (parentId?: string | null) => {
|
| 28 |
+
if (!parentId) return 'Raíz';
|
| 29 |
+
const folder = allFolders.find(f => f.id === parentId);
|
| 30 |
+
if (!folder) return 'Carpeta anterior';
|
| 31 |
+
const raw = (folder.title || '').replace(/<[^>]*>?/gm, '').replace(/ /g, ' ').trim() || folder.title;
|
| 32 |
+
return raw || 'Carpeta anterior';
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
const getTimeAgo = (timestamp?: number) => {
|
| 36 |
+
if (!timestamp) return 'Recientemente';
|
| 37 |
+
const diff = now - timestamp;
|
| 38 |
+
const minutes = Math.floor(diff / (1000 * 60));
|
| 39 |
+
const hours = Math.floor(diff / (1000 * 60 * 60));
|
| 40 |
+
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
|
| 41 |
+
|
| 42 |
+
if (days > 0) return `Hace ${days} día${days > 1 ? 's' : ''}`;
|
| 43 |
+
if (hours > 0) return `Hace ${hours} hora${hours > 1 ? 's' : ''}`;
|
| 44 |
+
if (minutes > 0) return `Hace ${minutes} min`;
|
| 45 |
+
return 'Hace un momento';
|
| 46 |
+
};
|
| 47 |
+
|
| 48 |
+
const getRemainingDays = (timestamp?: number) => {
|
| 49 |
+
if (!timestamp) return 30;
|
| 50 |
+
const diff = now - timestamp;
|
| 51 |
+
const daysLeft = Math.max(0, 30 - Math.floor(diff / (1000 * 60 * 60 * 24)));
|
| 52 |
+
return daysLeft;
|
| 53 |
+
};
|
| 54 |
+
|
| 55 |
+
const handleRestoreOne = async (item: DataItem) => {
|
| 56 |
+
try {
|
| 57 |
+
setLoadingAction(item.id);
|
| 58 |
+
await restoreItem(item.id);
|
| 59 |
+
} catch (e) {
|
| 60 |
+
alert('Error al restaurar el elemento.');
|
| 61 |
+
} finally {
|
| 62 |
+
setLoadingAction(null);
|
| 63 |
+
}
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
const handleRestoreAll = async () => {
|
| 67 |
+
if (validDeletedItems.length === 0) return;
|
| 68 |
+
try {
|
| 69 |
+
setLoadingAction('ALL');
|
| 70 |
+
await restoreAllItems(validDeletedItems.map(i => i.id));
|
| 71 |
+
} catch (e) {
|
| 72 |
+
alert('Error al restaurar todos los elementos.');
|
| 73 |
+
} finally {
|
| 74 |
+
setLoadingAction(null);
|
| 75 |
+
}
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
const handleDeletePermanent = async (item: DataItem) => {
|
| 79 |
+
if (!confirm(`¿Eliminar permanentemente "${item.title.replace(/<[^>]*>?/gm, '')}"? Esta acción no se puede deshacer.`)) return;
|
| 80 |
+
try {
|
| 81 |
+
setLoadingAction(item.id);
|
| 82 |
+
await permanentlyDeleteItem(item.id);
|
| 83 |
+
} catch (e) {
|
| 84 |
+
alert('Error al eliminar el elemento.');
|
| 85 |
+
} finally {
|
| 86 |
+
setLoadingAction(null);
|
| 87 |
+
}
|
| 88 |
+
};
|
| 89 |
+
|
| 90 |
+
const handleEmptyTrash = async () => {
|
| 91 |
+
try {
|
| 92 |
+
setLoadingAction('EMPTY');
|
| 93 |
+
await emptyTrash(validDeletedItems.map(i => i.id));
|
| 94 |
+
setShowConfirmEmpty(false);
|
| 95 |
+
} catch (e) {
|
| 96 |
+
alert('Error al vaciar la papelera.');
|
| 97 |
+
} finally {
|
| 98 |
+
setLoadingAction(null);
|
| 99 |
+
}
|
| 100 |
+
};
|
| 101 |
+
|
| 102 |
+
return (
|
| 103 |
+
<div className="fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/70 backdrop-blur-md animate-in fade-in duration-200">
|
| 104 |
+
<div className="bg-[#18181b] border border-white/10 rounded-2xl w-full max-w-3xl max-h-[85vh] flex flex-col shadow-2xl overflow-hidden animate-in zoom-in-95 duration-200">
|
| 105 |
+
|
| 106 |
+
{/* Header */}
|
| 107 |
+
<div className="p-6 border-b border-white/10 flex items-center justify-between bg-white/[0.02]">
|
| 108 |
+
<div className="flex items-center gap-3">
|
| 109 |
+
<div className="p-3 bg-red-500/10 border border-red-500/20 rounded-xl text-red-400">
|
| 110 |
+
<Trash2 size={24} />
|
| 111 |
+
</div>
|
| 112 |
+
<div>
|
| 113 |
+
<h2 className="text-xl font-bold text-white flex items-center gap-2">
|
| 114 |
+
Papelera de Reciclaje
|
| 115 |
+
<span className="text-xs px-2.5 py-0.5 rounded-full bg-red-500/20 text-red-300 font-semibold border border-red-500/30">
|
| 116 |
+
{validDeletedItems.length} {validDeletedItems.length === 1 ? 'elemento' : 'elementos'}
|
| 117 |
+
</span>
|
| 118 |
+
</h2>
|
| 119 |
+
<p className="text-sm text-gray-400">
|
| 120 |
+
Los elementos eliminados se conservan por 30 días antes de ser purgados.
|
| 121 |
+
</p>
|
| 122 |
+
</div>
|
| 123 |
+
</div>
|
| 124 |
+
<button
|
| 125 |
+
onClick={onClose}
|
| 126 |
+
className="p-2 text-gray-400 hover:text-white rounded-lg hover:bg-white/10 transition-colors"
|
| 127 |
+
>
|
| 128 |
+
<X size={20} />
|
| 129 |
+
</button>
|
| 130 |
+
</div>
|
| 131 |
+
|
| 132 |
+
{/* Top Control Bar */}
|
| 133 |
+
{validDeletedItems.length > 0 && (
|
| 134 |
+
<div className="px-6 py-3 bg-white/[0.01] border-b border-white/5 flex items-center justify-between flex-wrap gap-3">
|
| 135 |
+
<button
|
| 136 |
+
onClick={handleRestoreAll}
|
| 137 |
+
disabled={loadingAction === 'ALL'}
|
| 138 |
+
className="flex items-center gap-2 px-4 py-2 bg-primary text-background font-semibold rounded-xl hover:bg-primary/90 transition-all shadow-md active:scale-95 disabled:opacity-50"
|
| 139 |
+
>
|
| 140 |
+
<RotateCcw size={16} />
|
| 141 |
+
Restaurar Todo ({validDeletedItems.length})
|
| 142 |
+
</button>
|
| 143 |
+
|
| 144 |
+
<button
|
| 145 |
+
onClick={() => setShowConfirmEmpty(true)}
|
| 146 |
+
disabled={loadingAction === 'EMPTY'}
|
| 147 |
+
className="flex items-center gap-2 px-4 py-2 bg-red-500/10 text-red-400 hover:bg-red-500/20 border border-red-500/20 font-medium rounded-xl transition-all active:scale-95 disabled:opacity-50"
|
| 148 |
+
>
|
| 149 |
+
<Trash2 size={16} />
|
| 150 |
+
Vaciar Papelera
|
| 151 |
+
</button>
|
| 152 |
+
</div>
|
| 153 |
+
)}
|
| 154 |
+
|
| 155 |
+
{/* Content Body */}
|
| 156 |
+
<div className="flex-1 overflow-y-auto p-6 space-y-3">
|
| 157 |
+
{validDeletedItems.length === 0 ? (
|
| 158 |
+
<div className="py-16 text-center flex flex-col items-center justify-center">
|
| 159 |
+
<div className="w-16 h-16 rounded-full bg-white/5 flex items-center justify-center text-gray-500 mb-4 border border-white/5">
|
| 160 |
+
<Trash2 size={32} />
|
| 161 |
+
</div>
|
| 162 |
+
<h3 className="text-lg font-semibold text-white mb-1">La papelera está vacía</h3>
|
| 163 |
+
<p className="text-sm text-gray-400 max-w-sm">
|
| 164 |
+
No hay elementos eliminados en los últimos 30 días. Todos tus archivos y voces se conservan en tus carpetas.
|
| 165 |
+
</p>
|
| 166 |
+
</div>
|
| 167 |
+
) : (
|
| 168 |
+
validDeletedItems.map(item => {
|
| 169 |
+
const cleanTitle = (item.title || '').replace(/<[^>]*>?/gm, '').replace(/ /g, ' ') || 'Sin título';
|
| 170 |
+
const isFolder = item.isFolder;
|
| 171 |
+
const folderName = getFolderName(item.parentId);
|
| 172 |
+
const remainingDays = getRemainingDays(item.deletedAt);
|
| 173 |
+
|
| 174 |
+
return (
|
| 175 |
+
<div
|
| 176 |
+
key={item.id}
|
| 177 |
+
className="p-4 bg-surface hover:bg-white/[0.03] border border-white/5 hover:border-white/10 rounded-xl flex items-center justify-between gap-4 transition-all"
|
| 178 |
+
>
|
| 179 |
+
<div className="flex items-center gap-3.5 min-w-0 flex-1">
|
| 180 |
+
<div className={`p-2.5 rounded-lg shrink-0 ${isFolder ? 'bg-primary/10 text-primary' : 'bg-white/5 text-gray-300'}`}>
|
| 181 |
+
{isFolder ? <Folder size={20} /> : <Layers size={20} />}
|
| 182 |
+
</div>
|
| 183 |
+
<div className="min-w-0 flex-1">
|
| 184 |
+
<h4 className="font-semibold text-white truncate text-base" title={cleanTitle}>
|
| 185 |
+
{cleanTitle}
|
| 186 |
+
</h4>
|
| 187 |
+
<div className="flex items-center gap-3 text-xs text-gray-400 mt-0.5 flex-wrap">
|
| 188 |
+
<span className="flex items-center gap-1 text-gray-400">
|
| 189 |
+
📁 {folderName}
|
| 190 |
+
</span>
|
| 191 |
+
<span>•</span>
|
| 192 |
+
<span>{getTimeAgo(item.deletedAt)}</span>
|
| 193 |
+
<span>•</span>
|
| 194 |
+
<span className="text-amber-400/90 font-medium">
|
| 195 |
+
Expira en {remainingDays} día{remainingDays !== 1 ? 's' : ''}
|
| 196 |
+
</span>
|
| 197 |
+
</div>
|
| 198 |
+
</div>
|
| 199 |
+
</div>
|
| 200 |
+
|
| 201 |
+
{/* Actions for single item */}
|
| 202 |
+
<div className="flex items-center gap-2 shrink-0">
|
| 203 |
+
<button
|
| 204 |
+
onClick={() => handleRestoreOne(item)}
|
| 205 |
+
disabled={loadingAction === item.id}
|
| 206 |
+
className="flex items-center gap-1.5 px-3 py-1.5 bg-primary/10 hover:bg-primary/20 text-primary border border-primary/20 rounded-lg font-medium text-xs transition-colors active:scale-95"
|
| 207 |
+
>
|
| 208 |
+
<RotateCcw size={14} />
|
| 209 |
+
Restaurar
|
| 210 |
+
</button>
|
| 211 |
+
<button
|
| 212 |
+
onClick={() => handleDeletePermanent(item)}
|
| 213 |
+
disabled={loadingAction === item.id}
|
| 214 |
+
className="p-1.5 text-gray-400 hover:text-red-400 hover:bg-red-500/10 rounded-lg transition-colors"
|
| 215 |
+
title="Eliminar permanentemente"
|
| 216 |
+
>
|
| 217 |
+
<Trash2 size={16} />
|
| 218 |
+
</button>
|
| 219 |
+
</div>
|
| 220 |
+
</div>
|
| 221 |
+
);
|
| 222 |
+
})
|
| 223 |
+
)}
|
| 224 |
+
</div>
|
| 225 |
+
|
| 226 |
+
{/* Footer */}
|
| 227 |
+
<div className="p-4 border-t border-white/10 bg-white/[0.01] flex items-center justify-between text-xs text-gray-400">
|
| 228 |
+
<span>Sistema de Recuperación Automática (30 días)</span>
|
| 229 |
+
<button
|
| 230 |
+
onClick={onClose}
|
| 231 |
+
className="px-4 py-2 bg-surface hover:bg-white/10 text-white rounded-lg transition-colors font-medium text-xs"
|
| 232 |
+
>
|
| 233 |
+
Cerrar
|
| 234 |
+
</button>
|
| 235 |
+
</div>
|
| 236 |
+
|
| 237 |
+
</div>
|
| 238 |
+
|
| 239 |
+
{/* Confirmation Modal for Empty Trash */}
|
| 240 |
+
{showConfirmEmpty && (
|
| 241 |
+
<div className="fixed inset-0 z-[110] flex items-center justify-center p-4 bg-black/80 backdrop-blur-sm animate-in fade-in duration-200">
|
| 242 |
+
<div className="bg-[#18181b] border border-red-500/30 rounded-xl p-6 max-w-md w-full shadow-2xl animate-in zoom-in-95 duration-200 text-center">
|
| 243 |
+
<div className="w-12 h-12 rounded-full bg-red-500/10 border border-red-500/20 text-red-400 flex items-center justify-center mx-auto mb-4">
|
| 244 |
+
<AlertTriangle size={24} />
|
| 245 |
+
</div>
|
| 246 |
+
<h3 className="text-lg font-bold text-white mb-2">¿Vaciar la papelera?</h3>
|
| 247 |
+
<p className="text-sm text-gray-400 mb-6">
|
| 248 |
+
Esta acción eliminará **permanentemente** todos los {validDeletedItems.length} elementos de la papelera. No podrás recuperarlos después.
|
| 249 |
+
</p>
|
| 250 |
+
<div className="flex items-center justify-center gap-3">
|
| 251 |
+
<button
|
| 252 |
+
onClick={() => setShowConfirmEmpty(false)}
|
| 253 |
+
className="px-4 py-2 bg-surface hover:bg-white/10 text-gray-300 rounded-xl font-medium text-sm transition-colors"
|
| 254 |
+
>
|
| 255 |
+
Cancelar
|
| 256 |
+
</button>
|
| 257 |
+
<button
|
| 258 |
+
onClick={handleEmptyTrash}
|
| 259 |
+
disabled={loadingAction === 'EMPTY'}
|
| 260 |
+
className="px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-xl font-semibold text-sm transition-all shadow-lg active:scale-95"
|
| 261 |
+
>
|
| 262 |
+
Sí, vaciar permanentemente
|
| 263 |
+
</button>
|
| 264 |
+
</div>
|
| 265 |
+
</div>
|
| 266 |
+
</div>
|
| 267 |
+
)}
|
| 268 |
+
</div>
|
| 269 |
+
);
|
| 270 |
+
};
|
package-lock.json
CHANGED
|
@@ -1384,19 +1384,19 @@
|
|
| 1384 |
"license": "Apache-2.0"
|
| 1385 |
},
|
| 1386 |
"node_modules/@floating-ui/core": {
|
| 1387 |
-
"version": "1.
|
| 1388 |
-
"resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.
|
| 1389 |
-
"integrity": "sha512-
|
| 1390 |
"license": "MIT",
|
| 1391 |
"optional": true,
|
| 1392 |
"dependencies": {
|
| 1393 |
-
"@floating-ui/utils": "^0.2.
|
| 1394 |
}
|
| 1395 |
},
|
| 1396 |
"node_modules/@floating-ui/utils": {
|
| 1397 |
-
"version": "0.2.
|
| 1398 |
-
"resolved": "https://registry.npmjs.org/@floating-ui/utils/-/utils-0.2.
|
| 1399 |
-
"integrity": "sha512-
|
| 1400 |
"license": "MIT",
|
| 1401 |
"optional": true
|
| 1402 |
},
|
|
|
|
| 1384 |
"license": "Apache-2.0"
|
| 1385 |
},
|
| 1386 |
"node_modules/@floating-ui/core": {
|
| 1387 |
+
"version": "1.8.0",
|
| 1388 |
+
"resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.8.0.tgz",
|
| 1389 |
+
"integrity": "sha512-0CIZ5itps/8x7BG8dEIhs53BvCUH2PCoogtakwRTut+Arm58sJooJ0AuZhLw2HJYIR5cMLNPBSS728sPho2khQ==",
|
| 1390 |
"license": "MIT",
|
| 1391 |
"optional": true,
|
| 1392 |
"dependencies": {
|
| 1393 |
+
"@floating-ui/utils": "^0.2.12"
|
| 1394 |
}
|
| 1395 |
},
|
| 1396 |
"node_modules/@floating-ui/utils": {
|
| 1397 |
+
"version": "0.2.12",
|
| 1398 |
+
"resolved": "https://registry.npmjs.org/@floating-ui/utils/-/utils-0.2.12.tgz",
|
| 1399 |
+
"integrity": "sha512-HpCo8tmWzLVad5s2d19EhAz5zqrrQ6s69qd6moPMQvkOuSwDT1YgRfWSVuc4ennqrgv3OHppiOGMQ7oC13yIww==",
|
| 1400 |
"license": "MIT",
|
| 1401 |
"optional": true
|
| 1402 |
},
|
services/firebase.ts
CHANGED
|
@@ -108,11 +108,60 @@ export const updateItem = async (id: string, item: Partial<DataItem>) => {
|
|
| 108 |
}
|
| 109 |
};
|
| 110 |
|
|
|
|
| 111 |
export const deleteItem = async (id: string) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
try {
|
| 113 |
await deleteDoc(doc(db, COLLECTION_NAME, id));
|
| 114 |
} catch (e) {
|
| 115 |
-
console.error("Error deleting document: ", e);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
throw e;
|
| 117 |
}
|
| 118 |
};
|
|
|
|
| 108 |
}
|
| 109 |
};
|
| 110 |
|
| 111 |
+
// Soft delete (moves item to trash bin)
|
| 112 |
export const deleteItem = async (id: string) => {
|
| 113 |
+
try {
|
| 114 |
+
const docRef = doc(db, COLLECTION_NAME, id);
|
| 115 |
+
await updateDoc(docRef, {
|
| 116 |
+
isDeleted: true,
|
| 117 |
+
deletedAt: Date.now()
|
| 118 |
+
});
|
| 119 |
+
} catch (e) {
|
| 120 |
+
console.error("Error soft deleting document: ", e);
|
| 121 |
+
throw e;
|
| 122 |
+
}
|
| 123 |
+
};
|
| 124 |
+
|
| 125 |
+
// Restore item from trash bin
|
| 126 |
+
export const restoreItem = async (id: string) => {
|
| 127 |
+
try {
|
| 128 |
+
const docRef = doc(db, COLLECTION_NAME, id);
|
| 129 |
+
await updateDoc(docRef, {
|
| 130 |
+
isDeleted: false,
|
| 131 |
+
deletedAt: null
|
| 132 |
+
});
|
| 133 |
+
} catch (e) {
|
| 134 |
+
console.error("Error restoring document: ", e);
|
| 135 |
+
throw e;
|
| 136 |
+
}
|
| 137 |
+
};
|
| 138 |
+
|
| 139 |
+
// Restore multiple items
|
| 140 |
+
export const restoreAllItems = async (ids: string[]) => {
|
| 141 |
+
try {
|
| 142 |
+
await Promise.all(ids.map(id => restoreItem(id)));
|
| 143 |
+
} catch (e) {
|
| 144 |
+
console.error("Error restoring all items: ", e);
|
| 145 |
+
throw e;
|
| 146 |
+
}
|
| 147 |
+
};
|
| 148 |
+
|
| 149 |
+
// Permanently delete document from Firestore
|
| 150 |
+
export const permanentlyDeleteItem = async (id: string) => {
|
| 151 |
try {
|
| 152 |
await deleteDoc(doc(db, COLLECTION_NAME, id));
|
| 153 |
} catch (e) {
|
| 154 |
+
console.error("Error permanently deleting document: ", e);
|
| 155 |
+
throw e;
|
| 156 |
+
}
|
| 157 |
+
};
|
| 158 |
+
|
| 159 |
+
// Permanently empty trash bin
|
| 160 |
+
export const emptyTrash = async (ids: string[]) => {
|
| 161 |
+
try {
|
| 162 |
+
await Promise.all(ids.map(id => permanentlyDeleteItem(id)));
|
| 163 |
+
} catch (e) {
|
| 164 |
+
console.error("Error emptying trash: ", e);
|
| 165 |
throw e;
|
| 166 |
}
|
| 167 |
};
|
types.ts
CHANGED
|
@@ -29,6 +29,8 @@ export interface DataItem {
|
|
| 29 |
isFolder?: boolean;
|
| 30 |
isPinned?: boolean;
|
| 31 |
parentId?: string | null;
|
|
|
|
|
|
|
| 32 |
}
|
| 33 |
|
| 34 |
export type ViewState = 'LIST' | 'DETAIL' | 'CREATE' | 'EDIT';
|
|
|
|
| 29 |
isFolder?: boolean;
|
| 30 |
isPinned?: boolean;
|
| 31 |
parentId?: string | null;
|
| 32 |
+
isDeleted?: boolean;
|
| 33 |
+
deletedAt?: number;
|
| 34 |
}
|
| 35 |
|
| 36 |
export type ViewState = 'LIST' | 'DETAIL' | 'CREATE' | 'EDIT';
|