dante commited on
Upload 36 files
Browse files- src/App.tsx +83 -9
- src/components/BulkCategoryModal.tsx +329 -0
- src/components/CategorySelector.tsx +215 -0
- src/components/HDComicViewer.tsx +4 -16
- src/components/MangaCard.tsx +40 -25
- src/components/NewMangaModal.tsx +91 -171
- src/components/SearchResults.tsx +9 -0
- src/components/SettingsModal.tsx +28 -2
- src/services/manga.ts +24 -2
- src/types/manga.ts +1 -0
- src/utils/searchUtils.ts +19 -1
src/App.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
import { useState, useEffect, useMemo } from 'react';
|
| 3 |
import { HDComicViewer } from './components/HDComicViewer';
|
| 4 |
import { NewMangaModal } from './components/NewMangaModal';
|
|
@@ -7,9 +8,11 @@ import { AnnouncementBanner } from './components/AnnouncementBanner';
|
|
| 7 |
import { ComicDetail } from './components/ComicDetail';
|
| 8 |
import { ChapterReader } from './components/ChapterReader';
|
| 9 |
import { InfoPage } from './components/InfoPage';
|
|
|
|
| 10 |
|
| 11 |
import { SearchBar } from './components/SearchBar';
|
| 12 |
import { SearchResults } from './components/SearchResults';
|
|
|
|
| 13 |
import { getAllMangas, deleteManga } from './services/manga';
|
| 14 |
import { Manga, Chapter } from './types/manga';
|
| 15 |
import { searchItems } from './utils/searchUtils';
|
|
@@ -25,6 +28,9 @@ function App() {
|
|
| 25 |
return localStorage.getItem('isAdmin') === 'true';
|
| 26 |
});
|
| 27 |
const [editingManga, setEditingManga] = useState<Manga | null>(null);
|
|
|
|
|
|
|
|
|
|
| 28 |
const [selectedComicId, setSelectedComicId] = useState<string | null>(null);
|
| 29 |
const [navigationHistory, setNavigationHistory] = useState<string[]>([]);
|
| 30 |
const [selectedChapter, setSelectedChapter] = useState<{ manga: Manga; chapter: Chapter } | null>(null);
|
|
@@ -122,7 +128,12 @@ function App() {
|
|
| 122 |
return { items: mangas, query: '', resultCount: mangas.length };
|
| 123 |
}
|
| 124 |
return searchItems(
|
| 125 |
-
mangas.map(m => ({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
searchTerm,
|
| 127 |
{ fuzzyMatch: true, minChars: 1 }
|
| 128 |
);
|
|
@@ -181,8 +192,22 @@ function App() {
|
|
| 181 |
}
|
| 182 |
};
|
| 183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
const handleSelectComic = (mangaId: string) => {
|
| 185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
setSelectedComicId(mangaId);
|
| 187 |
};
|
| 188 |
|
|
@@ -196,7 +221,7 @@ function App() {
|
|
| 196 |
if (selectedComicId) {
|
| 197 |
setNavigationHistory([...navigationHistory, selectedComicId]);
|
| 198 |
}
|
| 199 |
-
window.location.hash = `manga/${newMangaId}`;
|
| 200 |
setSelectedComicId(newMangaId);
|
| 201 |
};
|
| 202 |
|
|
@@ -238,7 +263,7 @@ function App() {
|
|
| 238 |
onBack={() => {
|
| 239 |
window.history.back();
|
| 240 |
// Fallback if history back doesn't work or we want explicit control:
|
| 241 |
-
// window.location.hash = `manga/${selectedComicId}`;
|
| 242 |
}}
|
| 243 |
/>
|
| 244 |
);
|
|
@@ -251,7 +276,7 @@ function App() {
|
|
| 251 |
if (navigationHistory.length > 0) {
|
| 252 |
const previousId = navigationHistory[navigationHistory.length - 1];
|
| 253 |
setNavigationHistory(navigationHistory.slice(0, -1));
|
| 254 |
-
window.location.hash = `manga/${previousId}`;
|
| 255 |
setSelectedComicId(previousId);
|
| 256 |
} else {
|
| 257 |
handleBackToHome();
|
|
@@ -288,9 +313,18 @@ function App() {
|
|
| 288 |
</h1>
|
| 289 |
</div>
|
| 290 |
<div className="flex items-center gap-1.5 sm:gap-3">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
<button
|
| 292 |
onClick={() => setShowSettingsModal(true)}
|
| 293 |
-
className="bg-gray-800 hover:bg-gray-700 active:scale-95 text-white px-2 py-2 sm:px-4 sm:py-2.5 rounded-lg flex items-center gap-1.5 sm:gap-2 font-semibold transition-all duration-300 border border-gray-700/50 hover:border-gray-600 text-xs sm:text-sm hover:scale-110 hover:shadow-lg hover:shadow-
|
| 294 |
title="Ajustes y Admin"
|
| 295 |
>
|
| 296 |
<Settings className="w-4 h-4 sm:w-5 sm:h-5 transition-transform duration-300 hover:rotate-180" />
|
|
@@ -341,12 +375,40 @@ function App() {
|
|
| 341 |
onSelectComic={handleSelectComic}
|
| 342 |
onEditManga={isAdmin ? handleEditManga : undefined}
|
| 343 |
onDeleteManga={isAdmin ? handleDeleteManga : undefined}
|
|
|
|
|
|
|
|
|
|
| 344 |
/>
|
| 345 |
</>
|
| 346 |
)}
|
| 347 |
</div>
|
| 348 |
</main>
|
| 349 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
<GlobalFooter />
|
| 351 |
|
| 352 |
<NewMangaModal
|
|
@@ -368,16 +430,28 @@ function App() {
|
|
| 368 |
onDelete={isAdmin ? handleDeleteManga : undefined}
|
| 369 |
/>
|
| 370 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
<SettingsModal
|
| 372 |
isOpen={showSettingsModal}
|
| 373 |
onClose={() => setShowSettingsModal(false)}
|
| 374 |
isAdmin={isAdmin}
|
| 375 |
onAdminChange={setIsAdmin}
|
|
|
|
|
|
|
| 376 |
/>
|
| 377 |
-
|
| 378 |
-
|
| 379 |
</div>
|
| 380 |
);
|
| 381 |
}
|
| 382 |
|
| 383 |
export default App;
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import { Plus, Settings, Layers } from 'lucide-react';
|
| 3 |
import { useState, useEffect, useMemo } from 'react';
|
| 4 |
import { HDComicViewer } from './components/HDComicViewer';
|
| 5 |
import { NewMangaModal } from './components/NewMangaModal';
|
|
|
|
| 8 |
import { ComicDetail } from './components/ComicDetail';
|
| 9 |
import { ChapterReader } from './components/ChapterReader';
|
| 10 |
import { InfoPage } from './components/InfoPage';
|
| 11 |
+
import { BulkCategoryModal } from './components/BulkCategoryModal';
|
| 12 |
|
| 13 |
import { SearchBar } from './components/SearchBar';
|
| 14 |
import { SearchResults } from './components/SearchResults';
|
| 15 |
+
import { Toaster } from 'sonner';
|
| 16 |
import { getAllMangas, deleteManga } from './services/manga';
|
| 17 |
import { Manga, Chapter } from './types/manga';
|
| 18 |
import { searchItems } from './utils/searchUtils';
|
|
|
|
| 28 |
return localStorage.getItem('isAdmin') === 'true';
|
| 29 |
});
|
| 30 |
const [editingManga, setEditingManga] = useState<Manga | null>(null);
|
| 31 |
+
const [isCategoryPlusEnabled, setIsCategoryPlusEnabled] = useState(false);
|
| 32 |
+
const [selectedMangaIds, setSelectedMangaIds] = useState<string[]>([]);
|
| 33 |
+
const [showBulkModal, setShowBulkModal] = useState(false);
|
| 34 |
const [selectedComicId, setSelectedComicId] = useState<string | null>(null);
|
| 35 |
const [navigationHistory, setNavigationHistory] = useState<string[]>([]);
|
| 36 |
const [selectedChapter, setSelectedChapter] = useState<{ manga: Manga; chapter: Chapter } | null>(null);
|
|
|
|
| 128 |
return { items: mangas, query: '', resultCount: mangas.length };
|
| 129 |
}
|
| 130 |
return searchItems(
|
| 131 |
+
mangas.map(m => ({
|
| 132 |
+
id: m.id,
|
| 133 |
+
title: m.title,
|
| 134 |
+
author: m.author,
|
| 135 |
+
categories: m.categories ? m.categories.map(c => c.name) : []
|
| 136 |
+
})),
|
| 137 |
searchTerm,
|
| 138 |
{ fuzzyMatch: true, minChars: 1 }
|
| 139 |
);
|
|
|
|
| 192 |
}
|
| 193 |
};
|
| 194 |
|
| 195 |
+
const toggleSelectManga = (id: string) => {
|
| 196 |
+
setSelectedMangaIds(prev => {
|
| 197 |
+
if (prev.includes(id)) {
|
| 198 |
+
return prev.filter(mId => mId !== id);
|
| 199 |
+
} else {
|
| 200 |
+
return [...prev, id];
|
| 201 |
+
}
|
| 202 |
+
});
|
| 203 |
+
};
|
| 204 |
+
|
| 205 |
const handleSelectComic = (mangaId: string) => {
|
| 206 |
+
if (isCategoryPlusEnabled) {
|
| 207 |
+
toggleSelectManga(mangaId);
|
| 208 |
+
return;
|
| 209 |
+
}
|
| 210 |
+
window.location.hash = `manga / ${mangaId} `;
|
| 211 |
setSelectedComicId(mangaId);
|
| 212 |
};
|
| 213 |
|
|
|
|
| 221 |
if (selectedComicId) {
|
| 222 |
setNavigationHistory([...navigationHistory, selectedComicId]);
|
| 223 |
}
|
| 224 |
+
window.location.hash = `manga / ${newMangaId} `;
|
| 225 |
setSelectedComicId(newMangaId);
|
| 226 |
};
|
| 227 |
|
|
|
|
| 263 |
onBack={() => {
|
| 264 |
window.history.back();
|
| 265 |
// Fallback if history back doesn't work or we want explicit control:
|
| 266 |
+
// window.location.hash = `manga / ${ selectedComicId } `;
|
| 267 |
}}
|
| 268 |
/>
|
| 269 |
);
|
|
|
|
| 276 |
if (navigationHistory.length > 0) {
|
| 277 |
const previousId = navigationHistory[navigationHistory.length - 1];
|
| 278 |
setNavigationHistory(navigationHistory.slice(0, -1));
|
| 279 |
+
window.location.hash = `manga / ${previousId} `;
|
| 280 |
setSelectedComicId(previousId);
|
| 281 |
} else {
|
| 282 |
handleBackToHome();
|
|
|
|
| 313 |
</h1>
|
| 314 |
</div>
|
| 315 |
<div className="flex items-center gap-1.5 sm:gap-3">
|
| 316 |
+
{isCategoryPlusEnabled && (
|
| 317 |
+
<div className="hidden sm:flex items-center gap-2 mr-2 px-3 py-1.5 bg-purple-500/10 rounded-lg border border-purple-500/20">
|
| 318 |
+
<Layers className="w-4 h-4 text-purple-400" />
|
| 319 |
+
<span className="text-xs font-semibold text-purple-300">Modo Plus Activo</span>
|
| 320 |
+
<span className="text-xs bg-purple-500/20 px-2 py-0.5 rounded text-purple-200">
|
| 321 |
+
{selectedMangaIds.length}
|
| 322 |
+
</span>
|
| 323 |
+
</div>
|
| 324 |
+
)}
|
| 325 |
<button
|
| 326 |
onClick={() => setShowSettingsModal(true)}
|
| 327 |
+
className="bg-gray-800 hover:bg-gray-700 active:scale-95 text-white px-2 py-2 sm:px-4 sm:py-2.5 rounded-lg flex items-center gap-1.5 sm:gap-2 font-semibold transition-all duration-300 border border-gray-700/50 hover:border-gray-600 text-xs sm:text-sm hover:scale-110 hover:shadow-lg hover:shadow-700/50"
|
| 328 |
title="Ajustes y Admin"
|
| 329 |
>
|
| 330 |
<Settings className="w-4 h-4 sm:w-5 sm:h-5 transition-transform duration-300 hover:rotate-180" />
|
|
|
|
| 375 |
onSelectComic={handleSelectComic}
|
| 376 |
onEditManga={isAdmin ? handleEditManga : undefined}
|
| 377 |
onDeleteManga={isAdmin ? handleDeleteManga : undefined}
|
| 378 |
+
isCategoryPlusEnabled={isCategoryPlusEnabled}
|
| 379 |
+
selectedMangaIds={selectedMangaIds}
|
| 380 |
+
onToggleSelectManga={toggleSelectManga}
|
| 381 |
/>
|
| 382 |
</>
|
| 383 |
)}
|
| 384 |
</div>
|
| 385 |
</main>
|
| 386 |
|
| 387 |
+
{/* Bulk Action Bar */}
|
| 388 |
+
{isCategoryPlusEnabled && selectedMangaIds.length > 0 && (
|
| 389 |
+
<div className="fixed bottom-6 left-1/2 transform -translate-x-1/2 z-40 animate-in slide-in-from-bottom-4 duration-200">
|
| 390 |
+
<div className="bg-[#1a1a1a] border border-gray-700/50 shadow-2xl rounded-xl px-6 py-3 flex items-center gap-4">
|
| 391 |
+
<div className="flex flex-col">
|
| 392 |
+
<span className="text-sm font-bold text-white">{selectedMangaIds.length} seleccionados</span>
|
| 393 |
+
<span className="text-xs text-gray-400">Listos para editar</span>
|
| 394 |
+
</div>
|
| 395 |
+
<div className="h-8 w-px bg-gray-700"></div>
|
| 396 |
+
<button
|
| 397 |
+
onClick={() => setSelectedMangaIds([])}
|
| 398 |
+
className="text-gray-400 hover:text-white text-sm font-semibold transition-colors"
|
| 399 |
+
>
|
| 400 |
+
Cancelar
|
| 401 |
+
</button>
|
| 402 |
+
<button
|
| 403 |
+
onClick={() => setShowBulkModal(true)}
|
| 404 |
+
className="bg-[#bb86fc] hover:bg-[#9966dd] text-white px-4 py-2 rounded-lg text-sm font-bold shadow-lg shadow-purple-500/20 transition-all transform hover:scale-105 active:scale-95"
|
| 405 |
+
>
|
| 406 |
+
Aplicar Categorías
|
| 407 |
+
</button>
|
| 408 |
+
</div>
|
| 409 |
+
</div>
|
| 410 |
+
)}
|
| 411 |
+
|
| 412 |
<GlobalFooter />
|
| 413 |
|
| 414 |
<NewMangaModal
|
|
|
|
| 430 |
onDelete={isAdmin ? handleDeleteManga : undefined}
|
| 431 |
/>
|
| 432 |
|
| 433 |
+
<BulkCategoryModal
|
| 434 |
+
isOpen={showBulkModal}
|
| 435 |
+
onClose={() => setShowBulkModal(false)}
|
| 436 |
+
selectedMangaIds={selectedMangaIds}
|
| 437 |
+
onSaveComplete={() => {
|
| 438 |
+
loadMangas();
|
| 439 |
+
setSelectedMangaIds([]);
|
| 440 |
+
}}
|
| 441 |
+
/>
|
| 442 |
+
|
| 443 |
<SettingsModal
|
| 444 |
isOpen={showSettingsModal}
|
| 445 |
onClose={() => setShowSettingsModal(false)}
|
| 446 |
isAdmin={isAdmin}
|
| 447 |
onAdminChange={setIsAdmin}
|
| 448 |
+
isCategoryPlusEnabled={isCategoryPlusEnabled}
|
| 449 |
+
onCategoryPlusChange={setIsCategoryPlusEnabled}
|
| 450 |
/>
|
| 451 |
+
<Toaster position="top-center" richColors theme="dark" />
|
|
|
|
| 452 |
</div>
|
| 453 |
);
|
| 454 |
}
|
| 455 |
|
| 456 |
export default App;
|
| 457 |
+
|
src/components/BulkCategoryModal.tsx
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { X, Plus, Save } from 'lucide-react';
|
| 2 |
+
import { toast } from 'sonner';
|
| 3 |
+
import { useState, useEffect } from 'react';
|
| 4 |
+
import { Category } from '../types/manga';
|
| 5 |
+
import { createCategory, getAllCategories, updateManga, getMangaById } from '../services/manga';
|
| 6 |
+
import { LoadingSpinner } from './LoadingSpinner';
|
| 7 |
+
|
| 8 |
+
interface BulkCategoryModalProps {
|
| 9 |
+
isOpen: boolean;
|
| 10 |
+
onClose: () => void;
|
| 11 |
+
selectedMangaIds: string[];
|
| 12 |
+
onSaveComplete: () => void;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
export function BulkCategoryModal({ isOpen, onClose, selectedMangaIds, onSaveComplete }: BulkCategoryModalProps) {
|
| 16 |
+
const [categories, setCategories] = useState<Category[]>([]);
|
| 17 |
+
const [selectedCategories, setSelectedCategories] = useState<string[]>([]);
|
| 18 |
+
|
| 19 |
+
const [newCharacterName, setNewCharacterName] = useState('');
|
| 20 |
+
const [newSeriesName, setNewSeriesName] = useState('');
|
| 21 |
+
const [newGenreName, setNewGenreName] = useState('');
|
| 22 |
+
|
| 23 |
+
const [isSaving, setIsSaving] = useState(false);
|
| 24 |
+
const [isLoading, setIsLoading] = useState(false);
|
| 25 |
+
|
| 26 |
+
useEffect(() => {
|
| 27 |
+
if (isOpen) {
|
| 28 |
+
loadCategories();
|
| 29 |
+
setSelectedCategories([]); // Reset selection on open
|
| 30 |
+
}
|
| 31 |
+
}, [isOpen]);
|
| 32 |
+
|
| 33 |
+
const loadCategories = async () => {
|
| 34 |
+
try {
|
| 35 |
+
setIsLoading(true);
|
| 36 |
+
const data = await getAllCategories();
|
| 37 |
+
setCategories(data);
|
| 38 |
+
} catch (error) {
|
| 39 |
+
console.error('Error loading categories:', error);
|
| 40 |
+
} finally {
|
| 41 |
+
setIsLoading(false);
|
| 42 |
+
}
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
const handleCreateCategory = async (name: string, type: 'character' | 'series' | 'genre') => {
|
| 46 |
+
if (!name.trim()) return;
|
| 47 |
+
|
| 48 |
+
try {
|
| 49 |
+
const existingCategory = categories.find(
|
| 50 |
+
cat => cat.name.toLowerCase() === name.trim().toLowerCase() && cat.type === type
|
| 51 |
+
);
|
| 52 |
+
|
| 53 |
+
if (existingCategory) {
|
| 54 |
+
if (!selectedCategories.includes(existingCategory.id)) {
|
| 55 |
+
setSelectedCategories(prev => [...prev, existingCategory.id]);
|
| 56 |
+
}
|
| 57 |
+
} else {
|
| 58 |
+
const newCategory = await createCategory(name.trim(), type);
|
| 59 |
+
setCategories(prev => [...prev, newCategory]);
|
| 60 |
+
setSelectedCategories(prev => [...prev, newCategory.id]);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
if (type === 'character') setNewCharacterName('');
|
| 64 |
+
if (type === 'series') setNewSeriesName('');
|
| 65 |
+
if (type === 'genre') setNewGenreName('');
|
| 66 |
+
|
| 67 |
+
} catch (error) {
|
| 68 |
+
console.error('Error creating category:', error);
|
| 69 |
+
toast.error('Error al crear la categoría');
|
| 70 |
+
}
|
| 71 |
+
};
|
| 72 |
+
|
| 73 |
+
const handleRemoveCategory = (categoryId: string) => {
|
| 74 |
+
setSelectedCategories(prev => prev.filter(id => id !== categoryId));
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
const handleSave = async () => {
|
| 78 |
+
if (selectedCategories.length === 0) {
|
| 79 |
+
toast.error('Selecciona al menos una categoría para aplicar.');
|
| 80 |
+
return;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
setIsSaving(true);
|
| 84 |
+
try {
|
| 85 |
+
// Process all mangas
|
| 86 |
+
// Strategy: Fetch current manga data (to get existing categories), append new ones unique, update.
|
| 87 |
+
// This ensures we don't overwrite existing categories that are NOT in the selection.
|
| 88 |
+
|
| 89 |
+
const updatePromises = selectedMangaIds.map(async (mangaId) => {
|
| 90 |
+
try {
|
| 91 |
+
const manga = await getMangaById(mangaId);
|
| 92 |
+
if (!manga) return;
|
| 93 |
+
|
| 94 |
+
const existingIds = manga.categories?.map(c => c.id) || [];
|
| 95 |
+
// Merge existing with selected, avoid duplicates
|
| 96 |
+
const mergedIds = Array.from(new Set([...existingIds, ...selectedCategories]));
|
| 97 |
+
|
| 98 |
+
await updateManga(mangaId, {
|
| 99 |
+
title: manga.title,
|
| 100 |
+
author: manga.author,
|
| 101 |
+
categoryIds: mergedIds
|
| 102 |
+
});
|
| 103 |
+
} catch (err) {
|
| 104 |
+
console.error(`Error updating manga ${mangaId}`, err);
|
| 105 |
+
}
|
| 106 |
+
});
|
| 107 |
+
|
| 108 |
+
await Promise.all(updatePromises);
|
| 109 |
+
toast.success('Categorías aplicadas correctamente.');
|
| 110 |
+
onSaveComplete();
|
| 111 |
+
onClose();
|
| 112 |
+
|
| 113 |
+
} catch (error) {
|
| 114 |
+
console.error('Error bulk updating mangas:', error);
|
| 115 |
+
toast.error('Error al aplicar cambios.');
|
| 116 |
+
} finally {
|
| 117 |
+
setIsSaving(false);
|
| 118 |
+
}
|
| 119 |
+
};
|
| 120 |
+
|
| 121 |
+
if (!isOpen) return null;
|
| 122 |
+
|
| 123 |
+
return (
|
| 124 |
+
<div className="fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4 animate-in fade-in duration-200">
|
| 125 |
+
<div className="bg-[#121212] rounded-2xl border border-gray-800 w-full max-w-2xl shadow-2xl overflow-hidden flex flex-col max-h-[90vh]">
|
| 126 |
+
|
| 127 |
+
{/* Header */}
|
| 128 |
+
<div className="bg-[#1a1a1a] border-b border-gray-800 px-6 py-4 flex items-center justify-between sticky top-0 z-10">
|
| 129 |
+
<h2 className="text-xl font-bold text-white">
|
| 130 |
+
Aplicar Categorías a {selectedMangaIds.length} Mangas
|
| 131 |
+
</h2>
|
| 132 |
+
<button onClick={onClose} className="text-gray-400 hover:text-white transition-colors p-2 hover:bg-white/5 rounded-lg">
|
| 133 |
+
<X className="w-5 h-5" />
|
| 134 |
+
</button>
|
| 135 |
+
</div>
|
| 136 |
+
|
| 137 |
+
<div className="p-6 overflow-y-auto custom-scrollbar flex-1">
|
| 138 |
+
{isLoading ? (
|
| 139 |
+
<div className="flex justify-center p-8">
|
| 140 |
+
<LoadingSpinner size={32} />
|
| 141 |
+
</div>
|
| 142 |
+
) : (
|
| 143 |
+
<div className="space-y-6">
|
| 144 |
+
{/* Personajes */}
|
| 145 |
+
<div className="space-y-3">
|
| 146 |
+
<label className="text-xs text-blue-400 uppercase font-bold tracking-wider">Personajes</label>
|
| 147 |
+
<div className="flex gap-2">
|
| 148 |
+
<select
|
| 149 |
+
onChange={(e) => {
|
| 150 |
+
const catId = e.target.value;
|
| 151 |
+
if (catId && !selectedCategories.includes(catId)) {
|
| 152 |
+
setSelectedCategories(prev => [...prev, catId]);
|
| 153 |
+
}
|
| 154 |
+
}}
|
| 155 |
+
value=""
|
| 156 |
+
className="w-1/3 bg-[#1a1a1a] border border-gray-600/50 rounded-lg px-3 py-2 text-sm text-white focus:outline-none focus:border-[#bb86fc]"
|
| 157 |
+
>
|
| 158 |
+
<option value="">Seleccionar...</option>
|
| 159 |
+
{categories.filter(c => c.type === 'character').map(cat => (
|
| 160 |
+
<option key={cat.id} value={cat.id}>{cat.name}</option>
|
| 161 |
+
))}
|
| 162 |
+
</select>
|
| 163 |
+
<input
|
| 164 |
+
type="text"
|
| 165 |
+
placeholder="Nuevo personaje..."
|
| 166 |
+
value={newCharacterName}
|
| 167 |
+
onChange={(e) => setNewCharacterName(e.target.value)}
|
| 168 |
+
onKeyPress={(e) => e.key === 'Enter' && handleCreateCategory(newCharacterName, 'character')}
|
| 169 |
+
className="flex-1 bg-[#1a1a1a] border border-gray-600/50 rounded-lg px-4 py-2 text-sm text-white focus:outline-none focus:border-[#bb86fc]"
|
| 170 |
+
/>
|
| 171 |
+
<button
|
| 172 |
+
onClick={() => handleCreateCategory(newCharacterName, 'character')}
|
| 173 |
+
disabled={!newCharacterName.trim()}
|
| 174 |
+
className="bg-[#bb86fc]/20 hover:bg-[#bb86fc]/30 text-[#bb86fc] px-3 rounded-lg"
|
| 175 |
+
>
|
| 176 |
+
<Plus className="w-5 h-5" />
|
| 177 |
+
</button>
|
| 178 |
+
</div>
|
| 179 |
+
<div className="flex gap-2 flex-wrap">
|
| 180 |
+
{selectedCategories.map(catId => {
|
| 181 |
+
const category = categories.find(c => c.id === catId);
|
| 182 |
+
if (category && category.type === 'character') {
|
| 183 |
+
return (
|
| 184 |
+
<span key={catId} className="px-3 py-1 bg-blue-500/20 text-blue-300 text-xs rounded-full border border-blue-500/30 flex items-center gap-2">
|
| 185 |
+
{category.name}
|
| 186 |
+
<button onClick={() => handleRemoveCategory(catId)} className="hover:text-white"><X className="w-3 h-3" /></button>
|
| 187 |
+
</span>
|
| 188 |
+
);
|
| 189 |
+
}
|
| 190 |
+
return null;
|
| 191 |
+
})}
|
| 192 |
+
</div>
|
| 193 |
+
</div>
|
| 194 |
+
|
| 195 |
+
{/* Series */}
|
| 196 |
+
<div className="space-y-3">
|
| 197 |
+
<label className="text-xs text-green-400 uppercase font-bold tracking-wider">Series</label>
|
| 198 |
+
<div className="flex gap-2">
|
| 199 |
+
<select
|
| 200 |
+
onChange={(e) => {
|
| 201 |
+
const catId = e.target.value;
|
| 202 |
+
if (catId && !selectedCategories.includes(catId)) {
|
| 203 |
+
setSelectedCategories(prev => [...prev, catId]);
|
| 204 |
+
}
|
| 205 |
+
}}
|
| 206 |
+
value=""
|
| 207 |
+
className="w-1/3 bg-[#1a1a1a] border border-gray-600/50 rounded-lg px-3 py-2 text-sm text-white focus:outline-none focus:border-[#bb86fc]"
|
| 208 |
+
>
|
| 209 |
+
<option value="">Seleccionar...</option>
|
| 210 |
+
{categories.filter(c => c.type === 'series').map(cat => (
|
| 211 |
+
<option key={cat.id} value={cat.id}>{cat.name}</option>
|
| 212 |
+
))}
|
| 213 |
+
</select>
|
| 214 |
+
<input
|
| 215 |
+
type="text"
|
| 216 |
+
placeholder="Nueva serie..."
|
| 217 |
+
value={newSeriesName}
|
| 218 |
+
onChange={(e) => setNewSeriesName(e.target.value)}
|
| 219 |
+
onKeyPress={(e) => e.key === 'Enter' && handleCreateCategory(newSeriesName, 'series')}
|
| 220 |
+
className="flex-1 bg-[#1a1a1a] border border-gray-600/50 rounded-lg px-4 py-2 text-sm text-white focus:outline-none focus:border-[#bb86fc]"
|
| 221 |
+
/>
|
| 222 |
+
<button
|
| 223 |
+
onClick={() => handleCreateCategory(newSeriesName, 'series')}
|
| 224 |
+
disabled={!newSeriesName.trim()}
|
| 225 |
+
className="bg-[#bb86fc]/20 hover:bg-[#bb86fc]/30 text-[#bb86fc] px-3 rounded-lg"
|
| 226 |
+
>
|
| 227 |
+
<Plus className="w-5 h-5" />
|
| 228 |
+
</button>
|
| 229 |
+
</div>
|
| 230 |
+
<div className="flex gap-2 flex-wrap">
|
| 231 |
+
{selectedCategories.map(catId => {
|
| 232 |
+
const category = categories.find(c => c.id === catId);
|
| 233 |
+
if (category && category.type === 'series') {
|
| 234 |
+
return (
|
| 235 |
+
<span key={catId} className="px-3 py-1 bg-green-500/20 text-green-300 text-xs rounded-full border border-green-500/30 flex items-center gap-2">
|
| 236 |
+
{category.name}
|
| 237 |
+
<button onClick={() => handleRemoveCategory(catId)} className="hover:text-white"><X className="w-3 h-3" /></button>
|
| 238 |
+
</span>
|
| 239 |
+
);
|
| 240 |
+
}
|
| 241 |
+
return null;
|
| 242 |
+
})}
|
| 243 |
+
</div>
|
| 244 |
+
</div>
|
| 245 |
+
|
| 246 |
+
{/* Generos */}
|
| 247 |
+
<div className="space-y-3">
|
| 248 |
+
<label className="text-xs text-purple-400 uppercase font-bold tracking-wider">Géneros</label>
|
| 249 |
+
<div className="flex gap-2">
|
| 250 |
+
<select
|
| 251 |
+
onChange={(e) => {
|
| 252 |
+
const catId = e.target.value;
|
| 253 |
+
if (catId && !selectedCategories.includes(catId)) {
|
| 254 |
+
setSelectedCategories(prev => [...prev, catId]);
|
| 255 |
+
}
|
| 256 |
+
}}
|
| 257 |
+
value=""
|
| 258 |
+
className="w-1/3 bg-[#1a1a1a] border border-gray-600/50 rounded-lg px-3 py-2 text-sm text-white focus:outline-none focus:border-[#bb86fc]"
|
| 259 |
+
>
|
| 260 |
+
<option value="">Seleccionar...</option>
|
| 261 |
+
{categories.filter(c => c.type === 'genre' || !c.type).map(cat => (
|
| 262 |
+
<option key={cat.id} value={cat.id}>{cat.name}</option>
|
| 263 |
+
))}
|
| 264 |
+
</select>
|
| 265 |
+
<input
|
| 266 |
+
type="text"
|
| 267 |
+
placeholder="Nuevo género..."
|
| 268 |
+
value={newGenreName}
|
| 269 |
+
onChange={(e) => setNewGenreName(e.target.value)}
|
| 270 |
+
onKeyPress={(e) => e.key === 'Enter' && handleCreateCategory(newGenreName, 'genre')}
|
| 271 |
+
className="flex-1 bg-[#1a1a1a] border border-gray-600/50 rounded-lg px-4 py-2 text-sm text-white focus:outline-none focus:border-[#bb86fc]"
|
| 272 |
+
/>
|
| 273 |
+
<button
|
| 274 |
+
onClick={() => handleCreateCategory(newGenreName, 'genre')}
|
| 275 |
+
disabled={!newGenreName.trim()}
|
| 276 |
+
className="bg-[#bb86fc]/20 hover:bg-[#bb86fc]/30 text-[#bb86fc] px-3 rounded-lg"
|
| 277 |
+
>
|
| 278 |
+
<Plus className="w-5 h-5" />
|
| 279 |
+
</button>
|
| 280 |
+
</div>
|
| 281 |
+
<div className="flex gap-2 flex-wrap">
|
| 282 |
+
{selectedCategories.map(catId => {
|
| 283 |
+
const category = categories.find(c => c.id === catId);
|
| 284 |
+
if (category && (category.type === 'genre' || !category.type)) {
|
| 285 |
+
return (
|
| 286 |
+
<span key={catId} className="px-3 py-1 bg-purple-500/20 text-purple-300 text-xs rounded-full border border-purple-500/30 flex items-center gap-2">
|
| 287 |
+
{category.name}
|
| 288 |
+
<button onClick={() => handleRemoveCategory(catId)} className="hover:text-white"><X className="w-3 h-3" /></button>
|
| 289 |
+
</span>
|
| 290 |
+
);
|
| 291 |
+
}
|
| 292 |
+
return null;
|
| 293 |
+
})}
|
| 294 |
+
</div>
|
| 295 |
+
</div>
|
| 296 |
+
</div>
|
| 297 |
+
)}
|
| 298 |
+
</div>
|
| 299 |
+
|
| 300 |
+
<div className="p-6 border-t border-gray-800 flex justify-end gap-3 bg-[#1a1a1a]">
|
| 301 |
+
<button
|
| 302 |
+
onClick={onClose}
|
| 303 |
+
className="px-4 py-2 rounded-lg text-sm font-semibold text-gray-300 hover:text-white transition-colors"
|
| 304 |
+
>
|
| 305 |
+
Cancelar
|
| 306 |
+
</button>
|
| 307 |
+
<button
|
| 308 |
+
onClick={handleSave}
|
| 309 |
+
disabled={isSaving || selectedCategories.length === 0}
|
| 310 |
+
className="bg-[#bb86fc] hover:bg-[#9966dd] text-white px-6 py-2 rounded-lg font-semibold text-sm transition-all shadow-lg shadow-[#bb86fc]/20 flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed"
|
| 311 |
+
>
|
| 312 |
+
{isSaving ? (
|
| 313 |
+
<>
|
| 314 |
+
<LoadingSpinner size={16} />
|
| 315 |
+
Guardando...
|
| 316 |
+
</>
|
| 317 |
+
) : (
|
| 318 |
+
<>
|
| 319 |
+
<Save className="w-4 h-4" />
|
| 320 |
+
Aplicar Cambios
|
| 321 |
+
</>
|
| 322 |
+
)}
|
| 323 |
+
</button>
|
| 324 |
+
</div>
|
| 325 |
+
|
| 326 |
+
</div>
|
| 327 |
+
</div>
|
| 328 |
+
);
|
| 329 |
+
}
|
src/components/CategorySelector.tsx
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState, useRef, useEffect, useMemo } from 'react';
|
| 2 |
+
import { toast } from 'sonner';
|
| 3 |
+
import { X, Plus, Trash2, Check } from 'lucide-react';
|
| 4 |
+
import { Category } from '../types/manga';
|
| 5 |
+
|
| 6 |
+
interface CategorySelectorProps {
|
| 7 |
+
label: string;
|
| 8 |
+
type: 'character' | 'series' | 'genre';
|
| 9 |
+
categories: Category[];
|
| 10 |
+
selectedIds: string[];
|
| 11 |
+
onSelect: (id: string) => void;
|
| 12 |
+
onRemove: (id: string) => void;
|
| 13 |
+
onCreate: (name: string) => void;
|
| 14 |
+
onDeleteCategory: (id: string) => void;
|
| 15 |
+
colorClass: string; // e.g., 'text-blue-400', 'bg-blue-500'
|
| 16 |
+
placeholder?: string;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
export function CategorySelector({
|
| 20 |
+
label,
|
| 21 |
+
type,
|
| 22 |
+
categories,
|
| 23 |
+
selectedIds,
|
| 24 |
+
onSelect,
|
| 25 |
+
onRemove,
|
| 26 |
+
onCreate,
|
| 27 |
+
onDeleteCategory,
|
| 28 |
+
colorClass,
|
| 29 |
+
placeholder = 'Añadir...'
|
| 30 |
+
}: CategorySelectorProps) {
|
| 31 |
+
const [inputValue, setInputValue] = useState('');
|
| 32 |
+
const [isOpen, setIsOpen] = useState(false);
|
| 33 |
+
const containerRef = useRef<HTMLDivElement>(null);
|
| 34 |
+
|
| 35 |
+
// Filter categories by type
|
| 36 |
+
const typeCategories = useMemo(() =>
|
| 37 |
+
categories.filter(c => c.type === type || (!c.type && type === 'genre')),
|
| 38 |
+
[categories, type]);
|
| 39 |
+
|
| 40 |
+
// Filter suggestions based on input
|
| 41 |
+
const suggestions = useMemo(() => {
|
| 42 |
+
if (!inputValue.trim()) return typeCategories;
|
| 43 |
+
return typeCategories.filter(c =>
|
| 44 |
+
c.name.toLowerCase().includes(inputValue.toLowerCase())
|
| 45 |
+
);
|
| 46 |
+
}, [typeCategories, inputValue]);
|
| 47 |
+
|
| 48 |
+
// Handle click outside to close dropdown
|
| 49 |
+
useEffect(() => {
|
| 50 |
+
const handleClickOutside = (event: MouseEvent) => {
|
| 51 |
+
if (containerRef.current && !containerRef.current.contains(event.target as Node)) {
|
| 52 |
+
setIsOpen(false);
|
| 53 |
+
}
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
document.addEventListener('mousedown', handleClickOutside);
|
| 57 |
+
return () => document.removeEventListener('mousedown', handleClickOutside);
|
| 58 |
+
}, []);
|
| 59 |
+
|
| 60 |
+
const handleKeyDown = (e: React.KeyboardEvent) => {
|
| 61 |
+
if (e.key === 'Enter') {
|
| 62 |
+
e.preventDefault();
|
| 63 |
+
handleAction();
|
| 64 |
+
}
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
const handleAction = () => {
|
| 68 |
+
if (!inputValue.trim()) return;
|
| 69 |
+
|
| 70 |
+
// Check for exact match (case insensitive)
|
| 71 |
+
const existing = typeCategories.find(
|
| 72 |
+
c => c.name.toLowerCase() === inputValue.trim().toLowerCase()
|
| 73 |
+
);
|
| 74 |
+
|
| 75 |
+
if (existing) {
|
| 76 |
+
if (!selectedIds.includes(existing.id)) {
|
| 77 |
+
onSelect(existing.id);
|
| 78 |
+
}
|
| 79 |
+
} else {
|
| 80 |
+
onCreate(inputValue.trim());
|
| 81 |
+
}
|
| 82 |
+
setInputValue('');
|
| 83 |
+
setIsOpen(false);
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
+
const handleDeleteClick = (e: React.MouseEvent, catId: string) => {
|
| 87 |
+
e.stopPropagation();
|
| 88 |
+
toast('¿Eliminar esta categoría permanentemente?', {
|
| 89 |
+
description: 'Esta acción no se puede deshacer.',
|
| 90 |
+
action: {
|
| 91 |
+
label: 'Eliminar',
|
| 92 |
+
onClick: () => onDeleteCategory(catId),
|
| 93 |
+
},
|
| 94 |
+
cancel: {
|
| 95 |
+
label: 'Cancelar',
|
| 96 |
+
onClick: () => { },
|
| 97 |
+
},
|
| 98 |
+
duration: 5000,
|
| 99 |
+
});
|
| 100 |
+
};
|
| 101 |
+
|
| 102 |
+
// Get color classes
|
| 103 |
+
const getColors = () => {
|
| 104 |
+
if (colorClass.includes('blue')) return { bg: 'bg-blue-500/20', text: 'text-blue-300', border: 'border-blue-500/30' };
|
| 105 |
+
if (colorClass.includes('green')) return { bg: 'bg-green-500/20', text: 'text-green-300', border: 'border-green-500/30' };
|
| 106 |
+
if (colorClass.includes('purple')) return { bg: 'bg-purple-500/20', text: 'text-purple-300', border: 'border-purple-500/30' };
|
| 107 |
+
return { bg: 'bg-gray-500/20', text: 'text-gray-300', border: 'border-gray-500/30' };
|
| 108 |
+
};
|
| 109 |
+
|
| 110 |
+
const colors = getColors();
|
| 111 |
+
|
| 112 |
+
return (
|
| 113 |
+
<div className="space-y-3 mb-6" ref={containerRef}>
|
| 114 |
+
<label className={`text-xs uppercase font-bold tracking-wider ${colorClass}`}>{label}</label>
|
| 115 |
+
|
| 116 |
+
<div className="relative">
|
| 117 |
+
<div className="flex gap-2">
|
| 118 |
+
<div className="relative flex-1">
|
| 119 |
+
<input
|
| 120 |
+
type="text"
|
| 121 |
+
value={inputValue}
|
| 122 |
+
onChange={(e) => {
|
| 123 |
+
setInputValue(e.target.value);
|
| 124 |
+
setIsOpen(true);
|
| 125 |
+
}}
|
| 126 |
+
onFocus={() => setIsOpen(true)}
|
| 127 |
+
onKeyDown={handleKeyDown}
|
| 128 |
+
placeholder={placeholder}
|
| 129 |
+
className="w-full bg-[#1a1a1a] border border-gray-600/50 rounded-lg px-4 py-2 text-sm text-white placeholder-gray-500 focus:outline-none focus:border-[#bb86fc] transition-all"
|
| 130 |
+
/>
|
| 131 |
+
{inputValue && (
|
| 132 |
+
<button
|
| 133 |
+
onClick={() => setInputValue('')}
|
| 134 |
+
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-white"
|
| 135 |
+
>
|
| 136 |
+
<X className="w-3 h-3" />
|
| 137 |
+
</button>
|
| 138 |
+
)}
|
| 139 |
+
</div>
|
| 140 |
+
<button
|
| 141 |
+
onClick={handleAction}
|
| 142 |
+
disabled={!inputValue.trim()}
|
| 143 |
+
className="bg-[#bb86fc]/20 hover:bg-[#bb86fc]/30 text-[#bb86fc] px-3 rounded-lg transition-all"
|
| 144 |
+
>
|
| 145 |
+
<Plus className="w-5 h-5" />
|
| 146 |
+
</button>
|
| 147 |
+
</div>
|
| 148 |
+
|
| 149 |
+
{/* Dropdown Suggestions */}
|
| 150 |
+
{isOpen && (suggestions.length > 0 || inputValue) && (
|
| 151 |
+
<div className="absolute top-full left-0 right-0 mt-1 bg-[#1a1a1a] border border-gray-700/50 rounded-lg shadow-xl z-50 max-h-60 overflow-y-auto w-full custom-scrollbar">
|
| 152 |
+
{suggestions.length > 0 ? (
|
| 153 |
+
suggestions.map(cat => {
|
| 154 |
+
const isSelected = selectedIds.includes(cat.id);
|
| 155 |
+
return (
|
| 156 |
+
<div
|
| 157 |
+
key={cat.id}
|
| 158 |
+
className="flex items-center justify-between px-4 py-2 hover:bg-white/5 cursor-pointer group"
|
| 159 |
+
onClick={() => {
|
| 160 |
+
if (!isSelected) {
|
| 161 |
+
onSelect(cat.id);
|
| 162 |
+
setInputValue('');
|
| 163 |
+
setIsOpen(false);
|
| 164 |
+
}
|
| 165 |
+
}}
|
| 166 |
+
>
|
| 167 |
+
<span className={`text-sm ${isSelected ? 'text-[#bb86fc]' : 'text-gray-300'}`}>
|
| 168 |
+
{cat.name}
|
| 169 |
+
</span>
|
| 170 |
+
<div className="flex items-center gap-2">
|
| 171 |
+
{isSelected && <Check className="w-4 h-4 text-[#bb86fc]" />}
|
| 172 |
+
<button
|
| 173 |
+
onClick={(e) => handleDeleteClick(e, cat.id)}
|
| 174 |
+
className="opacity-0 group-hover:opacity-100 p-1 hover:bg-red-500/20 text-gray-500 hover:text-red-400 rounded transition-all"
|
| 175 |
+
title="Eliminar permanentemente"
|
| 176 |
+
>
|
| 177 |
+
<Trash2 className="w-3.5 h-3.5" />
|
| 178 |
+
</button>
|
| 179 |
+
</div>
|
| 180 |
+
</div>
|
| 181 |
+
);
|
| 182 |
+
})
|
| 183 |
+
) : (
|
| 184 |
+
<div className="px-4 py-3 text-center">
|
| 185 |
+
<p className="text-gray-400 text-xs mb-2">No encontrado.</p>
|
| 186 |
+
<button
|
| 187 |
+
onClick={handleAction}
|
| 188 |
+
className="text-xs text-[#bb86fc] hover:underline font-semibold"
|
| 189 |
+
>
|
| 190 |
+
Crear "{inputValue}"
|
| 191 |
+
</button>
|
| 192 |
+
</div>
|
| 193 |
+
)}
|
| 194 |
+
</div>
|
| 195 |
+
)}
|
| 196 |
+
</div>
|
| 197 |
+
|
| 198 |
+
{/* Selected Tags */}
|
| 199 |
+
<div className="flex gap-2 flex-wrap">
|
| 200 |
+
{selectedIds.map(catId => {
|
| 201 |
+
const category = categories.find(c => c.id === catId);
|
| 202 |
+
// Only show if it matches the current selector type
|
| 203 |
+
if (!category || (category.type !== type && !(type === 'genre' && !category.type))) return null;
|
| 204 |
+
|
| 205 |
+
return (
|
| 206 |
+
<span key={catId} className={`px-3 py-1 ${colors.bg} ${colors.text} text-xs rounded-full border ${colors.border} flex items-center gap-2`}>
|
| 207 |
+
{category.name}
|
| 208 |
+
<button onClick={() => onRemove(catId)} className="hover:text-white"><X className="w-3 h-3" /></button>
|
| 209 |
+
</span>
|
| 210 |
+
);
|
| 211 |
+
})}
|
| 212 |
+
</div>
|
| 213 |
+
</div>
|
| 214 |
+
);
|
| 215 |
+
}
|
src/components/HDComicViewer.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import { Manga } from '../types/manga';
|
|
| 5 |
import { ImageLoader } from './ImageLoader';
|
| 6 |
import { ImageLightbox } from './ImageLightbox';
|
| 7 |
import { GlobalFooter } from './GlobalFooter';
|
| 8 |
-
|
| 9 |
|
| 10 |
interface HDComicViewerProps {
|
| 11 |
manga: Manga;
|
|
@@ -132,13 +132,8 @@ export function HDComicViewer({ manga, onBack }: HDComicViewerProps) {
|
|
| 132 |
${viewMode === 'grid' ? 'grid grid-cols-3 md:grid-cols-5 gap-2 p-2' : ''}
|
| 133 |
`}>
|
| 134 |
{pages.map((pageUrl, index) => {
|
| 135 |
-
//
|
| 136 |
-
|
| 137 |
-
// If we wanted "Original" original without ANY proxy (if possible and CORS allows), we'd use pageUrl directly.
|
| 138 |
-
// But let's stick to getReaderUrl(pageUrl) to ensure we can actually load it (CORS).
|
| 139 |
-
// Wait, current getReaderUrl might resize if we aren't careful?
|
| 140 |
-
// so it should return original size, just proxied. Perfect.
|
| 141 |
-
const src = getReaderUrl(pageUrl, 'original');
|
| 142 |
|
| 143 |
if (viewMode === 'vertical') {
|
| 144 |
// Calculate width style based on zoom
|
|
@@ -146,13 +141,6 @@ export function HDComicViewer({ manga, onBack }: HDComicViewerProps) {
|
|
| 146 |
// We can apply transform or width. Width is safer for layout flow.
|
| 147 |
// Let's use inline style for width percentage relative to "normal" max-width, or just set max-width.
|
| 148 |
// Actually, simpler: Wrapper width.
|
| 149 |
-
const style = {
|
| 150 |
-
width: `${Math.min(100 * zoomLevel, 100)}%`, // Don't overflow viewport width too easily, allow scroll?
|
| 151 |
-
// Actually, if zoom > 1, we want it to overflow.
|
| 152 |
-
// But 'flex-col items-center' centers it.
|
| 153 |
-
maxWidth: zoomLevel > 1 ? 'none' : '64rem', // 5xl equivalent
|
| 154 |
-
minWidth: zoomLevel < 1 ? 'auto' : undefined
|
| 155 |
-
};
|
| 156 |
// Better approach: Control the wrapper width directly.
|
| 157 |
return (
|
| 158 |
<div key={index} className="relative transition-all duration-200" style={{ width: zoomLevel === 1 ? '100%' : `${100 * zoomLevel}%`, maxWidth: zoomLevel > 1 ? 'none' : '80rem' }}>
|
|
@@ -203,7 +191,7 @@ export function HDComicViewer({ manga, onBack }: HDComicViewerProps) {
|
|
| 203 |
|
| 204 |
{lightboxOpen && (
|
| 205 |
<ImageLightbox
|
| 206 |
-
images={pages
|
| 207 |
initialIndex={lightboxIndex}
|
| 208 |
onClose={() => setLightboxOpen(false)}
|
| 209 |
/>
|
|
|
|
| 5 |
import { ImageLoader } from './ImageLoader';
|
| 6 |
import { ImageLightbox } from './ImageLightbox';
|
| 7 |
import { GlobalFooter } from './GlobalFooter';
|
| 8 |
+
|
| 9 |
|
| 10 |
interface HDComicViewerProps {
|
| 11 |
manga: Manga;
|
|
|
|
| 132 |
${viewMode === 'grid' ? 'grid grid-cols-3 md:grid-cols-5 gap-2 p-2' : ''}
|
| 133 |
`}>
|
| 134 |
{pages.map((pageUrl, index) => {
|
| 135 |
+
// Use the direct URL to avoid proxy issues, matching ComicDetail behavior.
|
| 136 |
+
const src = pageUrl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
if (viewMode === 'vertical') {
|
| 139 |
// Calculate width style based on zoom
|
|
|
|
| 141 |
// We can apply transform or width. Width is safer for layout flow.
|
| 142 |
// Let's use inline style for width percentage relative to "normal" max-width, or just set max-width.
|
| 143 |
// Actually, simpler: Wrapper width.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
// Better approach: Control the wrapper width directly.
|
| 145 |
return (
|
| 146 |
<div key={index} className="relative transition-all duration-200" style={{ width: zoomLevel === 1 ? '100%' : `${100 * zoomLevel}%`, maxWidth: zoomLevel > 1 ? 'none' : '80rem' }}>
|
|
|
|
| 191 |
|
| 192 |
{lightboxOpen && (
|
| 193 |
<ImageLightbox
|
| 194 |
+
images={pages} // Use direct URLs
|
| 195 |
initialIndex={lightboxIndex}
|
| 196 |
onClose={() => setLightboxOpen(false)}
|
| 197 |
/>
|
src/components/MangaCard.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import { useState } from 'react';
|
| 2 |
-
import { BookOpen, Edit2, Trash2 } from 'lucide-react';
|
| 3 |
import { Manga } from '../types/manga';
|
| 4 |
import { ImageLoader } from './ImageLoader';
|
| 5 |
import { incrementMangaViews } from '../services/manga';
|
|
@@ -16,9 +16,12 @@ interface MangaCardProps {
|
|
| 16 |
onSelect?: (id: string) => void;
|
| 17 |
onEdit?: (manga: Manga) => void;
|
| 18 |
onDelete?: (id: string) => void;
|
|
|
|
|
|
|
|
|
|
| 19 |
}
|
| 20 |
|
| 21 |
-
export function MangaCard({ id, title, author, pageCount, thumbnail, manga, onSelect, onEdit, onDelete }: MangaCardProps) {
|
| 22 |
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
| 23 |
const thumbnailUrl = thumbnail ? getThumbnailUrl(thumbnail) : undefined;
|
| 24 |
|
|
@@ -44,10 +47,14 @@ export function MangaCard({ id, title, author, pageCount, thumbnail, manga, onSe
|
|
| 44 |
<div className="group cursor-pointer flex flex-col w-full max-w-xs">
|
| 45 |
<div
|
| 46 |
onClick={() => {
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
}}
|
| 50 |
-
className=
|
| 51 |
>
|
| 52 |
{thumbnailUrl ? (
|
| 53 |
<>
|
|
@@ -71,26 +78,34 @@ export function MangaCard({ id, title, author, pageCount, thumbnail, manga, onSe
|
|
| 71 |
{pageCount} paginas
|
| 72 |
</div>
|
| 73 |
|
| 74 |
-
|
| 75 |
-
{
|
| 76 |
-
<
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
{showDeleteConfirm && (
|
| 96 |
<div className="absolute inset-0 bg-black/80 backdrop-blur-sm flex flex-col items-center justify-center gap-3 rounded-lg z-20 animate-in fade-in duration-200">
|
|
|
|
| 1 |
import { useState } from 'react';
|
| 2 |
+
import { BookOpen, Edit2, Trash2, Check } from 'lucide-react';
|
| 3 |
import { Manga } from '../types/manga';
|
| 4 |
import { ImageLoader } from './ImageLoader';
|
| 5 |
import { incrementMangaViews } from '../services/manga';
|
|
|
|
| 16 |
onSelect?: (id: string) => void;
|
| 17 |
onEdit?: (manga: Manga) => void;
|
| 18 |
onDelete?: (id: string) => void;
|
| 19 |
+
isCategoryPlusEnabled?: boolean;
|
| 20 |
+
isSelected?: boolean;
|
| 21 |
+
onToggleSelect?: () => void;
|
| 22 |
}
|
| 23 |
|
| 24 |
+
export function MangaCard({ id, title, author, pageCount, thumbnail, manga, onSelect, onEdit, onDelete, isCategoryPlusEnabled, isSelected, onToggleSelect }: MangaCardProps) {
|
| 25 |
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
| 26 |
const thumbnailUrl = thumbnail ? getThumbnailUrl(thumbnail) : undefined;
|
| 27 |
|
|
|
|
| 47 |
<div className="group cursor-pointer flex flex-col w-full max-w-xs">
|
| 48 |
<div
|
| 49 |
onClick={() => {
|
| 50 |
+
if (isCategoryPlusEnabled && onToggleSelect) {
|
| 51 |
+
onToggleSelect();
|
| 52 |
+
} else {
|
| 53 |
+
incrementMangaViews(id);
|
| 54 |
+
onSelect?.(id);
|
| 55 |
+
}
|
| 56 |
}}
|
| 57 |
+
className={`relative bg-black rounded-lg shadow-lg overflow-hidden transition-transform duration-300 hover:scale-[1.02] aspect-[2/3] ${isSelected ? 'ring-4 ring-[#bb86fc]' : ''}`}
|
| 58 |
>
|
| 59 |
{thumbnailUrl ? (
|
| 60 |
<>
|
|
|
|
| 78 |
{pageCount} paginas
|
| 79 |
</div>
|
| 80 |
|
| 81 |
+
{isCategoryPlusEnabled && (
|
| 82 |
+
<div className={`absolute top-2 left-2 w-6 h-6 rounded-md border-2 flex items-center justify-center transition-all ${isSelected ? 'bg-[#bb86fc] border-[#bb86fc]' : 'bg-black/50 border-white/50 hover:border-white'}`}>
|
| 83 |
+
{isSelected && <Check className="w-4 h-4 text-white" />}
|
| 84 |
+
</div>
|
| 85 |
+
)}
|
| 86 |
+
|
| 87 |
+
{!isCategoryPlusEnabled && (
|
| 88 |
+
<div className="absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity duration-300 flex gap-1">
|
| 89 |
+
{manga && onEdit && (
|
| 90 |
+
<button
|
| 91 |
+
onClick={handleEditClick}
|
| 92 |
+
className="bg-black/60 hover:bg-purple-600 text-white p-1.5 rounded-full transition-colors backdrop-blur-sm"
|
| 93 |
+
title="Editar manga"
|
| 94 |
+
>
|
| 95 |
+
<Edit2 className="w-3 h-3" />
|
| 96 |
+
</button>
|
| 97 |
+
)}
|
| 98 |
+
{onDelete && (
|
| 99 |
+
<button
|
| 100 |
+
onClick={handleDeleteClick}
|
| 101 |
+
className="bg-black/60 hover:bg-red-600 text-white p-1.5 rounded-full transition-colors backdrop-blur-sm"
|
| 102 |
+
title="Eliminar manga"
|
| 103 |
+
>
|
| 104 |
+
<Trash2 className="w-3 h-3" />
|
| 105 |
+
</button>
|
| 106 |
+
)}
|
| 107 |
+
</div>
|
| 108 |
+
)}
|
| 109 |
|
| 110 |
{showDeleteConfirm && (
|
| 111 |
<div className="absolute inset-0 bg-black/80 backdrop-blur-sm flex flex-col items-center justify-center gap-3 rounded-lg z-20 animate-in fade-in duration-200">
|
src/components/NewMangaModal.tsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
| 1 |
-
import { BookOpen, Plus, X, Image as ImageIcon, Trash2, GripVertical, Settings2
|
| 2 |
import { useState, useEffect } from 'react';
|
| 3 |
import { processImage, OptimizedImage } from '../utils/imageOptimization';
|
| 4 |
import { uploadToImgBB, uploadMultipleToImgBB } from '../services/imgbb';
|
| 5 |
-
import { createManga, updateManga, getAllCategories, createCategory, createChapter } from '../services/manga';
|
| 6 |
import { Category, Manga } from '../types/manga';
|
|
|
|
| 7 |
import { LoadingSpinner } from './LoadingSpinner';
|
| 8 |
import { ImageLoader } from './ImageLoader';
|
| 9 |
import { db } from '../lib/firebase';
|
|
@@ -30,7 +31,7 @@ export function NewMangaModal({ isOpen, onClose, onMangaCreated, editingManga, o
|
|
| 30 |
const [isProcessing, setIsProcessing] = useState(false);
|
| 31 |
const [previewUrl, setPreviewUrl] = useState<string | null>(null);
|
| 32 |
const [categories, setCategories] = useState<Category[]>([]);
|
| 33 |
-
|
| 34 |
const [isCreating, setIsCreating] = useState(false);
|
| 35 |
const [chapterPages, setChapterPages] = useState<OptimizedImage[]>([]);
|
| 36 |
const [isProcessingPages, setIsProcessingPages] = useState(false);
|
|
@@ -41,7 +42,7 @@ export function NewMangaModal({ isOpen, onClose, onMangaCreated, editingManga, o
|
|
| 41 |
const [totalImagesToUpload, setTotalImagesToUpload] = useState(0);
|
| 42 |
const [processingProgress, setProcessingProgress] = useState(0);
|
| 43 |
const [currentProcessingImage, setCurrentProcessingImage] = useState(0);
|
| 44 |
-
|
| 45 |
|
| 46 |
const [showCoverSelector, setShowCoverSelector] = useState(false);
|
| 47 |
const [selectedCoverPageIndex, setSelectedCoverPageIndex] = useState<number | null>(null);
|
|
@@ -98,15 +99,9 @@ export function NewMangaModal({ isOpen, onClose, onMangaCreated, editingManga, o
|
|
| 98 |
setFormData(prev => ({ ...prev, [name]: value }));
|
| 99 |
};
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
setFormData(prev => ({
|
| 105 |
-
...prev,
|
| 106 |
-
selectedCategories: [...prev.selectedCategories, categoryId],
|
| 107 |
-
}));
|
| 108 |
-
}
|
| 109 |
-
};
|
| 110 |
|
| 111 |
const handleRemoveCategory = (categoryId: string) => {
|
| 112 |
setFormData(prev => ({
|
|
@@ -115,109 +110,48 @@ export function NewMangaModal({ isOpen, onClose, onMangaCreated, editingManga, o
|
|
| 115 |
}));
|
| 116 |
};
|
| 117 |
|
| 118 |
-
const
|
| 119 |
-
if (!
|
| 120 |
-
alert('Escribe un título primero.');
|
| 121 |
-
return;
|
| 122 |
-
}
|
| 123 |
|
| 124 |
-
setIsGeneratingCategories(true);
|
| 125 |
try {
|
| 126 |
-
|
| 127 |
-
const
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
const titleParts = titleText.split(delimiters); // Splitting by delimiters
|
| 138 |
-
chunks = [...chunks, ...titleParts];
|
| 139 |
-
|
| 140 |
-
// Process author (usually just one name, but maybe comma separated)
|
| 141 |
-
if (authorText) {
|
| 142 |
-
const authorParts = authorText.split(/[,&]/); // Split by comma or &
|
| 143 |
-
chunks = [...chunks, ...authorParts];
|
| 144 |
-
}
|
| 145 |
-
|
| 146 |
-
// Clean up chunks
|
| 147 |
-
const potentialCategories = chunks
|
| 148 |
-
.map(s => s.trim())
|
| 149 |
-
.filter(s => s.length > 1) // Filter out single chars like "-" if left over, or empty
|
| 150 |
-
.filter(s => !['-', '_', '.', ','].includes(s)); // Strict filter for punctuation-only
|
| 151 |
-
|
| 152 |
-
const categoriesToAdd: string[] = [...formData.selectedCategories];
|
| 153 |
-
const newCategoriesList = [...categories];
|
| 154 |
-
|
| 155 |
-
for (const candidate of potentialCategories) {
|
| 156 |
-
const existingCategory = newCategoriesList.find(
|
| 157 |
-
cat => cat.name.toLowerCase() === candidate.toLowerCase()
|
| 158 |
-
);
|
| 159 |
-
|
| 160 |
-
if (existingCategory) {
|
| 161 |
-
if (!categoriesToAdd.includes(existingCategory.id)) {
|
| 162 |
-
categoriesToAdd.push(existingCategory.id);
|
| 163 |
-
}
|
| 164 |
-
} else {
|
| 165 |
-
// Create new category
|
| 166 |
-
const newCategory = await createCategory(candidate);
|
| 167 |
-
categoriesToAdd.push(newCategory.id);
|
| 168 |
-
newCategoriesList.push(newCategory); // Add to local list to avoid re-creating in loop if duplicate words/phrases
|
| 169 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
}
|
| 171 |
-
|
| 172 |
-
setCategories(newCategoriesList);
|
| 173 |
-
setFormData(prev => ({
|
| 174 |
-
...prev,
|
| 175 |
-
selectedCategories: categoriesToAdd
|
| 176 |
-
}));
|
| 177 |
-
|
| 178 |
} catch (error) {
|
| 179 |
-
console.error(
|
| 180 |
-
alert(
|
| 181 |
-
} finally {
|
| 182 |
-
setIsGeneratingCategories(false);
|
| 183 |
}
|
| 184 |
};
|
| 185 |
|
| 186 |
-
const
|
| 187 |
-
if (!newCategoryName.trim()) return;
|
| 188 |
-
|
| 189 |
try {
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
for (const word of words) {
|
| 195 |
-
const existingCategory = categories.find(
|
| 196 |
-
cat => cat.name.toLowerCase() === word.toLowerCase()
|
| 197 |
-
);
|
| 198 |
-
|
| 199 |
-
if (existingCategory) {
|
| 200 |
-
if (!formData.selectedCategories.includes(existingCategory.id)) {
|
| 201 |
-
createdCategories.push(existingCategory);
|
| 202 |
-
}
|
| 203 |
-
} else {
|
| 204 |
-
const newCategory = await createCategory(word);
|
| 205 |
-
createdCategories.push(newCategory);
|
| 206 |
-
setCategories(prev => [...prev, newCategory]);
|
| 207 |
-
}
|
| 208 |
-
}
|
| 209 |
-
|
| 210 |
setFormData(prev => ({
|
| 211 |
...prev,
|
| 212 |
-
selectedCategories:
|
| 213 |
-
...prev.selectedCategories,
|
| 214 |
-
...createdCategories.map(cat => cat.id),
|
| 215 |
-
],
|
| 216 |
}));
|
| 217 |
-
setNewCategoryName('');
|
| 218 |
} catch (error) {
|
| 219 |
-
console.error('Error
|
| 220 |
-
alert('Error al
|
| 221 |
}
|
| 222 |
};
|
| 223 |
|
|
@@ -603,7 +537,6 @@ export function NewMangaModal({ isOpen, onClose, onMangaCreated, editingManga, o
|
|
| 603 |
setOptimizedImage(null);
|
| 604 |
setCoverFromExistingPage(null);
|
| 605 |
setPreviewUrl(null);
|
| 606 |
-
setNewCategoryName('');
|
| 607 |
setChapterPages([]);
|
| 608 |
setUploadProgress(0);
|
| 609 |
setUploadingImages(false);
|
|
@@ -693,75 +626,62 @@ export function NewMangaModal({ isOpen, onClose, onMangaCreated, editingManga, o
|
|
| 693 |
<div className="bg-gradient-to-br from-[#242424] to-[#1a1a1a] rounded-xl p-6 border border-gray-700/40 shadow-lg hover:border-gray-700/60 transition-all">
|
| 694 |
<div className="flex items-center gap-3 mb-5">
|
| 695 |
<div className="w-1 h-5 bg-gradient-to-b from-[#bb86fc] to-[#7744cc] rounded-full"></div>
|
| 696 |
-
<h3 className="text-sm font-semibold text-white tracking-wide uppercase">
|
| 697 |
-
<span className="text-xs text-gray-500 ml-auto">Opcional</span>
|
| 698 |
</div>
|
| 699 |
-
<div className="space-y-3">
|
| 700 |
-
<select
|
| 701 |
-
onChange={handleCategorySelect}
|
| 702 |
-
value=""
|
| 703 |
-
className="w-full bg-[#1a1a1a] border border-gray-600/50 rounded-lg px-4 py-3 text-sm text-white focus:outline-none focus:border-[#bb86fc] focus:ring-2 focus:ring-[#bb86fc]/30 transition-all shadow-md hover:border-gray-600/70"
|
| 704 |
-
>
|
| 705 |
-
<option value="">Selecciona una categoría...</option>
|
| 706 |
-
{categories.map(cat => (
|
| 707 |
-
<option key={cat.id} value={cat.id}>
|
| 708 |
-
{cat.name}
|
| 709 |
-
</option>
|
| 710 |
-
))}
|
| 711 |
-
</select>
|
| 712 |
-
|
| 713 |
-
{formData.selectedCategories.length > 0 && (
|
| 714 |
-
<div className="flex gap-2 flex-wrap pt-2">
|
| 715 |
-
{formData.selectedCategories.map(catId => {
|
| 716 |
-
const category = categories.find(c => c.id === catId);
|
| 717 |
-
return category ? (
|
| 718 |
-
<span
|
| 719 |
-
key={catId}
|
| 720 |
-
className="px-3 py-1.5 bg-gradient-to-r from-[#bb86fc]/25 to-[#9966dd]/25 text-[#bb86fc] text-xs font-medium rounded-full border border-[#bb86fc]/50 flex items-center gap-2 hover:border-[#bb86fc] transition-all"
|
| 721 |
-
>
|
| 722 |
-
{category.name}
|
| 723 |
-
<button
|
| 724 |
-
onClick={() => handleRemoveCategory(catId)}
|
| 725 |
-
className="hover:text-white transition-colors ml-1"
|
| 726 |
-
>
|
| 727 |
-
<X className="w-3 h-3" />
|
| 728 |
-
</button>
|
| 729 |
-
</span>
|
| 730 |
-
) : null;
|
| 731 |
-
})}
|
| 732 |
-
</div>
|
| 733 |
-
)}
|
| 734 |
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 765 |
</div>
|
| 766 |
|
| 767 |
<div className="bg-gradient-to-br from-[#242424] to-[#1a1a1a] rounded-xl p-6 border border-gray-700/40 shadow-lg hover:border-gray-700/60 transition-all">
|
|
|
|
| 1 |
+
import { BookOpen, Plus, X, Image as ImageIcon, Trash2, GripVertical, Settings2 } from 'lucide-react';
|
| 2 |
import { useState, useEffect } from 'react';
|
| 3 |
import { processImage, OptimizedImage } from '../utils/imageOptimization';
|
| 4 |
import { uploadToImgBB, uploadMultipleToImgBB } from '../services/imgbb';
|
| 5 |
+
import { createManga, updateManga, getAllCategories, createCategory, createChapter, deleteCategory } from '../services/manga';
|
| 6 |
import { Category, Manga } from '../types/manga';
|
| 7 |
+
import { CategorySelector } from './CategorySelector';
|
| 8 |
import { LoadingSpinner } from './LoadingSpinner';
|
| 9 |
import { ImageLoader } from './ImageLoader';
|
| 10 |
import { db } from '../lib/firebase';
|
|
|
|
| 31 |
const [isProcessing, setIsProcessing] = useState(false);
|
| 32 |
const [previewUrl, setPreviewUrl] = useState<string | null>(null);
|
| 33 |
const [categories, setCategories] = useState<Category[]>([]);
|
| 34 |
+
// Removed unused state variables for individual inputs
|
| 35 |
const [isCreating, setIsCreating] = useState(false);
|
| 36 |
const [chapterPages, setChapterPages] = useState<OptimizedImage[]>([]);
|
| 37 |
const [isProcessingPages, setIsProcessingPages] = useState(false);
|
|
|
|
| 42 |
const [totalImagesToUpload, setTotalImagesToUpload] = useState(0);
|
| 43 |
const [processingProgress, setProcessingProgress] = useState(0);
|
| 44 |
const [currentProcessingImage, setCurrentProcessingImage] = useState(0);
|
| 45 |
+
|
| 46 |
|
| 47 |
const [showCoverSelector, setShowCoverSelector] = useState(false);
|
| 48 |
const [selectedCoverPageIndex, setSelectedCoverPageIndex] = useState<number | null>(null);
|
|
|
|
| 99 |
setFormData(prev => ({ ...prev, [name]: value }));
|
| 100 |
};
|
| 101 |
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
const handleRemoveCategory = (categoryId: string) => {
|
| 107 |
setFormData(prev => ({
|
|
|
|
| 110 |
}));
|
| 111 |
};
|
| 112 |
|
| 113 |
+
const handleCreateCategory = async (name: string, type: 'character' | 'series' | 'genre') => {
|
| 114 |
+
if (!name.trim()) return;
|
|
|
|
|
|
|
|
|
|
| 115 |
|
|
|
|
| 116 |
try {
|
| 117 |
+
// Check if it already exists
|
| 118 |
+
const existingCategory = categories.find(
|
| 119 |
+
cat => cat.name.toLowerCase() === name.trim().toLowerCase() && cat.type === type
|
| 120 |
+
);
|
| 121 |
+
|
| 122 |
+
if (existingCategory) {
|
| 123 |
+
if (!formData.selectedCategories.includes(existingCategory.id)) {
|
| 124 |
+
setFormData(prev => ({
|
| 125 |
+
...prev,
|
| 126 |
+
selectedCategories: [...prev.selectedCategories, existingCategory.id]
|
| 127 |
+
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
}
|
| 129 |
+
} else {
|
| 130 |
+
const newCategory = await createCategory(name.trim(), type);
|
| 131 |
+
setCategories(prev => [...prev, newCategory]);
|
| 132 |
+
setFormData(prev => ({
|
| 133 |
+
...prev,
|
| 134 |
+
selectedCategories: [...prev.selectedCategories, newCategory.id]
|
| 135 |
+
}));
|
| 136 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
} catch (error) {
|
| 138 |
+
console.error('Error creating category:', error);
|
| 139 |
+
alert('Error al crear la categoría');
|
|
|
|
|
|
|
| 140 |
}
|
| 141 |
};
|
| 142 |
|
| 143 |
+
const handleDeleteCategory = async (id: string) => {
|
|
|
|
|
|
|
| 144 |
try {
|
| 145 |
+
await deleteCategory(id);
|
| 146 |
+
setCategories(prev => prev.filter(c => c.id !== id));
|
| 147 |
+
// Also remove from selection if selected
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
setFormData(prev => ({
|
| 149 |
...prev,
|
| 150 |
+
selectedCategories: prev.selectedCategories.filter(catId => catId !== id)
|
|
|
|
|
|
|
|
|
|
| 151 |
}));
|
|
|
|
| 152 |
} catch (error) {
|
| 153 |
+
console.error('Error deleting category:', error);
|
| 154 |
+
alert('Error al eliminar la categoría');
|
| 155 |
}
|
| 156 |
};
|
| 157 |
|
|
|
|
| 537 |
setOptimizedImage(null);
|
| 538 |
setCoverFromExistingPage(null);
|
| 539 |
setPreviewUrl(null);
|
|
|
|
| 540 |
setChapterPages([]);
|
| 541 |
setUploadProgress(0);
|
| 542 |
setUploadingImages(false);
|
|
|
|
| 626 |
<div className="bg-gradient-to-br from-[#242424] to-[#1a1a1a] rounded-xl p-6 border border-gray-700/40 shadow-lg hover:border-gray-700/60 transition-all">
|
| 627 |
<div className="flex items-center gap-3 mb-5">
|
| 628 |
<div className="w-1 h-5 bg-gradient-to-b from-[#bb86fc] to-[#7744cc] rounded-full"></div>
|
| 629 |
+
<h3 className="text-sm font-semibold text-white tracking-wide uppercase">Clasificación</h3>
|
|
|
|
| 630 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 631 |
|
| 632 |
+
{/* Personajes */}
|
| 633 |
+
<CategorySelector
|
| 634 |
+
label="Personajes"
|
| 635 |
+
type="character"
|
| 636 |
+
categories={categories}
|
| 637 |
+
selectedIds={formData.selectedCategories}
|
| 638 |
+
onSelect={(id) => {
|
| 639 |
+
if (!formData.selectedCategories.includes(id)) {
|
| 640 |
+
setFormData(prev => ({ ...prev, selectedCategories: [...prev.selectedCategories, id] }));
|
| 641 |
+
}
|
| 642 |
+
}}
|
| 643 |
+
onRemove={handleRemoveCategory}
|
| 644 |
+
onCreate={(name) => handleCreateCategory(name, 'character')}
|
| 645 |
+
onDeleteCategory={handleDeleteCategory}
|
| 646 |
+
colorClass="text-blue-400"
|
| 647 |
+
placeholder="Añadir personaje..."
|
| 648 |
+
/>
|
| 649 |
+
|
| 650 |
+
{/* Series */}
|
| 651 |
+
<CategorySelector
|
| 652 |
+
label="Series"
|
| 653 |
+
type="series"
|
| 654 |
+
categories={categories}
|
| 655 |
+
selectedIds={formData.selectedCategories}
|
| 656 |
+
onSelect={(id) => {
|
| 657 |
+
if (!formData.selectedCategories.includes(id)) {
|
| 658 |
+
setFormData(prev => ({ ...prev, selectedCategories: [...prev.selectedCategories, id] }));
|
| 659 |
+
}
|
| 660 |
+
}}
|
| 661 |
+
onRemove={handleRemoveCategory}
|
| 662 |
+
onCreate={(name) => handleCreateCategory(name, 'series')}
|
| 663 |
+
onDeleteCategory={handleDeleteCategory}
|
| 664 |
+
colorClass="text-green-400"
|
| 665 |
+
placeholder="Añadir serie..."
|
| 666 |
+
/>
|
| 667 |
+
|
| 668 |
+
{/* Géneros */}
|
| 669 |
+
<CategorySelector
|
| 670 |
+
label="Géneros"
|
| 671 |
+
type="genre"
|
| 672 |
+
categories={categories}
|
| 673 |
+
selectedIds={formData.selectedCategories}
|
| 674 |
+
onSelect={(id) => {
|
| 675 |
+
if (!formData.selectedCategories.includes(id)) {
|
| 676 |
+
setFormData(prev => ({ ...prev, selectedCategories: [...prev.selectedCategories, id] }));
|
| 677 |
+
}
|
| 678 |
+
}}
|
| 679 |
+
onRemove={handleRemoveCategory}
|
| 680 |
+
onCreate={(name) => handleCreateCategory(name, 'genre')}
|
| 681 |
+
onDeleteCategory={handleDeleteCategory}
|
| 682 |
+
colorClass="text-purple-400"
|
| 683 |
+
placeholder="Añadir género..."
|
| 684 |
+
/>
|
| 685 |
</div>
|
| 686 |
|
| 687 |
<div className="bg-gradient-to-br from-[#242424] to-[#1a1a1a] rounded-xl p-6 border border-gray-700/40 shadow-lg hover:border-gray-700/60 transition-all">
|
src/components/SearchResults.tsx
CHANGED
|
@@ -22,6 +22,9 @@ interface SearchResultsProps {
|
|
| 22 |
onEditManga?: (manga: Manga) => void;
|
| 23 |
onDeleteManga?: (id: string) => void;
|
| 24 |
isLoading?: boolean;
|
|
|
|
|
|
|
|
|
|
| 25 |
}
|
| 26 |
|
| 27 |
const ITEMS_PER_PAGE = 24;
|
|
@@ -34,6 +37,9 @@ export function SearchResults({
|
|
| 34 |
onEditManga,
|
| 35 |
onDeleteManga,
|
| 36 |
isLoading = false,
|
|
|
|
|
|
|
|
|
|
| 37 |
}: SearchResultsProps) {
|
| 38 |
const [currentPage, setCurrentPage] = useState(() => {
|
| 39 |
const params = new URLSearchParams(window.location.search);
|
|
@@ -219,6 +225,9 @@ export function SearchResults({
|
|
| 219 |
onSelect={() => onSelectComic(item.id)}
|
| 220 |
onEdit={onEditManga}
|
| 221 |
onDelete={onDeleteManga ? () => onDeleteManga(item.id) : undefined}
|
|
|
|
|
|
|
|
|
|
| 222 |
/>
|
| 223 |
</div>
|
| 224 |
))}
|
|
|
|
| 22 |
onEditManga?: (manga: Manga) => void;
|
| 23 |
onDeleteManga?: (id: string) => void;
|
| 24 |
isLoading?: boolean;
|
| 25 |
+
isCategoryPlusEnabled?: boolean;
|
| 26 |
+
selectedMangaIds?: string[];
|
| 27 |
+
onToggleSelectManga?: (id: string) => void;
|
| 28 |
}
|
| 29 |
|
| 30 |
const ITEMS_PER_PAGE = 24;
|
|
|
|
| 37 |
onEditManga,
|
| 38 |
onDeleteManga,
|
| 39 |
isLoading = false,
|
| 40 |
+
isCategoryPlusEnabled = false,
|
| 41 |
+
selectedMangaIds = [],
|
| 42 |
+
onToggleSelectManga,
|
| 43 |
}: SearchResultsProps) {
|
| 44 |
const [currentPage, setCurrentPage] = useState(() => {
|
| 45 |
const params = new URLSearchParams(window.location.search);
|
|
|
|
| 225 |
onSelect={() => onSelectComic(item.id)}
|
| 226 |
onEdit={onEditManga}
|
| 227 |
onDelete={onDeleteManga ? () => onDeleteManga(item.id) : undefined}
|
| 228 |
+
isCategoryPlusEnabled={isCategoryPlusEnabled}
|
| 229 |
+
isSelected={selectedMangaIds.includes(item.id)}
|
| 230 |
+
onToggleSelect={onToggleSelectManga ? () => onToggleSelectManga(item.id) : undefined}
|
| 231 |
/>
|
| 232 |
</div>
|
| 233 |
))}
|
src/components/SettingsModal.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import { X, Key, Trash2, Save, Settings, Shield, Lock, Unlock, Megaphone, Clock, LogOut, UserPlus, UserMinus, Eye } from 'lucide-react';
|
| 2 |
import { useState, useEffect } from 'react';
|
| 3 |
import { getUserApiKey, saveUserApiKey, deleteUserApiKey } from '../utils/apiKeyManager';
|
| 4 |
import { saveAnnouncement } from '../services/announcement';
|
|
@@ -12,12 +12,14 @@ interface SettingsModalProps {
|
|
| 12 |
onClose: () => void;
|
| 13 |
isAdmin: boolean;
|
| 14 |
onAdminChange: (isAdmin: boolean) => void;
|
|
|
|
|
|
|
| 15 |
}
|
| 16 |
|
| 17 |
// SHA-256 Hash for 'Loyola069012*'
|
| 18 |
|
| 19 |
|
| 20 |
-
export function SettingsModal({ isOpen, onClose, isAdmin, onAdminChange }: SettingsModalProps) {
|
| 21 |
// API Key State
|
| 22 |
const [apiKey, setApiKey] = useState('');
|
| 23 |
const [hasUserApiKey, setHasUserApiKey] = useState(false);
|
|
@@ -429,6 +431,30 @@ export function SettingsModal({ isOpen, onClose, isAdmin, onAdminChange }: Setti
|
|
| 429 |
)}
|
| 430 |
</section>
|
| 431 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
{isAdmin && (
|
| 433 |
<section className="space-y-4 pt-4 border-t border-gray-800">
|
| 434 |
<div className="flex items-center gap-3 mb-2">
|
|
|
|
| 1 |
+
import { X, Key, Trash2, Save, Settings, Shield, Lock, Unlock, Megaphone, Clock, LogOut, UserPlus, UserMinus, Eye, Layers } from 'lucide-react';
|
| 2 |
import { useState, useEffect } from 'react';
|
| 3 |
import { getUserApiKey, saveUserApiKey, deleteUserApiKey } from '../utils/apiKeyManager';
|
| 4 |
import { saveAnnouncement } from '../services/announcement';
|
|
|
|
| 12 |
onClose: () => void;
|
| 13 |
isAdmin: boolean;
|
| 14 |
onAdminChange: (isAdmin: boolean) => void;
|
| 15 |
+
isCategoryPlusEnabled: boolean;
|
| 16 |
+
onCategoryPlusChange: (enabled: boolean) => void;
|
| 17 |
}
|
| 18 |
|
| 19 |
// SHA-256 Hash for 'Loyola069012*'
|
| 20 |
|
| 21 |
|
| 22 |
+
export function SettingsModal({ isOpen, onClose, isAdmin, onAdminChange, isCategoryPlusEnabled, onCategoryPlusChange }: SettingsModalProps) {
|
| 23 |
// API Key State
|
| 24 |
const [apiKey, setApiKey] = useState('');
|
| 25 |
const [hasUserApiKey, setHasUserApiKey] = useState(false);
|
|
|
|
| 431 |
)}
|
| 432 |
</section>
|
| 433 |
|
| 434 |
+
{/* Category Plus Toggle */}
|
| 435 |
+
<section className="space-y-4 pt-4 border-t border-gray-800">
|
| 436 |
+
<div className="flex items-center justify-between">
|
| 437 |
+
<div className="flex items-center gap-3">
|
| 438 |
+
<div className={`p-2 rounded-lg ${isCategoryPlusEnabled ? 'bg-purple-500/10 text-purple-400' : 'bg-gray-800 text-gray-400'}`}>
|
| 439 |
+
<Layers className="w-5 h-5" />
|
| 440 |
+
</div>
|
| 441 |
+
<div>
|
| 442 |
+
<h3 className="text-sm font-semibold text-white">Categorías Plus</h3>
|
| 443 |
+
<p className="text-xs text-gray-400">Habilitar selección múltiple y edición masiva</p>
|
| 444 |
+
</div>
|
| 445 |
+
</div>
|
| 446 |
+
<label className="relative inline-flex items-center cursor-pointer">
|
| 447 |
+
<input
|
| 448 |
+
type="checkbox"
|
| 449 |
+
className="sr-only peer"
|
| 450 |
+
checked={isCategoryPlusEnabled}
|
| 451 |
+
onChange={(e) => onCategoryPlusChange(e.target.checked)}
|
| 452 |
+
/>
|
| 453 |
+
<div className="w-11 h-6 bg-gray-700 peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-purple-300 dark:peer-focus:ring-purple-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-[#bb86fc]"></div>
|
| 454 |
+
</label>
|
| 455 |
+
</div>
|
| 456 |
+
</section>
|
| 457 |
+
|
| 458 |
{isAdmin && (
|
| 459 |
<section className="space-y-4 pt-4 border-t border-gray-800">
|
| 460 |
<div className="flex items-center gap-3 mb-2">
|
src/services/manga.ts
CHANGED
|
@@ -380,8 +380,8 @@ export async function getAllCategories(): Promise<Category[]> {
|
|
| 380 |
} as Category));
|
| 381 |
}
|
| 382 |
|
| 383 |
-
export async function createCategory(name: string): Promise<Category> {
|
| 384 |
-
const docRef = await addDoc(collection(db, 'categories'), { name });
|
| 385 |
const docSnap = await getDoc(docRef);
|
| 386 |
|
| 387 |
return {
|
|
@@ -408,6 +408,28 @@ export async function deleteAllCategories(): Promise<void> {
|
|
| 408 |
await Promise.all(updatePromises);
|
| 409 |
}
|
| 410 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 411 |
export async function regenerateAllMangaCategories(): Promise<{ updated: number, errors: number }> {
|
| 412 |
try {
|
| 413 |
const mangas = await getAllMangas();
|
|
|
|
| 380 |
} as Category));
|
| 381 |
}
|
| 382 |
|
| 383 |
+
export async function createCategory(name: string, type: 'character' | 'series' | 'genre' | 'other' = 'genre'): Promise<Category> {
|
| 384 |
+
const docRef = await addDoc(collection(db, 'categories'), { name, type });
|
| 385 |
const docSnap = await getDoc(docRef);
|
| 386 |
|
| 387 |
return {
|
|
|
|
| 408 |
await Promise.all(updatePromises);
|
| 409 |
}
|
| 410 |
|
| 411 |
+
export async function deleteCategory(categoryId: string): Promise<void> {
|
| 412 |
+
const categoryRef = doc(db, 'categories', categoryId);
|
| 413 |
+
await deleteDoc(categoryRef);
|
| 414 |
+
|
| 415 |
+
// Remove from all mangas that have this category
|
| 416 |
+
// Since we can't easily query array-contains for multiple mangas and update in one go without fetching,
|
| 417 |
+
// we'll fetch all mangas (or use a cloud function in a real app, but here client-side):
|
| 418 |
+
// Optimization: Query only mangas that MIGHT have it.
|
| 419 |
+
// actually 'array-contains' is supported.
|
| 420 |
+
const q = query(collection(db, 'mangas'), where('categories', 'array-contains', categoryId));
|
| 421 |
+
const querySnapshot = await getDocs(q);
|
| 422 |
+
|
| 423 |
+
const updatePromises = querySnapshot.docs.map(docSnap => {
|
| 424 |
+
const mangaData = docSnap.data();
|
| 425 |
+
const currentCategories = mangaData.categories as string[] || [];
|
| 426 |
+
const newCategories = currentCategories.filter(id => id !== categoryId);
|
| 427 |
+
return updateDoc(doc(db, 'mangas', docSnap.id), { categories: newCategories });
|
| 428 |
+
});
|
| 429 |
+
|
| 430 |
+
await Promise.all(updatePromises);
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
export async function regenerateAllMangaCategories(): Promise<{ updated: number, errors: number }> {
|
| 434 |
try {
|
| 435 |
const mangas = await getAllMangas();
|
src/types/manga.ts
CHANGED
|
@@ -18,6 +18,7 @@ export interface Manga {
|
|
| 18 |
export interface Category {
|
| 19 |
id: string;
|
| 20 |
name: string;
|
|
|
|
| 21 |
created_at: string;
|
| 22 |
}
|
| 23 |
|
|
|
|
| 18 |
export interface Category {
|
| 19 |
id: string;
|
| 20 |
name: string;
|
| 21 |
+
type?: 'character' | 'series' | 'genre' | 'other';
|
| 22 |
created_at: string;
|
| 23 |
}
|
| 24 |
|
src/utils/searchUtils.ts
CHANGED
|
@@ -51,6 +51,7 @@ export interface SearchableItem {
|
|
| 51 |
id: string;
|
| 52 |
title: string;
|
| 53 |
author: string;
|
|
|
|
| 54 |
[key: string]: any;
|
| 55 |
}
|
| 56 |
|
|
@@ -77,7 +78,24 @@ export function searchItems<T extends SearchableItem>(
|
|
| 77 |
const titleExactMatch = normalizeString(item.title).includes(normalizedQuery) ? 0.3 : 0;
|
| 78 |
const authorExactMatch = normalizeString(item.author).includes(normalizedQuery) ? 0.2 : 0;
|
| 79 |
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
return { item, score };
|
| 83 |
})
|
|
|
|
| 51 |
id: string;
|
| 52 |
title: string;
|
| 53 |
author: string;
|
| 54 |
+
categories?: string[];
|
| 55 |
[key: string]: any;
|
| 56 |
}
|
| 57 |
|
|
|
|
| 78 |
const titleExactMatch = normalizeString(item.title).includes(normalizedQuery) ? 0.3 : 0;
|
| 79 |
const authorExactMatch = normalizeString(item.author).includes(normalizedQuery) ? 0.2 : 0;
|
| 80 |
|
| 81 |
+
let categoryScore = 0;
|
| 82 |
+
let categoryExactMatch = 0;
|
| 83 |
+
|
| 84 |
+
if (item.categories && item.categories.length > 0) {
|
| 85 |
+
// Find best matching category
|
| 86 |
+
const catScores = item.categories.map(cat => calculateSimilarity(cat, query));
|
| 87 |
+
categoryScore = Math.max(...catScores);
|
| 88 |
+
|
| 89 |
+
// Check for exact substring match in any category
|
| 90 |
+
const catExact = item.categories.some(cat => normalizeString(cat).includes(normalizedQuery));
|
| 91 |
+
categoryExactMatch = catExact ? 0.3 : 0;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
score = Math.max(
|
| 95 |
+
titleScore * 0.6 + titleExactMatch,
|
| 96 |
+
authorScore * 0.4 + authorExactMatch,
|
| 97 |
+
categoryScore * 0.5 + categoryExactMatch
|
| 98 |
+
);
|
| 99 |
|
| 100 |
return { item, score };
|
| 101 |
})
|