Spaces:
Sleeping
Sleeping
Upload 61 files
Browse files- App.tsx +517 -19
- base data.txt +13 -0
- components/BulkCategoryModal.tsx +95 -0
- components/Card.tsx +51 -7
- components/ConfirmModal.tsx +75 -0
- components/MoveToFolderModal.tsx +203 -0
- dist/assets/index-B8NpKCEH.js +0 -0
- dist/index.html +1 -1
- services/firebase.ts +3 -2
- types.ts +2 -0
App.tsx
CHANGED
|
@@ -4,13 +4,20 @@ import { Card } from './components/Card';
|
|
| 4 |
import { DataForm } from './components/DataForm';
|
| 5 |
import { DetailView } from './components/DetailView';
|
| 6 |
import { Button } from './components/Button';
|
| 7 |
-
import { Plus, Search, Layers, Loader2, WifiOff, Settings, Code, Type, Clock, Calendar, Shuffle, ChevronsLeft, ChevronLeft, ChevronRight, ChevronsRight } from 'lucide-react';
|
| 8 |
import { subscribeToItems, addItem, updateItem, deleteItem } from './services/firebase';
|
| 9 |
import { subscribeToStyleConfig } from './services/codeStyleService';
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
const App: React.FC = () => {
|
| 12 |
const [items, setItems] = useState<DataItem[]>([]);
|
| 13 |
const [view, setView] = useState<ViewState>('LIST');
|
|
|
|
|
|
|
|
|
|
| 14 |
const [viewMode, setViewMode] = useState<'normal' | 'admin'>(() => {
|
| 15 |
if (typeof window !== 'undefined') {
|
| 16 |
const params = new URLSearchParams(window.location.search);
|
|
@@ -23,6 +30,32 @@ const App: React.FC = () => {
|
|
| 23 |
return 'normal';
|
| 24 |
});
|
| 25 |
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
const [currentPage, setCurrentPage] = useState(() => {
|
| 27 |
if (typeof window !== 'undefined') {
|
| 28 |
const p = new URLSearchParams(window.location.search).get('page');
|
|
@@ -30,8 +63,19 @@ const App: React.FC = () => {
|
|
| 30 |
}
|
| 31 |
return 1;
|
| 32 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
const ITEMS_PER_PAGE = 20;
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
useEffect(() => {
|
| 36 |
if (typeof window !== 'undefined') {
|
| 37 |
const url = new URL(window.location.href);
|
|
@@ -59,6 +103,22 @@ const App: React.FC = () => {
|
|
| 59 |
localStorage.setItem('sortOrder', sortOrder);
|
| 60 |
}, [sortOrder]);
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
// Handle URL Sync
|
| 63 |
useEffect(() => {
|
| 64 |
if (typeof window !== 'undefined') {
|
|
@@ -90,6 +150,18 @@ const App: React.FC = () => {
|
|
| 90 |
}
|
| 91 |
}
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
if (modified) {
|
| 94 |
const newSearch = params.toString() ? `?${params.toString()}` : '';
|
| 95 |
window.history.replaceState({}, '', url.pathname + newSearch);
|
|
@@ -97,11 +169,13 @@ const App: React.FC = () => {
|
|
| 97 |
}
|
| 98 |
}, [currentPage, selectedItem]);
|
| 99 |
|
| 100 |
-
// Load deep linked item
|
| 101 |
useEffect(() => {
|
| 102 |
if (!loading && items.length > 0 && typeof window !== 'undefined' && view === 'LIST' && !selectedItem) {
|
| 103 |
const params = new URLSearchParams(window.location.search);
|
| 104 |
const itemId = params.get('item');
|
|
|
|
|
|
|
| 105 |
if (itemId) {
|
| 106 |
const found = items.find((i) => i.id === itemId);
|
| 107 |
if (found) {
|
|
@@ -109,10 +183,27 @@ const App: React.FC = () => {
|
|
| 109 |
setView('DETAIL');
|
| 110 |
} else {
|
| 111 |
params.delete('item');
|
| 112 |
-
|
| 113 |
-
window.history.replaceState({}, '', window.location.pathname + newSearch);
|
| 114 |
}
|
| 115 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
}
|
| 117 |
// eslint-disable-next-line react-hooks/exhaustive-deps
|
| 118 |
}, [loading, items]);
|
|
@@ -200,13 +291,23 @@ const App: React.FC = () => {
|
|
| 200 |
}, []);
|
| 201 |
|
| 202 |
const filteredItems = useMemo(() => {
|
|
|
|
|
|
|
| 203 |
if (!searchQuery.trim()) {
|
| 204 |
-
const
|
| 205 |
-
|
| 206 |
-
if (sortOrder === '
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
}
|
| 211 |
|
| 212 |
const lowerQ = searchQuery.toLowerCase();
|
|
@@ -246,11 +347,49 @@ const App: React.FC = () => {
|
|
| 246 |
return score;
|
| 247 |
};
|
| 248 |
|
| 249 |
-
//
|
| 250 |
-
const
|
| 251 |
.map(item => ({ item, score: getScore(item) }))
|
| 252 |
.filter(entry => entry.score > 0);
|
| 253 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
// Sort by Score DESC, then by sortOrder
|
| 255 |
scoredItems.sort((a, b) => {
|
| 256 |
if (a.score !== b.score) return b.score - a.score; // Higher score first
|
|
@@ -264,7 +403,7 @@ const App: React.FC = () => {
|
|
| 264 |
|
| 265 |
return scoredItems.map(entry => entry.item);
|
| 266 |
|
| 267 |
-
}, [items, searchQuery, sortOrder]);
|
| 268 |
|
| 269 |
// Reset to first page when search or sort changes
|
| 270 |
useEffect(() => {
|
|
@@ -276,6 +415,21 @@ const App: React.FC = () => {
|
|
| 276 |
return filteredItems.slice(startIndex, startIndex + ITEMS_PER_PAGE);
|
| 277 |
}, [filteredItems, currentPage]);
|
| 278 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
const totalPages = Math.ceil(filteredItems.length / ITEMS_PER_PAGE);
|
| 280 |
|
| 281 |
const renderPagination = () => {
|
|
@@ -400,7 +554,12 @@ const App: React.FC = () => {
|
|
| 400 |
<div className="flex items-center justify-between h-20">
|
| 401 |
<div
|
| 402 |
className="flex items-center gap-2 cursor-pointer group"
|
| 403 |
-
onClick={() => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
>
|
| 405 |
<div className="p-2 bg-surface rounded-lg group-hover:bg-primary/20 transition-colors">
|
| 406 |
<Layers className="text-primary" size={24} />
|
|
@@ -465,9 +624,10 @@ const App: React.FC = () => {
|
|
| 465 |
<Button
|
| 466 |
variant="secondary"
|
| 467 |
onClick={() => setIsSettingsOpen(!isSettingsOpen)}
|
| 468 |
-
className="bg-surface border border-white/5 hover:bg-surfaceHover !px-
|
| 469 |
>
|
| 470 |
<Settings size={20} />
|
|
|
|
| 471 |
</Button>
|
| 472 |
|
| 473 |
{isSettingsOpen && (
|
|
@@ -476,7 +636,7 @@ const App: React.FC = () => {
|
|
| 476 |
className="fixed inset-0 z-10"
|
| 477 |
onClick={() => setIsSettingsOpen(false)}
|
| 478 |
/>
|
| 479 |
-
<div className=
|
| 480 |
<div className="p-1">
|
| 481 |
|
| 482 |
<button
|
|
@@ -486,7 +646,7 @@ const App: React.FC = () => {
|
|
| 486 |
} else {
|
| 487 |
setViewMode('admin');
|
| 488 |
}
|
| 489 |
-
setIsSettingsOpen(false);
|
| 490 |
}}
|
| 491 |
className={`w-full flex items-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${viewMode === 'admin'
|
| 492 |
? 'bg-primary/10 text-primary'
|
|
@@ -496,6 +656,101 @@ const App: React.FC = () => {
|
|
| 496 |
<Settings size={16} />
|
| 497 |
{viewMode === 'admin' ? 'Desactivar Admin' : 'Modo Admin'}
|
| 498 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 499 |
</div>
|
| 500 |
</div>
|
| 501 |
</>
|
|
@@ -540,6 +795,55 @@ const App: React.FC = () => {
|
|
| 540 |
<>
|
| 541 |
{view === 'LIST' && (
|
| 542 |
<>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 543 |
{filteredItems.length === 0 ? (
|
| 544 |
<div className="text-center py-20 opacity-50">
|
| 545 |
<div className="inline-block p-6 rounded-full bg-surface mb-4">
|
|
@@ -557,7 +861,48 @@ const App: React.FC = () => {
|
|
| 557 |
<Card
|
| 558 |
key={item.id}
|
| 559 |
item={item}
|
| 560 |
-
onClick={(i) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 561 |
/>
|
| 562 |
))}
|
| 563 |
</div>
|
|
@@ -569,7 +914,17 @@ const App: React.FC = () => {
|
|
| 569 |
|
| 570 |
{view === 'CREATE' && (
|
| 571 |
<DataForm
|
| 572 |
-
onSave={
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 573 |
onCancel={() => setView('LIST')}
|
| 574 |
/>
|
| 575 |
)}
|
|
@@ -606,6 +961,149 @@ const App: React.FC = () => {
|
|
| 606 |
)}
|
| 607 |
|
| 608 |
</main>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 609 |
</div>
|
| 610 |
);
|
| 611 |
};
|
|
|
|
| 4 |
import { DataForm } from './components/DataForm';
|
| 5 |
import { DetailView } from './components/DetailView';
|
| 6 |
import { Button } from './components/Button';
|
| 7 |
+
import { Plus, Search, Layers, Loader2, WifiOff, Settings, Code, Type, Clock, Calendar, Shuffle, ChevronsLeft, ChevronLeft, ChevronRight, ChevronsRight, Check, Trash, MapPin } from 'lucide-react';
|
| 8 |
import { subscribeToItems, addItem, updateItem, deleteItem } from './services/firebase';
|
| 9 |
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 { Folder } from 'lucide-react';
|
| 14 |
|
| 15 |
const App: React.FC = () => {
|
| 16 |
const [items, setItems] = useState<DataItem[]>([]);
|
| 17 |
const [view, setView] = useState<ViewState>('LIST');
|
| 18 |
+
const [selectedItemIds, setSelectedItemIds] = useState<Set<string>>(new Set());
|
| 19 |
+
const [showBulkCategoryModal, setShowBulkCategoryModal] = useState(false);
|
| 20 |
+
const [isApplyingCategories, setIsApplyingCategories] = useState(false);
|
| 21 |
const [viewMode, setViewMode] = useState<'normal' | 'admin'>(() => {
|
| 22 |
if (typeof window !== 'undefined') {
|
| 23 |
const params = new URLSearchParams(window.location.search);
|
|
|
|
| 30 |
return 'normal';
|
| 31 |
});
|
| 32 |
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
|
| 33 |
+
const [isCategoriesPlusEnabled, setIsCategoriesPlusEnabled] = useState(() => {
|
| 34 |
+
if (typeof window !== 'undefined') {
|
| 35 |
+
return localStorage.getItem('categoriesPlusEnabled') === 'true';
|
| 36 |
+
}
|
| 37 |
+
return false;
|
| 38 |
+
});
|
| 39 |
+
const [isDeletePlusEnabled, setIsDeletePlusEnabled] = useState(() => {
|
| 40 |
+
if (typeof window !== 'undefined') {
|
| 41 |
+
return localStorage.getItem('deletePlusEnabled') === 'true';
|
| 42 |
+
}
|
| 43 |
+
return false;
|
| 44 |
+
});
|
| 45 |
+
const [isFoldersPlusEnabled, setIsFoldersPlusEnabled] = useState(() => {
|
| 46 |
+
if (typeof window !== 'undefined') {
|
| 47 |
+
return localStorage.getItem('foldersPlusEnabled') === 'true';
|
| 48 |
+
}
|
| 49 |
+
return false;
|
| 50 |
+
});
|
| 51 |
+
const [isShowBreadcrumbsEnabled, setIsShowBreadcrumbsEnabled] = useState(() => {
|
| 52 |
+
if (typeof window !== 'undefined') {
|
| 53 |
+
return localStorage.getItem('showBreadcrumbsEnabled') !== 'false';
|
| 54 |
+
}
|
| 55 |
+
return true;
|
| 56 |
+
});
|
| 57 |
+
const [isDragging, setIsDragging] = useState(false);
|
| 58 |
+
const [dragMode, setDragMode] = useState<'select' | 'deselect'>('select');
|
| 59 |
const [currentPage, setCurrentPage] = useState(() => {
|
| 60 |
if (typeof window !== 'undefined') {
|
| 61 |
const p = new URLSearchParams(window.location.search).get('page');
|
|
|
|
| 63 |
}
|
| 64 |
return 1;
|
| 65 |
});
|
| 66 |
+
const [currentFolderId, setCurrentFolderId] = useState<string | null>(null);
|
| 67 |
+
|
| 68 |
+
const [showConfirmDelete, setShowConfirmDelete] = useState(false);
|
| 69 |
+
const [showMoveToFolder, setShowMoveToFolder] = useState(false);
|
| 70 |
+
|
| 71 |
const ITEMS_PER_PAGE = 20;
|
| 72 |
|
| 73 |
+
useEffect(() => {
|
| 74 |
+
const handleMouseUp = () => setIsDragging(false);
|
| 75 |
+
window.addEventListener('mouseup', handleMouseUp);
|
| 76 |
+
return () => window.removeEventListener('mouseup', handleMouseUp);
|
| 77 |
+
}, []);
|
| 78 |
+
|
| 79 |
useEffect(() => {
|
| 80 |
if (typeof window !== 'undefined') {
|
| 81 |
const url = new URL(window.location.href);
|
|
|
|
| 103 |
localStorage.setItem('sortOrder', sortOrder);
|
| 104 |
}, [sortOrder]);
|
| 105 |
|
| 106 |
+
useEffect(() => {
|
| 107 |
+
localStorage.setItem('categoriesPlusEnabled', isCategoriesPlusEnabled.toString());
|
| 108 |
+
localStorage.setItem('deletePlusEnabled', isDeletePlusEnabled.toString());
|
| 109 |
+
localStorage.setItem('foldersPlusEnabled', isFoldersPlusEnabled.toString());
|
| 110 |
+
}, [isFoldersPlusEnabled]);
|
| 111 |
+
|
| 112 |
+
useEffect(() => {
|
| 113 |
+
localStorage.setItem('showBreadcrumbsEnabled', isShowBreadcrumbsEnabled.toString());
|
| 114 |
+
}, [isShowBreadcrumbsEnabled]);
|
| 115 |
+
|
| 116 |
+
useEffect(() => {
|
| 117 |
+
if (!isCategoriesPlusEnabled && !isDeletePlusEnabled && !isFoldersPlusEnabled) {
|
| 118 |
+
setSelectedItemIds(new Set());
|
| 119 |
+
}
|
| 120 |
+
}, [isCategoriesPlusEnabled, isDeletePlusEnabled, isFoldersPlusEnabled]);
|
| 121 |
+
|
| 122 |
// Handle URL Sync
|
| 123 |
useEffect(() => {
|
| 124 |
if (typeof window !== 'undefined') {
|
|
|
|
| 150 |
}
|
| 151 |
}
|
| 152 |
|
| 153 |
+
if (currentFolderId) {
|
| 154 |
+
if (params.get('folder') !== currentFolderId) {
|
| 155 |
+
params.set('folder', currentFolderId);
|
| 156 |
+
modified = true;
|
| 157 |
+
}
|
| 158 |
+
} else {
|
| 159 |
+
if (params.has('folder')) {
|
| 160 |
+
params.delete('folder');
|
| 161 |
+
modified = true;
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
if (modified) {
|
| 166 |
const newSearch = params.toString() ? `?${params.toString()}` : '';
|
| 167 |
window.history.replaceState({}, '', url.pathname + newSearch);
|
|
|
|
| 169 |
}
|
| 170 |
}, [currentPage, selectedItem]);
|
| 171 |
|
| 172 |
+
// Load deep linked item and folder
|
| 173 |
useEffect(() => {
|
| 174 |
if (!loading && items.length > 0 && typeof window !== 'undefined' && view === 'LIST' && !selectedItem) {
|
| 175 |
const params = new URLSearchParams(window.location.search);
|
| 176 |
const itemId = params.get('item');
|
| 177 |
+
let urlModified = false;
|
| 178 |
+
|
| 179 |
if (itemId) {
|
| 180 |
const found = items.find((i) => i.id === itemId);
|
| 181 |
if (found) {
|
|
|
|
| 183 |
setView('DETAIL');
|
| 184 |
} else {
|
| 185 |
params.delete('item');
|
| 186 |
+
urlModified = true;
|
|
|
|
| 187 |
}
|
| 188 |
}
|
| 189 |
+
|
| 190 |
+
if (!itemId && view === 'LIST' && currentFolderId === null) {
|
| 191 |
+
const folderId = params.get('folder');
|
| 192 |
+
if (folderId) {
|
| 193 |
+
const foundFolder = items.find(i => i.id === folderId && i.isFolder);
|
| 194 |
+
if (foundFolder) {
|
| 195 |
+
setCurrentFolderId(folderId);
|
| 196 |
+
} else {
|
| 197 |
+
params.delete('folder');
|
| 198 |
+
urlModified = true;
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
if (urlModified) {
|
| 204 |
+
const newSearch = params.toString() ? `?${params.toString()}` : '';
|
| 205 |
+
window.history.replaceState({}, '', window.location.pathname + newSearch);
|
| 206 |
+
}
|
| 207 |
}
|
| 208 |
// eslint-disable-next-line react-hooks/exhaustive-deps
|
| 209 |
}, [loading, items]);
|
|
|
|
| 291 |
}, []);
|
| 292 |
|
| 293 |
const filteredItems = useMemo(() => {
|
| 294 |
+
const inFolder = items.filter(i => (i.parentId || null) === currentFolderId);
|
| 295 |
+
|
| 296 |
if (!searchQuery.trim()) {
|
| 297 |
+
const sorted = [...inFolder];
|
| 298 |
+
if (sortOrder === 'random') return sorted.sort(() => Math.random() - 0.5);
|
| 299 |
+
if (sortOrder === 'name') return sorted.sort((a, b) => {
|
| 300 |
+
if (a.isFolder === b.isFolder) return a.title.localeCompare(b.title);
|
| 301 |
+
return a.isFolder ? -1 : 1;
|
| 302 |
+
});
|
| 303 |
+
if (sortOrder === 'updated') return sorted.sort((a, b) => {
|
| 304 |
+
if (a.isFolder === b.isFolder) return (b.updatedAt || b.createdAt) - (a.updatedAt || a.createdAt);
|
| 305 |
+
return a.isFolder ? -1 : 1;
|
| 306 |
+
});
|
| 307 |
+
return sorted.sort((a, b) => {
|
| 308 |
+
if (a.isFolder === b.isFolder) return b.createdAt - a.createdAt;
|
| 309 |
+
return a.isFolder ? -1 : 1;
|
| 310 |
+
});
|
| 311 |
}
|
| 312 |
|
| 313 |
const lowerQ = searchQuery.toLowerCase();
|
|
|
|
| 347 |
return score;
|
| 348 |
};
|
| 349 |
|
| 350 |
+
// 1. Score ALL items in the database regardless of folder
|
| 351 |
+
const allScored = items
|
| 352 |
.map(item => ({ item, score: getScore(item) }))
|
| 353 |
.filter(entry => entry.score > 0);
|
| 354 |
|
| 355 |
+
// 2. Map matches to the current folder context
|
| 356 |
+
const visibleResultsMap = new Map<string, { item: DataItem, score: number }>();
|
| 357 |
+
|
| 358 |
+
allScored.forEach(entry => {
|
| 359 |
+
let currentItem = entry.item;
|
| 360 |
+
let valid = true;
|
| 361 |
+
|
| 362 |
+
// Trace up to find the ancestor that lives in currentFolderId
|
| 363 |
+
while (currentItem && (currentItem.parentId || null) !== currentFolderId) {
|
| 364 |
+
const parent = items.find(i => i.id === currentItem.parentId);
|
| 365 |
+
if (!parent) {
|
| 366 |
+
valid = false; // Broken link or orphaned item, ignore
|
| 367 |
+
break;
|
| 368 |
+
}
|
| 369 |
+
currentItem = parent;
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
if (valid && currentItem) {
|
| 373 |
+
// currentItem now lives in currentFolderId!
|
| 374 |
+
// We accumulate the MAX score so that folders bubble up with the highest relevance of their contents.
|
| 375 |
+
if (!visibleResultsMap.has(currentItem.id)) {
|
| 376 |
+
visibleResultsMap.set(currentItem.id, { item: currentItem, score: entry.score });
|
| 377 |
+
} else {
|
| 378 |
+
const existing = visibleResultsMap.get(currentItem.id)!;
|
| 379 |
+
if (entry.score > existing.score) {
|
| 380 |
+
existing.score = entry.score;
|
| 381 |
+
}
|
| 382 |
+
}
|
| 383 |
+
}
|
| 384 |
+
});
|
| 385 |
+
|
| 386 |
+
const scoredItems = Array.from(visibleResultsMap.values());
|
| 387 |
+
|
| 388 |
+
// Boost folders so they appear first in the results
|
| 389 |
+
scoredItems.forEach(entry => {
|
| 390 |
+
if (entry.item.isFolder) entry.score += 50;
|
| 391 |
+
});
|
| 392 |
+
|
| 393 |
// Sort by Score DESC, then by sortOrder
|
| 394 |
scoredItems.sort((a, b) => {
|
| 395 |
if (a.score !== b.score) return b.score - a.score; // Higher score first
|
|
|
|
| 403 |
|
| 404 |
return scoredItems.map(entry => entry.item);
|
| 405 |
|
| 406 |
+
}, [items, searchQuery, sortOrder, currentFolderId]);
|
| 407 |
|
| 408 |
// Reset to first page when search or sort changes
|
| 409 |
useEffect(() => {
|
|
|
|
| 415 |
return filteredItems.slice(startIndex, startIndex + ITEMS_PER_PAGE);
|
| 416 |
}, [filteredItems, currentPage]);
|
| 417 |
|
| 418 |
+
const breadcrumbs = useMemo(() => {
|
| 419 |
+
const crumbs = [];
|
| 420 |
+
let current = currentFolderId;
|
| 421 |
+
while (current) {
|
| 422 |
+
const folder = items.find(i => i.id === current);
|
| 423 |
+
if (folder) {
|
| 424 |
+
crumbs.unshift(folder);
|
| 425 |
+
current = folder.parentId || null;
|
| 426 |
+
} else {
|
| 427 |
+
break;
|
| 428 |
+
}
|
| 429 |
+
}
|
| 430 |
+
return crumbs;
|
| 431 |
+
}, [currentFolderId, items]);
|
| 432 |
+
|
| 433 |
const totalPages = Math.ceil(filteredItems.length / ITEMS_PER_PAGE);
|
| 434 |
|
| 435 |
const renderPagination = () => {
|
|
|
|
| 554 |
<div className="flex items-center justify-between h-20">
|
| 555 |
<div
|
| 556 |
className="flex items-center gap-2 cursor-pointer group"
|
| 557 |
+
onClick={() => {
|
| 558 |
+
setView('LIST');
|
| 559 |
+
setSearchQuery('');
|
| 560 |
+
setCurrentFolderId(null);
|
| 561 |
+
setCurrentPage(1);
|
| 562 |
+
}}
|
| 563 |
>
|
| 564 |
<div className="p-2 bg-surface rounded-lg group-hover:bg-primary/20 transition-colors">
|
| 565 |
<Layers className="text-primary" size={24} />
|
|
|
|
| 624 |
<Button
|
| 625 |
variant="secondary"
|
| 626 |
onClick={() => setIsSettingsOpen(!isSettingsOpen)}
|
| 627 |
+
className="bg-surface border border-white/5 hover:bg-surfaceHover !px-3 sm:!px-4 justify-center flex items-center gap-2"
|
| 628 |
>
|
| 629 |
<Settings size={20} />
|
| 630 |
+
<span className="hidden sm:inline font-medium">Ajustes</span>
|
| 631 |
</Button>
|
| 632 |
|
| 633 |
{isSettingsOpen && (
|
|
|
|
| 636 |
className="fixed inset-0 z-10"
|
| 637 |
onClick={() => setIsSettingsOpen(false)}
|
| 638 |
/>
|
| 639 |
+
<div className={`absolute right-0 mt-2 ${viewMode === 'admin' ? 'w-[320px]' : 'w-48'} bg-surface border border-white/10 rounded-xl shadow-xl z-20 overflow-hidden animate-in fade-in zoom-in-95 duration-200`}>
|
| 640 |
<div className="p-1">
|
| 641 |
|
| 642 |
<button
|
|
|
|
| 646 |
} else {
|
| 647 |
setViewMode('admin');
|
| 648 |
}
|
| 649 |
+
// setIsSettingsOpen(false); // remove auto close for admin view to show/hide extra settings smoothly
|
| 650 |
}}
|
| 651 |
className={`w-full flex items-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${viewMode === 'admin'
|
| 652 |
? 'bg-primary/10 text-primary'
|
|
|
|
| 656 |
<Settings size={16} />
|
| 657 |
{viewMode === 'admin' ? 'Desactivar Admin' : 'Modo Admin'}
|
| 658 |
</button>
|
| 659 |
+
|
| 660 |
+
{viewMode === 'admin' && (
|
| 661 |
+
<div className="animate-in fade-in slide-in-from-top-2 duration-200">
|
| 662 |
+
<div className="my-1 border-t border-white/5"></div>
|
| 663 |
+
<div className="px-3 py-2 text-xs font-semibold text-gray-500 uppercase tracking-wider flex items-center gap-2">
|
| 664 |
+
Ajustes de Administrador
|
| 665 |
+
</div>
|
| 666 |
+
|
| 667 |
+
<div className="mt-1">
|
| 668 |
+
<div
|
| 669 |
+
className="flex items-center justify-between px-3 py-3 rounded-lg hover:bg-white/5 group border border-transparent hover:border-white/5 transition-all cursor-pointer"
|
| 670 |
+
onClick={() => setIsShowBreadcrumbsEnabled(!isShowBreadcrumbsEnabled)}
|
| 671 |
+
>
|
| 672 |
+
<div className="flex items-start gap-3">
|
| 673 |
+
<div className="p-2 bg-[#1a1f2e] group-hover:bg-[#22283a] border border-white/5 rounded-xl transition-colors">
|
| 674 |
+
<MapPin size={18} className="text-gray-300 group-hover:text-white transition-colors" />
|
| 675 |
+
</div>
|
| 676 |
+
<div className="flex flex-col text-left justify-center">
|
| 677 |
+
<span className="text-sm font-medium text-white mb-0.5">Mostrar Ubicación</span>
|
| 678 |
+
<span className="text-[11px] text-gray-400 leading-tight">Mostrar barra de navegación de carpetas (Migajas de pan)</span>
|
| 679 |
+
</div>
|
| 680 |
+
</div>
|
| 681 |
+
<button
|
| 682 |
+
className={`relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none ${isShowBreadcrumbsEnabled ? 'bg-primary' : 'bg-gray-600'}`}
|
| 683 |
+
>
|
| 684 |
+
<span className="sr-only">Mostrar Ubicación</span>
|
| 685 |
+
<span className={`pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out ${isShowBreadcrumbsEnabled ? 'translate-x-5' : 'translate-x-0'}`} />
|
| 686 |
+
</button>
|
| 687 |
+
</div>
|
| 688 |
+
|
| 689 |
+
<div
|
| 690 |
+
className="flex items-center justify-between px-3 py-3 mt-1 rounded-lg hover:bg-white/5 group border border-transparent hover:border-white/5 transition-all cursor-pointer"
|
| 691 |
+
onClick={() => setIsCategoriesPlusEnabled(!isCategoriesPlusEnabled)}
|
| 692 |
+
>
|
| 693 |
+
<div className="flex items-start gap-3">
|
| 694 |
+
<div className="p-2 bg-[#1a1f2e] group-hover:bg-[#22283a] border border-white/5 rounded-xl transition-colors">
|
| 695 |
+
<Layers size={18} className="text-gray-300 group-hover:text-white transition-colors" />
|
| 696 |
+
</div>
|
| 697 |
+
<div className="flex flex-col text-left justify-center">
|
| 698 |
+
<span className="text-sm font-medium text-white mb-0.5">Categorías Plus</span>
|
| 699 |
+
<span className="text-[11px] text-gray-400 leading-tight">Habilitar selección múltiple y edición masiva</span>
|
| 700 |
+
</div>
|
| 701 |
+
</div>
|
| 702 |
+
<button
|
| 703 |
+
className={`relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none ${isCategoriesPlusEnabled ? 'bg-primary' : 'bg-gray-600'}`}
|
| 704 |
+
>
|
| 705 |
+
<span className="sr-only">Habilitar Categorías Plus</span>
|
| 706 |
+
<span className={`pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out ${isCategoriesPlusEnabled ? 'translate-x-5' : 'translate-x-0'}`} />
|
| 707 |
+
</button>
|
| 708 |
+
</div>
|
| 709 |
+
|
| 710 |
+
<div
|
| 711 |
+
className="flex items-center justify-between px-3 py-3 mt-1 rounded-lg hover:bg-white/5 group border border-transparent hover:border-white/5 transition-all cursor-pointer"
|
| 712 |
+
onClick={() => setIsDeletePlusEnabled(!isDeletePlusEnabled)}
|
| 713 |
+
>
|
| 714 |
+
<div className="flex items-start gap-3">
|
| 715 |
+
<div className="p-2 bg-[#1a1f2e] group-hover:bg-[#22283a] border border-white/5 rounded-xl transition-colors">
|
| 716 |
+
<Trash size={18} className="text-gray-300 group-hover:text-white transition-colors" />
|
| 717 |
+
</div>
|
| 718 |
+
<div className="flex flex-col text-left justify-center">
|
| 719 |
+
<span className="text-sm font-medium text-white mb-0.5">Eliminar Plus</span>
|
| 720 |
+
<span className="text-[11px] text-gray-400 leading-tight">Habilitar selección masiva para eliminar mangas</span>
|
| 721 |
+
</div>
|
| 722 |
+
</div>
|
| 723 |
+
<button
|
| 724 |
+
className={`relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none ${isDeletePlusEnabled ? 'bg-red-500' : 'bg-gray-600'}`}
|
| 725 |
+
>
|
| 726 |
+
<span className="sr-only">Habilitar Eliminar Plus</span>
|
| 727 |
+
<span className={`pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out ${isDeletePlusEnabled ? 'translate-x-5' : 'translate-x-0'}`} />
|
| 728 |
+
</button>
|
| 729 |
+
</div>
|
| 730 |
+
|
| 731 |
+
<div
|
| 732 |
+
className="flex items-center justify-between px-3 py-3 mt-1 rounded-lg hover:bg-white/5 group border border-transparent hover:border-white/5 transition-all cursor-pointer"
|
| 733 |
+
onClick={() => setIsFoldersPlusEnabled(!isFoldersPlusEnabled)}
|
| 734 |
+
>
|
| 735 |
+
<div className="flex items-start gap-3">
|
| 736 |
+
<div className="p-2 bg-[#1a1f2e] group-hover:bg-[#22283a] border border-white/5 rounded-xl transition-colors">
|
| 737 |
+
<Folder size={18} className="text-gray-300 group-hover:text-white transition-colors" />
|
| 738 |
+
</div>
|
| 739 |
+
<div className="flex flex-col text-left justify-center">
|
| 740 |
+
<span className="text-sm font-medium text-white mb-0.5">Carpetas Plus</span>
|
| 741 |
+
<span className="text-[11px] text-gray-400 leading-tight">Habilitar selección para crear carpetas y agrupar mangas</span>
|
| 742 |
+
</div>
|
| 743 |
+
</div>
|
| 744 |
+
<button
|
| 745 |
+
className={`relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none ${isFoldersPlusEnabled ? 'bg-primary' : 'bg-gray-600'}`}
|
| 746 |
+
>
|
| 747 |
+
<span className="sr-only">Habilitar Carpetas Plus</span>
|
| 748 |
+
<span className={`pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out ${isFoldersPlusEnabled ? 'translate-x-5' : 'translate-x-0'}`} />
|
| 749 |
+
</button>
|
| 750 |
+
</div>
|
| 751 |
+
</div>
|
| 752 |
+
</div>
|
| 753 |
+
)}
|
| 754 |
</div>
|
| 755 |
</div>
|
| 756 |
</>
|
|
|
|
| 795 |
<>
|
| 796 |
{view === 'LIST' && (
|
| 797 |
<>
|
| 798 |
+
{/* Contenedor de Navegación (Flujo normal del documento, subido con margen negativo corto) */}
|
| 799 |
+
{(currentFolderId !== null || (isShowBreadcrumbsEnabled && isFoldersPlusEnabled)) && (
|
| 800 |
+
<div className="flex flex-col sm:flex-row sm:items-center gap-3 sm:gap-4 mb-5 -mt-3 sm:-mt-4">
|
| 801 |
+
{currentFolderId !== null && (
|
| 802 |
+
<button
|
| 803 |
+
onClick={() => {
|
| 804 |
+
if (breadcrumbs.length > 1) {
|
| 805 |
+
setCurrentFolderId(breadcrumbs[breadcrumbs.length - 2].id);
|
| 806 |
+
} else {
|
| 807 |
+
setCurrentFolderId(null);
|
| 808 |
+
}
|
| 809 |
+
setCurrentPage(1);
|
| 810 |
+
}}
|
| 811 |
+
className="flex items-center justify-center sm:justify-start gap-2 px-3 py-1.5 rounded-lg bg-surface hover:bg-white/10 text-gray-300 hover:text-white transition-all text-sm font-medium border border-white/5 w-fit shadow-sm"
|
| 812 |
+
>
|
| 813 |
+
<ChevronLeft size={16} /> Volver
|
| 814 |
+
</button>
|
| 815 |
+
)}
|
| 816 |
+
|
| 817 |
+
{isShowBreadcrumbsEnabled && (
|
| 818 |
+
<div className="flex items-center gap-1 text-sm text-gray-400 overflow-x-auto pb-1 sm:pb-0 custom-scrollbar w-max max-w-full">
|
| 819 |
+
<button
|
| 820 |
+
onClick={() => {
|
| 821 |
+
setCurrentFolderId(null);
|
| 822 |
+
setCurrentPage(1);
|
| 823 |
+
}}
|
| 824 |
+
className={`hover:text-white transition-colors px-2 py-1 rounded-md hover:bg-white/5 ${currentFolderId === null ? 'text-white font-bold' : ''}`}
|
| 825 |
+
>
|
| 826 |
+
Raíz
|
| 827 |
+
</button>
|
| 828 |
+
{breadcrumbs.map((crumb) => (
|
| 829 |
+
<React.Fragment key={crumb.id}>
|
| 830 |
+
<ChevronRight size={14} className="opacity-50 shrink-0" />
|
| 831 |
+
<button
|
| 832 |
+
onClick={() => {
|
| 833 |
+
setCurrentFolderId(crumb.id);
|
| 834 |
+
setCurrentPage(1);
|
| 835 |
+
}}
|
| 836 |
+
className={`hover:text-white transition-colors whitespace-nowrap px-2 py-1 rounded-md hover:bg-white/5 ${currentFolderId === crumb.id ? 'text-white font-bold' : ''}`}
|
| 837 |
+
>
|
| 838 |
+
{crumb.title}
|
| 839 |
+
</button>
|
| 840 |
+
</React.Fragment>
|
| 841 |
+
))}
|
| 842 |
+
</div>
|
| 843 |
+
)}
|
| 844 |
+
</div>
|
| 845 |
+
)}
|
| 846 |
+
|
| 847 |
{filteredItems.length === 0 ? (
|
| 848 |
<div className="text-center py-20 opacity-50">
|
| 849 |
<div className="inline-block p-6 rounded-full bg-surface mb-4">
|
|
|
|
| 861 |
<Card
|
| 862 |
key={item.id}
|
| 863 |
item={item}
|
| 864 |
+
onClick={(i) => {
|
| 865 |
+
if (isCategoriesPlusEnabled || isDeletePlusEnabled || isFoldersPlusEnabled) return;
|
| 866 |
+
if (i.isFolder) {
|
| 867 |
+
setCurrentFolderId(i.id);
|
| 868 |
+
setCurrentPage(1);
|
| 869 |
+
return;
|
| 870 |
+
}
|
| 871 |
+
setSelectedItem(i); setView('DETAIL');
|
| 872 |
+
}}
|
| 873 |
+
onDoubleClick={(i) => {
|
| 874 |
+
if (i.isFolder) {
|
| 875 |
+
setCurrentFolderId(i.id);
|
| 876 |
+
setCurrentPage(1);
|
| 877 |
+
} else {
|
| 878 |
+
setSelectedItem(i);
|
| 879 |
+
setView('DETAIL');
|
| 880 |
+
}
|
| 881 |
+
}}
|
| 882 |
+
isSelectable={viewMode === 'admin' && (isCategoriesPlusEnabled || isDeletePlusEnabled || isFoldersPlusEnabled)}
|
| 883 |
+
isSelected={selectedItemIds.has(item.id)}
|
| 884 |
+
onMouseDown={(e, i) => {
|
| 885 |
+
if (!(isCategoriesPlusEnabled || isDeletePlusEnabled || isFoldersPlusEnabled)) return;
|
| 886 |
+
setIsDragging(true);
|
| 887 |
+
const currentlySelected = selectedItemIds.has(i.id);
|
| 888 |
+
setDragMode(currentlySelected ? 'deselect' : 'select');
|
| 889 |
+
|
| 890 |
+
setSelectedItemIds(prev => {
|
| 891 |
+
const next = new Set(prev);
|
| 892 |
+
if (currentlySelected) next.delete(i.id);
|
| 893 |
+
else next.add(i.id);
|
| 894 |
+
return next;
|
| 895 |
+
});
|
| 896 |
+
}}
|
| 897 |
+
onMouseEnter={(e, i) => {
|
| 898 |
+
if (!(isCategoriesPlusEnabled || isDeletePlusEnabled || isFoldersPlusEnabled) || !isDragging) return;
|
| 899 |
+
setSelectedItemIds(prev => {
|
| 900 |
+
const next = new Set(prev);
|
| 901 |
+
if (dragMode === 'select') next.add(i.id);
|
| 902 |
+
else next.delete(i.id);
|
| 903 |
+
return next;
|
| 904 |
+
});
|
| 905 |
+
}}
|
| 906 |
/>
|
| 907 |
))}
|
| 908 |
</div>
|
|
|
|
| 914 |
|
| 915 |
{view === 'CREATE' && (
|
| 916 |
<DataForm
|
| 917 |
+
onSave={async (data) => {
|
| 918 |
+
try {
|
| 919 |
+
await addItem({
|
| 920 |
+
...data,
|
| 921 |
+
parentId: currentFolderId
|
| 922 |
+
});
|
| 923 |
+
setView('LIST');
|
| 924 |
+
} catch (e) {
|
| 925 |
+
alert("Error al guardar en la nube.");
|
| 926 |
+
}
|
| 927 |
+
}}
|
| 928 |
onCancel={() => setView('LIST')}
|
| 929 |
/>
|
| 930 |
)}
|
|
|
|
| 961 |
)}
|
| 962 |
|
| 963 |
</main>
|
| 964 |
+
|
| 965 |
+
{/* Floating Action Bar for Bulk Mode */}
|
| 966 |
+
{(isCategoriesPlusEnabled || isDeletePlusEnabled || isFoldersPlusEnabled || selectedItemIds.size > 0) && viewMode === 'admin' && view === 'LIST' && (
|
| 967 |
+
<div className="fixed bottom-8 left-1/2 -translate-x-1/2 z-40 bg-[#121212] border border-white/10 p-4 rounded-2xl shadow-[0_0_30px_rgba(0,0,0,0.8)] flex items-center justify-between gap-6 min-w-[320px] animate-in slide-in-from-bottom-5 duration-300">
|
| 968 |
+
<div className="flex flex-col min-w-[120px]">
|
| 969 |
+
<span className="text-white font-bold">{selectedItemIds.size} seleccionados</span>
|
| 970 |
+
<span className="text-gray-500 text-xs text-left">Listos para acción</span>
|
| 971 |
+
</div>
|
| 972 |
+
<div className="flex items-center gap-3">
|
| 973 |
+
{paginatedItems.length > 0 && (
|
| 974 |
+
<button
|
| 975 |
+
onClick={() => {
|
| 976 |
+
const visibleIds = paginatedItems.map(i => i.id);
|
| 977 |
+
const allVisibleSelected = visibleIds.length > 0 && visibleIds.every(id => selectedItemIds.has(id));
|
| 978 |
+
|
| 979 |
+
setSelectedItemIds(prev => {
|
| 980 |
+
const next = new Set(prev);
|
| 981 |
+
if (allVisibleSelected) {
|
| 982 |
+
visibleIds.forEach(id => next.delete(id));
|
| 983 |
+
} else {
|
| 984 |
+
visibleIds.forEach(id => next.add(id));
|
| 985 |
+
}
|
| 986 |
+
return next;
|
| 987 |
+
});
|
| 988 |
+
}}
|
| 989 |
+
className="text-primary hover:text-primary/80 px-2 py-1 text-sm font-medium transition-colors whitespace-nowrap"
|
| 990 |
+
>
|
| 991 |
+
{paginatedItems.length > 0 && paginatedItems.every(i => selectedItemIds.has(i.id)) ? 'Desmarcar Todos' : 'Seleccionar Todos'}
|
| 992 |
+
</button>
|
| 993 |
+
)}
|
| 994 |
+
<button
|
| 995 |
+
onClick={() => setSelectedItemIds(new Set())}
|
| 996 |
+
className="text-gray-400 hover:text-white px-2 py-1 text-sm transition-colors"
|
| 997 |
+
>
|
| 998 |
+
Limpiar
|
| 999 |
+
</button>
|
| 1000 |
+
{isDeletePlusEnabled && (
|
| 1001 |
+
<Button
|
| 1002 |
+
onClick={() => setShowConfirmDelete(true)}
|
| 1003 |
+
className="!py-2 !px-4 bg-red-500/10 text-red-500 hover:bg-red-500 hover:text-white border-transparent"
|
| 1004 |
+
disabled={selectedItemIds.size === 0}
|
| 1005 |
+
>
|
| 1006 |
+
<Trash size={16} /> <span className="hidden sm:inline">Eliminar</span>
|
| 1007 |
+
</Button>
|
| 1008 |
+
)}
|
| 1009 |
+
{isFoldersPlusEnabled && (
|
| 1010 |
+
<Button
|
| 1011 |
+
onClick={() => setShowMoveToFolder(true)}
|
| 1012 |
+
className="!py-2 !px-4 bg-blue-500/10 text-blue-400 hover:bg-blue-500 hover:text-white border-transparent"
|
| 1013 |
+
disabled={selectedItemIds.size === 0}
|
| 1014 |
+
>
|
| 1015 |
+
<Folder size={16} /> <span className="hidden sm:inline">Mover a Carpeta</span>
|
| 1016 |
+
</Button>
|
| 1017 |
+
)}
|
| 1018 |
+
{isCategoriesPlusEnabled && (
|
| 1019 |
+
<Button
|
| 1020 |
+
onClick={() => setShowBulkCategoryModal(true)}
|
| 1021 |
+
className="!py-2 !px-4"
|
| 1022 |
+
disabled={isApplyingCategories || selectedItemIds.size === 0}
|
| 1023 |
+
>
|
| 1024 |
+
{isApplyingCategories ? <Loader2 size={16} className="animate-spin" /> : 'Aplicar Categorías'}
|
| 1025 |
+
</Button>
|
| 1026 |
+
)}
|
| 1027 |
+
</div>
|
| 1028 |
+
</div>
|
| 1029 |
+
)}
|
| 1030 |
+
|
| 1031 |
+
<ConfirmModal
|
| 1032 |
+
isOpen={showConfirmDelete}
|
| 1033 |
+
onClose={() => setShowConfirmDelete(false)}
|
| 1034 |
+
title="Confirmar eliminación"
|
| 1035 |
+
message={`¿Estás seguro de que quieres eliminar ${selectedItemIds.size} elemento(s)? Esta acción no se puede deshacer.`}
|
| 1036 |
+
confirmText="Eliminar"
|
| 1037 |
+
isDestructive={true}
|
| 1038 |
+
onConfirm={async () => {
|
| 1039 |
+
try {
|
| 1040 |
+
await Promise.all(Array.from(selectedItemIds).map(id => deleteItem(id)));
|
| 1041 |
+
setSelectedItemIds(new Set());
|
| 1042 |
+
} catch (e) {
|
| 1043 |
+
alert('Error al eliminar los elementos.');
|
| 1044 |
+
}
|
| 1045 |
+
}}
|
| 1046 |
+
/>
|
| 1047 |
+
|
| 1048 |
+
<MoveToFolderModal
|
| 1049 |
+
isOpen={showMoveToFolder}
|
| 1050 |
+
onClose={() => setShowMoveToFolder(false)}
|
| 1051 |
+
selectionCount={selectedItemIds.size}
|
| 1052 |
+
currentFolderId={currentFolderId}
|
| 1053 |
+
folders={items.filter(i => i.isFolder)}
|
| 1054 |
+
onMoveToFolder={async (folderId) => {
|
| 1055 |
+
try {
|
| 1056 |
+
await Promise.all(
|
| 1057 |
+
Array.from(selectedItemIds).map(id => updateItem(id, { parentId: folderId }))
|
| 1058 |
+
);
|
| 1059 |
+
setSelectedItemIds(new Set());
|
| 1060 |
+
} catch (e) {
|
| 1061 |
+
console.error(e);
|
| 1062 |
+
throw e;
|
| 1063 |
+
}
|
| 1064 |
+
}}
|
| 1065 |
+
onCreateFolder={async (name) => {
|
| 1066 |
+
const newFolder = {
|
| 1067 |
+
title: name,
|
| 1068 |
+
summary: 'Carpeta',
|
| 1069 |
+
content: '',
|
| 1070 |
+
tags: [],
|
| 1071 |
+
categories: [],
|
| 1072 |
+
isFolder: true,
|
| 1073 |
+
parentId: currentFolderId
|
| 1074 |
+
};
|
| 1075 |
+
|
| 1076 |
+
const newId = await addItem(newFolder);
|
| 1077 |
+
return newId;
|
| 1078 |
+
}}
|
| 1079 |
+
/>
|
| 1080 |
+
|
| 1081 |
+
<BulkCategoryModal
|
| 1082 |
+
isOpen={showBulkCategoryModal}
|
| 1083 |
+
onClose={() => setShowBulkCategoryModal(false)}
|
| 1084 |
+
selectionCount={selectedItemIds.size}
|
| 1085 |
+
onApply={async (categories) => {
|
| 1086 |
+
setIsApplyingCategories(true);
|
| 1087 |
+
try {
|
| 1088 |
+
await Promise.all(
|
| 1089 |
+
Array.from(selectedItemIds).map(async (id) => {
|
| 1090 |
+
const item = items.find(i => i.id === id);
|
| 1091 |
+
if (item) {
|
| 1092 |
+
const mergedCats = Array.from(new Set([...(item.categories || []), ...categories]));
|
| 1093 |
+
await updateItem(id, { categories: mergedCats });
|
| 1094 |
+
}
|
| 1095 |
+
})
|
| 1096 |
+
);
|
| 1097 |
+
setShowBulkCategoryModal(false);
|
| 1098 |
+
setSelectedItemIds(new Set());
|
| 1099 |
+
} catch (err) {
|
| 1100 |
+
console.error('Error applying bulk categories:', err);
|
| 1101 |
+
alert('Error al aplicar las categorías');
|
| 1102 |
+
} finally {
|
| 1103 |
+
setIsApplyingCategories(false);
|
| 1104 |
+
}
|
| 1105 |
+
}}
|
| 1106 |
+
/>
|
| 1107 |
</div>
|
| 1108 |
);
|
| 1109 |
};
|
base data.txt
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1. Base de Datos (Firebase)
|
| 2 |
+
El proyecto está conectado a Firebase Firestore. Los detalles de la cuenta y el proyecto en Firebase son los siguientes:
|
| 3 |
+
|
| 4 |
+
Project ID: twistedbrody-9d163 (Este es el nombre del proyecto en la consola de Firebase).
|
| 5 |
+
Dominio: twistedbrody-9d163.firebaseapp.com
|
| 6 |
+
Colección (Tabla) principal: Guarda los datos en una colección llamada neonvault_items.
|
| 7 |
+
(Nota: Toda esta configuración de Firebase está guardada en el archivo services/firebase.ts).
|
| 8 |
+
|
| 9 |
+
2. API de Inteligencia Artificial (Google Gemini)
|
| 10 |
+
El proyecto también está preparado para conectarse a la API de Google Gemini (usado para funciones de IA en la página).
|
| 11 |
+
|
| 12 |
+
La configuración para esto espera que tengas un archivo .env en la raíz de tu proyecto con una variable llamada VITE_GEMINI_API_KEY donde pones tu clave de la API de Google.
|
| 13 |
+
Si necesitas cambiar la cuenta de Firebase a otra tuya, tendrías que ir a tu consola de Firebase, crear un proyecto nuevo y reemplazar las claves (apiKey, authDomain, projectId, etc.) que están en el archivo services/firebase.ts (líneas 17 a 25).
|
components/BulkCategoryModal.tsx
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useState } from 'react';
|
| 2 |
+
import { X, Sparkles, Check, Hash } from 'lucide-react';
|
| 3 |
+
import { Button } from './Button';
|
| 4 |
+
|
| 5 |
+
interface BulkCategoryModalProps {
|
| 6 |
+
isOpen: boolean;
|
| 7 |
+
onClose: () => void;
|
| 8 |
+
onApply: (categories: string[]) => void;
|
| 9 |
+
selectionCount: number;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
export const BulkCategoryModal: React.FC<BulkCategoryModalProps> = ({ isOpen, onClose, onApply, selectionCount }) => {
|
| 13 |
+
const [categories, setCategories] = useState<string[]>([]);
|
| 14 |
+
const [categoryInput, setCategoryInput] = useState('');
|
| 15 |
+
|
| 16 |
+
if (!isOpen) return null;
|
| 17 |
+
|
| 18 |
+
return (
|
| 19 |
+
<div className="fixed inset-0 z-[100] flex items-center justify-center bg-black/60 backdrop-blur-sm px-4">
|
| 20 |
+
<div className="bg-[#1e1e1e] rounded-xl shadow-2xl w-full max-w-lg border border-white/10 animate-fade-in overflow-hidden">
|
| 21 |
+
<div className="flex items-center justify-between p-4 border-b border-white/10 bg-white/5">
|
| 22 |
+
<h2 className="text-lg font-bold text-white flex items-center gap-2">
|
| 23 |
+
<Hash size={18} className="text-primary" /> Aplicar Categorías en Masa
|
| 24 |
+
</h2>
|
| 25 |
+
<button
|
| 26 |
+
onClick={onClose}
|
| 27 |
+
className="text-gray-400 hover:text-white transition-colors"
|
| 28 |
+
>
|
| 29 |
+
<X size={20} />
|
| 30 |
+
</button>
|
| 31 |
+
</div>
|
| 32 |
+
|
| 33 |
+
<div className="p-6">
|
| 34 |
+
<p className="text-sm text-gray-400 mb-6">
|
| 35 |
+
Añade las categorías que deseas aplicar a las {selectionCount} entradas seleccionadas. Las categorías existentes se conservarán.
|
| 36 |
+
</p>
|
| 37 |
+
|
| 38 |
+
<div className="mb-4">
|
| 39 |
+
<div className="flex flex-wrap gap-2 mb-2">
|
| 40 |
+
{categories.map((cat, idx) => (
|
| 41 |
+
<span key={idx} className="flex items-center gap-1 text-sm text-primary bg-primary/10 px-3 py-1 rounded-lg border border-primary/30 uppercase tracking-wide font-medium">
|
| 42 |
+
{cat}
|
| 43 |
+
<button
|
| 44 |
+
type="button"
|
| 45 |
+
onClick={() => setCategories(categories.filter((_, i) => i !== idx))}
|
| 46 |
+
className="ml-1 hover:text-red-400 focus:outline-none"
|
| 47 |
+
>
|
| 48 |
+
<X size={12} />
|
| 49 |
+
</button>
|
| 50 |
+
</span>
|
| 51 |
+
))}
|
| 52 |
+
</div>
|
| 53 |
+
<div className="relative">
|
| 54 |
+
<Sparkles size={16} className="absolute left-3 top-1/2 -translate-y-1/2 text-primary" />
|
| 55 |
+
<input
|
| 56 |
+
type="text"
|
| 57 |
+
autoFocus
|
| 58 |
+
className="w-full bg-background border border-white/10 rounded-lg p-3 pl-10 text-white focus:border-primary outline-none focus:ring-1 focus:ring-primary transition-colors"
|
| 59 |
+
value={categoryInput}
|
| 60 |
+
onChange={(e) => setCategoryInput(e.target.value)}
|
| 61 |
+
onKeyDown={(e) => {
|
| 62 |
+
if (e.key === 'Enter') {
|
| 63 |
+
e.preventDefault();
|
| 64 |
+
const val = categoryInput.trim();
|
| 65 |
+
if (val && !categories.includes(val)) {
|
| 66 |
+
setCategories([...categories, val]);
|
| 67 |
+
setCategoryInput('');
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
}}
|
| 71 |
+
placeholder="Escribe una categoría y presiona Enter..."
|
| 72 |
+
/>
|
| 73 |
+
</div>
|
| 74 |
+
</div>
|
| 75 |
+
|
| 76 |
+
<div className="flex justify-end gap-3 mt-8">
|
| 77 |
+
<Button variant="outline" onClick={onClose} className="px-6 border-white/10">
|
| 78 |
+
Cancelar
|
| 79 |
+
</Button>
|
| 80 |
+
<Button
|
| 81 |
+
onClick={() => {
|
| 82 |
+
onApply(categories);
|
| 83 |
+
setCategories([]);
|
| 84 |
+
setCategoryInput('');
|
| 85 |
+
}}
|
| 86 |
+
disabled={categories.length === 0}
|
| 87 |
+
>
|
| 88 |
+
<Check size={18} /> Aplicar a {selectionCount} items
|
| 89 |
+
</Button>
|
| 90 |
+
</div>
|
| 91 |
+
</div>
|
| 92 |
+
</div>
|
| 93 |
+
</div>
|
| 94 |
+
);
|
| 95 |
+
};
|
components/Card.tsx
CHANGED
|
@@ -1,26 +1,70 @@
|
|
| 1 |
import React from 'react';
|
| 2 |
import { DataItem } from '../types';
|
| 3 |
-
import { Download, ExternalLink } from 'lucide-react';
|
| 4 |
import { getIconComponent } from './IconPicker';
|
| 5 |
|
| 6 |
interface CardProps {
|
| 7 |
item: DataItem;
|
| 8 |
onClick: (item: DataItem) => void;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
}
|
| 10 |
|
| 11 |
-
export const Card: React.FC<CardProps> = ({ item, onClick }) => {
|
| 12 |
-
console.log('[Card] Rendering item:', item.title, 'Icon:', item.icon);
|
| 13 |
const Icon = getIconComponent(item.icon);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
return (
|
| 15 |
<div
|
| 16 |
-
onClick={() =>
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
<div className="mb-2 flex-grow flex flex-col">
|
| 20 |
<div className="flex items-start gap-2">
|
| 21 |
{Icon && (
|
| 22 |
-
<div className="text-primary shrink-0">
|
| 23 |
-
<Icon size={
|
| 24 |
</div>
|
| 25 |
)}
|
| 26 |
<h3
|
|
|
|
| 1 |
import React from 'react';
|
| 2 |
import { DataItem } from '../types';
|
| 3 |
+
import { Download, ExternalLink, Check, Folder } from 'lucide-react';
|
| 4 |
import { getIconComponent } from './IconPicker';
|
| 5 |
|
| 6 |
interface CardProps {
|
| 7 |
item: DataItem;
|
| 8 |
onClick: (item: DataItem) => void;
|
| 9 |
+
isSelectable?: boolean;
|
| 10 |
+
isSelected?: boolean;
|
| 11 |
+
onMouseDown?: (e: React.MouseEvent, item: DataItem) => void;
|
| 12 |
+
onMouseEnter?: (e: React.MouseEvent, item: DataItem) => void;
|
| 13 |
+
onDoubleClick?: (item: DataItem) => void;
|
| 14 |
}
|
| 15 |
|
| 16 |
+
export const Card: React.FC<CardProps> = ({ item, onClick, isSelectable, isSelected, onMouseDown, onMouseEnter, onDoubleClick }) => {
|
|
|
|
| 17 |
const Icon = getIconComponent(item.icon);
|
| 18 |
+
|
| 19 |
+
if (item.isFolder) {
|
| 20 |
+
return (
|
| 21 |
+
<div
|
| 22 |
+
onClick={() => onClick(item)}
|
| 23 |
+
onDoubleClick={() => onDoubleClick?.(item)}
|
| 24 |
+
onMouseDown={(e) => onMouseDown?.(e, item)}
|
| 25 |
+
onMouseEnter={(e) => onMouseEnter?.(e, item)}
|
| 26 |
+
style={{ userSelect: isSelectable ? 'none' : 'auto' }}
|
| 27 |
+
className={`relative group bg-surface border ${isSelected ? 'border-primary ring-2 ring-primary bg-primary/10 shadow-[0_0_20px_rgba(187,134,252,0.15)]' : 'border-white/5 hover:border-primary/30 hover:bg-white/[0.02]'} rounded-xl p-6 cursor-pointer transition-all duration-300 ${isSelected ? 'scale-[0.98]' : 'hover:-translate-y-1 hover:shadow-xl'} flex flex-col items-center justify-center h-[200px] text-center overflow-hidden`}
|
| 28 |
+
>
|
| 29 |
+
{isSelected && (
|
| 30 |
+
<div className="absolute top-3 right-3 z-20 w-6 h-6 bg-primary rounded-full flex items-center justify-center shadow-lg transition-transform animate-in zoom-in duration-200 pointer-events-none">
|
| 31 |
+
<Check size={14} className="text-[#121212]" strokeWidth={3} />
|
| 32 |
+
</div>
|
| 33 |
+
)}
|
| 34 |
+
<div className="p-4 bg-white/5 rounded-2xl mb-4 group-hover:bg-primary/10 transition-colors">
|
| 35 |
+
<Folder size={48} className="text-primary opacity-80 group-hover:opacity-100 transition-opacity" strokeWidth={1} />
|
| 36 |
+
</div>
|
| 37 |
+
<h3 className="text-lg font-bold text-white group-hover:text-primary transition-colors line-clamp-2 w-full px-2">
|
| 38 |
+
{item.title}
|
| 39 |
+
</h3>
|
| 40 |
+
{item.summary && item.summary !== 'Carpeta' && (
|
| 41 |
+
<p className="text-xs text-gray-500 mt-2 line-clamp-1 break-words">{item.summary}</p>
|
| 42 |
+
)}
|
| 43 |
+
</div>
|
| 44 |
+
);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
return (
|
| 48 |
<div
|
| 49 |
+
onClick={(e) => {
|
| 50 |
+
onClick(item);
|
| 51 |
+
}}
|
| 52 |
+
onDoubleClick={() => onDoubleClick?.(item)}
|
| 53 |
+
onMouseDown={(e) => onMouseDown?.(e, item)}
|
| 54 |
+
onMouseEnter={(e) => onMouseEnter?.(e, item)}
|
| 55 |
+
style={{ userSelect: isSelectable ? 'none' : 'auto' }}
|
| 56 |
+
className={`relative group bg-surface border ${isSelected ? 'border-primary ring-2 ring-primary bg-primary/10 shadow-[0_0_20px_rgba(187,134,252,0.15)]' : 'border-white/5 hover:border-primary/30'} rounded-xl p-3 sm:p-4 cursor-pointer transition-all duration-300 ${isSelected ? 'scale-[0.98]' : 'hover:-translate-y-1 hover:shadow-xl'} flex flex-col h-full min-h-[200px] overflow-hidden`}
|
| 57 |
>
|
| 58 |
+
{isSelected && (
|
| 59 |
+
<div className="absolute top-3 right-3 z-20 w-6 h-6 bg-primary rounded-full flex items-center justify-center shadow-lg transition-transform animate-in zoom-in duration-200 pointer-events-none">
|
| 60 |
+
<Check size={14} className="text-[#121212]" strokeWidth={3} />
|
| 61 |
+
</div>
|
| 62 |
+
)}
|
| 63 |
<div className="mb-2 flex-grow flex flex-col">
|
| 64 |
<div className="flex items-start gap-2">
|
| 65 |
{Icon && (
|
| 66 |
+
<div className="text-primary shrink-0 mt-0.5">
|
| 67 |
+
<Icon size={18} className="sm:w-5 sm:h-5" />
|
| 68 |
</div>
|
| 69 |
)}
|
| 70 |
<h3
|
components/ConfirmModal.tsx
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react';
|
| 2 |
+
import { Button } from './Button';
|
| 3 |
+
import { AlertCircle, Trash2 } from 'lucide-react';
|
| 4 |
+
|
| 5 |
+
interface ConfirmModalProps {
|
| 6 |
+
isOpen: boolean;
|
| 7 |
+
onClose: () => void;
|
| 8 |
+
onConfirm: () => void;
|
| 9 |
+
title: string;
|
| 10 |
+
message: string;
|
| 11 |
+
confirmText?: string;
|
| 12 |
+
cancelText?: string;
|
| 13 |
+
isDestructive?: boolean;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
export const ConfirmModal: React.FC<ConfirmModalProps> = ({
|
| 17 |
+
isOpen,
|
| 18 |
+
onClose,
|
| 19 |
+
onConfirm,
|
| 20 |
+
title,
|
| 21 |
+
message,
|
| 22 |
+
confirmText = 'Aceptar',
|
| 23 |
+
cancelText = 'Cancelar',
|
| 24 |
+
isDestructive = false
|
| 25 |
+
}) => {
|
| 26 |
+
if (!isOpen) return null;
|
| 27 |
+
|
| 28 |
+
return (
|
| 29 |
+
<>
|
| 30 |
+
<div
|
| 31 |
+
className="fixed inset-0 bg-black/60 backdrop-blur-sm z-50 animate-in fade-in duration-200"
|
| 32 |
+
onClick={onClose}
|
| 33 |
+
/>
|
| 34 |
+
|
| 35 |
+
<div className="fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-sm bg-[#1a1a1a] shadow-[0_0_50px_rgba(0,0,0,0.5)] z-50 rounded-2xl overflow-hidden border border-white/10 animate-in zoom-in-95 duration-200">
|
| 36 |
+
<div className="p-6">
|
| 37 |
+
<div className="flex items-center gap-3 mb-4">
|
| 38 |
+
{isDestructive ? (
|
| 39 |
+
<div className="p-2.5 bg-red-500/10 rounded-xl text-red-500">
|
| 40 |
+
<Trash2 size={24} />
|
| 41 |
+
</div>
|
| 42 |
+
) : (
|
| 43 |
+
<div className="p-2.5 bg-primary/10 rounded-xl text-primary">
|
| 44 |
+
<AlertCircle size={24} />
|
| 45 |
+
</div>
|
| 46 |
+
)}
|
| 47 |
+
<h2 className="text-xl font-bold text-white tracking-tight">{title}</h2>
|
| 48 |
+
</div>
|
| 49 |
+
|
| 50 |
+
<p className="text-gray-400 mb-8 leading-relaxed">
|
| 51 |
+
{message}
|
| 52 |
+
</p>
|
| 53 |
+
|
| 54 |
+
<div className="flex justify-end gap-3">
|
| 55 |
+
<button
|
| 56 |
+
onClick={onClose}
|
| 57 |
+
className="px-4 py-2 text-sm font-medium text-gray-400 hover:text-white hover:bg-white/5 rounded-xl transition-colors"
|
| 58 |
+
>
|
| 59 |
+
{cancelText}
|
| 60 |
+
</button>
|
| 61 |
+
<Button
|
| 62 |
+
onClick={() => {
|
| 63 |
+
onConfirm();
|
| 64 |
+
onClose();
|
| 65 |
+
}}
|
| 66 |
+
className={`!py-2 !px-5 ${isDestructive ? 'bg-red-500 hover:bg-red-600 text-white shadow-lg shadow-red-500/20' : ''}`}
|
| 67 |
+
>
|
| 68 |
+
{confirmText}
|
| 69 |
+
</Button>
|
| 70 |
+
</div>
|
| 71 |
+
</div>
|
| 72 |
+
</div>
|
| 73 |
+
</>
|
| 74 |
+
);
|
| 75 |
+
};
|
components/MoveToFolderModal.tsx
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useState, useMemo } from 'react';
|
| 2 |
+
import { Button } from './Button';
|
| 3 |
+
import { FolderPlus, Folder, X, Search, MoveUp } from 'lucide-react';
|
| 4 |
+
import { DataItem } from '../types';
|
| 5 |
+
|
| 6 |
+
interface MoveToFolderModalProps {
|
| 7 |
+
isOpen: boolean;
|
| 8 |
+
onClose: () => void;
|
| 9 |
+
selectionCount: number;
|
| 10 |
+
folders: DataItem[];
|
| 11 |
+
currentFolderId: string | null;
|
| 12 |
+
onMoveToFolder: (folderId: string | null) => Promise<void>;
|
| 13 |
+
onCreateFolder: (name: string) => Promise<string>;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
export const MoveToFolderModal: React.FC<MoveToFolderModalProps> = ({
|
| 17 |
+
isOpen,
|
| 18 |
+
onClose,
|
| 19 |
+
selectionCount,
|
| 20 |
+
folders,
|
| 21 |
+
currentFolderId,
|
| 22 |
+
onMoveToFolder,
|
| 23 |
+
onCreateFolder,
|
| 24 |
+
}) => {
|
| 25 |
+
const [searchQuery, setSearchQuery] = useState('');
|
| 26 |
+
const [newFolderName, setNewFolderName] = useState('');
|
| 27 |
+
const [isProcessing, setIsProcessing] = useState(false);
|
| 28 |
+
|
| 29 |
+
// Filter folders to not include the current one if we want to prevent moving to same folder
|
| 30 |
+
// Actually, we can move to any folder.
|
| 31 |
+
// Construir mapa jerárquico recursivo de carpetas o filtrar de forma plana si hay búsqueda
|
| 32 |
+
const filteredFolders = useMemo(() => {
|
| 33 |
+
if (searchQuery.trim() !== '') {
|
| 34 |
+
return folders
|
| 35 |
+
.filter(f => f.title.toLowerCase().includes(searchQuery.toLowerCase()))
|
| 36 |
+
.map(f => ({ folder: f, depth: 0 }));
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
const buildTree = (parentId: string | null = null, depth: number = 0): { folder: DataItem, depth: number }[] => {
|
| 40 |
+
const children = folders.filter(f => (f.parentId || null) === parentId);
|
| 41 |
+
children.sort((a, b) => a.title.localeCompare(b.title));
|
| 42 |
+
|
| 43 |
+
let result: { folder: DataItem, depth: number }[] = [];
|
| 44 |
+
for (const child of children) {
|
| 45 |
+
result.push({ folder: child, depth });
|
| 46 |
+
result = result.concat(buildTree(child.id, depth + 1));
|
| 47 |
+
}
|
| 48 |
+
return result;
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
return buildTree(null, 0);
|
| 52 |
+
}, [folders, searchQuery]);
|
| 53 |
+
|
| 54 |
+
if (!isOpen) return null;
|
| 55 |
+
|
| 56 |
+
const handleCreateAndMove = async () => {
|
| 57 |
+
if (!newFolderName.trim() || isProcessing) return;
|
| 58 |
+
setIsProcessing(true);
|
| 59 |
+
try {
|
| 60 |
+
const newFolderId = await onCreateFolder(newFolderName.trim());
|
| 61 |
+
await onMoveToFolder(newFolderId);
|
| 62 |
+
onClose();
|
| 63 |
+
} catch(e) {
|
| 64 |
+
console.error(e);
|
| 65 |
+
alert("Error al crear carpeta");
|
| 66 |
+
} finally {
|
| 67 |
+
setIsProcessing(false);
|
| 68 |
+
}
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
const handleMove = async (folderId: string | null) => {
|
| 72 |
+
if (isProcessing) return;
|
| 73 |
+
setIsProcessing(true);
|
| 74 |
+
try {
|
| 75 |
+
await onMoveToFolder(folderId);
|
| 76 |
+
onClose();
|
| 77 |
+
} catch(e) {
|
| 78 |
+
console.error(e);
|
| 79 |
+
alert("Error al mover");
|
| 80 |
+
} finally {
|
| 81 |
+
setIsProcessing(false);
|
| 82 |
+
}
|
| 83 |
+
};
|
| 84 |
+
|
| 85 |
+
return (
|
| 86 |
+
<>
|
| 87 |
+
<div
|
| 88 |
+
className="fixed inset-0 bg-black/60 backdrop-blur-sm z-50 animate-in fade-in duration-200"
|
| 89 |
+
onClick={onClose}
|
| 90 |
+
/>
|
| 91 |
+
|
| 92 |
+
<div className="fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-md bg-[#1a1a1a] shadow-[0_0_50px_rgba(0,0,0,0.5)] z-50 rounded-2xl flex flex-col max-h-[85vh] border border-white/10 animate-in zoom-in-95 duration-200">
|
| 93 |
+
|
| 94 |
+
{/* Header */}
|
| 95 |
+
<div className="flex items-center justify-between p-5 border-b border-white/5">
|
| 96 |
+
<div>
|
| 97 |
+
<h2 className="text-xl font-bold text-white tracking-tight">Mover a...</h2>
|
| 98 |
+
<p className="text-sm text-gray-400 mt-1">{selectionCount} elementos seleccionados</p>
|
| 99 |
+
</div>
|
| 100 |
+
<button
|
| 101 |
+
onClick={onClose}
|
| 102 |
+
className="p-2 bg-white/5 hover:bg-white/10 rounded-full transition-colors text-gray-400 hover:text-white"
|
| 103 |
+
>
|
| 104 |
+
<X size={20} />
|
| 105 |
+
</button>
|
| 106 |
+
</div>
|
| 107 |
+
|
| 108 |
+
{/* Content */}
|
| 109 |
+
<div className="p-5 overflow-y-auto flex-1 custom-scrollbar">
|
| 110 |
+
|
| 111 |
+
{/* Create new folder inline */}
|
| 112 |
+
<div className="bg-surface border border-white/5 rounded-xl p-4 mb-6">
|
| 113 |
+
<h3 className="text-sm font-medium text-white mb-3 flex items-center gap-2">
|
| 114 |
+
<FolderPlus size={16} className="text-primary"/> Nueva Carpeta
|
| 115 |
+
</h3>
|
| 116 |
+
<div className="flex gap-2">
|
| 117 |
+
<input
|
| 118 |
+
type="text"
|
| 119 |
+
placeholder="Nombre de la carpeta"
|
| 120 |
+
value={newFolderName}
|
| 121 |
+
onChange={(e) => setNewFolderName(e.target.value)}
|
| 122 |
+
onKeyDown={(e) => {
|
| 123 |
+
if (e.key === 'Enter') {
|
| 124 |
+
e.preventDefault();
|
| 125 |
+
handleCreateAndMove();
|
| 126 |
+
}
|
| 127 |
+
}}
|
| 128 |
+
className="flex-1 bg-[#121212] border border-white/10 focus:border-primary rounded-lg px-3 py-2 text-sm outline-none transition-colors"
|
| 129 |
+
disabled={isProcessing}
|
| 130 |
+
/>
|
| 131 |
+
<Button
|
| 132 |
+
onClick={handleCreateAndMove}
|
| 133 |
+
disabled={!newFolderName.trim() || isProcessing}
|
| 134 |
+
className="!py-2 !px-4 whitespace-nowrap"
|
| 135 |
+
>
|
| 136 |
+
Crear y Mover
|
| 137 |
+
</Button>
|
| 138 |
+
</div>
|
| 139 |
+
</div>
|
| 140 |
+
|
| 141 |
+
{/* Search folders */}
|
| 142 |
+
<div className="mb-4 relative">
|
| 143 |
+
<Search className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-500" size={16} />
|
| 144 |
+
<input
|
| 145 |
+
type="text"
|
| 146 |
+
placeholder="Buscar carpeta..."
|
| 147 |
+
value={searchQuery}
|
| 148 |
+
onChange={(e) => setSearchQuery(e.target.value)}
|
| 149 |
+
className="w-full bg-[#121212] border border-white/10 focus:border-primary rounded-lg py-2.5 pl-10 pr-4 text-sm outline-none transition-colors"
|
| 150 |
+
/>
|
| 151 |
+
</div>
|
| 152 |
+
|
| 153 |
+
{/* Folder List */}
|
| 154 |
+
<div className="space-y-2">
|
| 155 |
+
{currentFolderId !== null && !searchQuery && (
|
| 156 |
+
<button
|
| 157 |
+
onClick={() => handleMove(null)}
|
| 158 |
+
disabled={isProcessing}
|
| 159 |
+
className="w-full flex items-center gap-3 p-3 rounded-xl hover:bg-white/5 transition-colors text-left group"
|
| 160 |
+
>
|
| 161 |
+
<div className="p-2 bg-white/5 rounded-lg text-gray-400 group-hover:text-white transition-colors">
|
| 162 |
+
<MoveUp size={18} />
|
| 163 |
+
</div>
|
| 164 |
+
<span className="font-medium text-gray-300 group-hover:text-white transition-colors">Volver a la Raíz</span>
|
| 165 |
+
</button>
|
| 166 |
+
)}
|
| 167 |
+
|
| 168 |
+
{filteredFolders.length === 0 ? (
|
| 169 |
+
<p className="text-center text-sm text-gray-500 py-6">No se encontraron carpetas.</p>
|
| 170 |
+
) : (
|
| 171 |
+
filteredFolders.map(({ folder, depth }) => (
|
| 172 |
+
<button
|
| 173 |
+
key={folder.id}
|
| 174 |
+
onClick={() => handleMove(folder.id)}
|
| 175 |
+
disabled={isProcessing || folder.id === currentFolderId}
|
| 176 |
+
className={`w-full flex items-center gap-3 p-3 rounded-xl transition-all text-left group border border-transparent hover:border-white/5 ${
|
| 177 |
+
folder.id === currentFolderId ? 'opacity-50 cursor-not-allowed bg-white/5' : 'hover:bg-white/5'
|
| 178 |
+
}`}
|
| 179 |
+
>
|
| 180 |
+
{/* Espaciador de profundidad para simular el mapa/árbol */}
|
| 181 |
+
{depth > 0 && (
|
| 182 |
+
<div style={{ width: `${depth * 20}px` }} className="h-full border-l border-white/10 ml-2" />
|
| 183 |
+
)}
|
| 184 |
+
|
| 185 |
+
<div className="p-2 bg-primary/10 rounded-lg text-primary">
|
| 186 |
+
<Folder size={18} />
|
| 187 |
+
</div>
|
| 188 |
+
<div className="flex-1 overflow-hidden">
|
| 189 |
+
<span className="font-medium text-gray-300 group-hover:text-white transition-colors truncate block">
|
| 190 |
+
{folder.title}
|
| 191 |
+
{folder.id === currentFolderId && <span className="ml-2 text-xs text-primary font-normal">(Ubicación actual)</span>}
|
| 192 |
+
</span>
|
| 193 |
+
</div>
|
| 194 |
+
</button>
|
| 195 |
+
))
|
| 196 |
+
)}
|
| 197 |
+
</div>
|
| 198 |
+
|
| 199 |
+
</div>
|
| 200 |
+
</div>
|
| 201 |
+
</>
|
| 202 |
+
);
|
| 203 |
+
};
|
dist/assets/index-B8NpKCEH.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
dist/index.html
CHANGED
|
@@ -72,7 +72,7 @@
|
|
| 72 |
}
|
| 73 |
}
|
| 74 |
</script>
|
| 75 |
-
<script type="module" crossorigin src="/assets/index-
|
| 76 |
<link rel="stylesheet" crossorigin href="/assets/index-DLwUYtS5.css">
|
| 77 |
</head>
|
| 78 |
|
|
|
|
| 72 |
}
|
| 73 |
}
|
| 74 |
</script>
|
| 75 |
+
<script type="module" crossorigin src="/assets/index-B8NpKCEH.js"></script>
|
| 76 |
<link rel="stylesheet" crossorigin href="/assets/index-DLwUYtS5.css">
|
| 77 |
</head>
|
| 78 |
|
services/firebase.ts
CHANGED
|
@@ -73,15 +73,16 @@ export const subscribeToItems = (callback: (items: DataItem[]) => void) => {
|
|
| 73 |
});
|
| 74 |
};
|
| 75 |
|
| 76 |
-
export const addItem = async (item: Omit<DataItem, 'id' | 'createdAt'>) => {
|
| 77 |
try {
|
| 78 |
// Sanitize the item to ensure no undefined values are sent
|
| 79 |
const itemToSave = cleanData(item);
|
| 80 |
|
| 81 |
-
await addDoc(collection(db, COLLECTION_NAME), {
|
| 82 |
...itemToSave,
|
| 83 |
createdAt: serverTimestamp() // Use server timestamp for consistency
|
| 84 |
});
|
|
|
|
| 85 |
} catch (e) {
|
| 86 |
console.error("Error adding document: ", e);
|
| 87 |
throw e;
|
|
|
|
| 73 |
});
|
| 74 |
};
|
| 75 |
|
| 76 |
+
export const addItem = async (item: Omit<DataItem, 'id' | 'createdAt'>): Promise<string> => {
|
| 77 |
try {
|
| 78 |
// Sanitize the item to ensure no undefined values are sent
|
| 79 |
const itemToSave = cleanData(item);
|
| 80 |
|
| 81 |
+
const docRef = await addDoc(collection(db, COLLECTION_NAME), {
|
| 82 |
...itemToSave,
|
| 83 |
createdAt: serverTimestamp() // Use server timestamp for consistency
|
| 84 |
});
|
| 85 |
+
return docRef.id;
|
| 86 |
} catch (e) {
|
| 87 |
console.error("Error adding document: ", e);
|
| 88 |
throw e;
|
types.ts
CHANGED
|
@@ -26,6 +26,8 @@ export interface DataItem {
|
|
| 26 |
updatedAt?: number; // Added for modification date sorting
|
| 27 |
tags: string[];
|
| 28 |
categories?: string[];
|
|
|
|
|
|
|
| 29 |
}
|
| 30 |
|
| 31 |
export type ViewState = 'LIST' | 'DETAIL' | 'CREATE' | 'EDIT';
|
|
|
|
| 26 |
updatedAt?: number; // Added for modification date sorting
|
| 27 |
tags: string[];
|
| 28 |
categories?: string[];
|
| 29 |
+
isFolder?: boolean;
|
| 30 |
+
parentId?: string | null;
|
| 31 |
}
|
| 32 |
|
| 33 |
export type ViewState = 'LIST' | 'DETAIL' | 'CREATE' | 'EDIT';
|