feat: Ajout de React pour le front, début de refonte du front
This commit is contained in:
parent
73774f84ff
commit
666636e5bf
26
assets/react/app/presentation/components/Header.jsx
Normal file
26
assets/react/app/presentation/components/Header.jsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import React from 'react';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faBars } from '@fortawesome/free-solid-svg-icons';
|
||||
import { SearchBar } from './SearchBar/SearchBar.jsx';
|
||||
|
||||
export function Header({ onMenuClick, onMangaClick, onAddMangaClick }) {
|
||||
return (
|
||||
<header className="bg-green-600 h-16 flex items-center fixed w-full z-50">
|
||||
<button
|
||||
onClick={onMenuClick}
|
||||
className="ml-4 text-white p-2 md:hidden"
|
||||
>
|
||||
<FontAwesomeIcon icon={faBars} />
|
||||
</button>
|
||||
<div className="flex items-center flex-1">
|
||||
<a href="/" className="text-white text-2xl font-bold ml-4">
|
||||
Mangarr
|
||||
</a>
|
||||
<SearchBar
|
||||
onMangaClick={onMangaClick}
|
||||
onAddMangaClick={onAddMangaClick}
|
||||
/>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
26
assets/react/app/presentation/components/Layout/Layout.jsx
Normal file
26
assets/react/app/presentation/components/Layout/Layout.jsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Header } from '../Header';
|
||||
import { Sidebar } from '../Sidebar';
|
||||
|
||||
export function Layout({ children, onMangaClick, onAddMangaClick }) {
|
||||
const [isSidebarOpen, setIsSidebarOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
<Header
|
||||
onMenuClick={() => setIsSidebarOpen(!isSidebarOpen)}
|
||||
onMangaClick={onMangaClick}
|
||||
onAddMangaClick={onAddMangaClick}
|
||||
/>
|
||||
<Sidebar
|
||||
isOpen={isSidebarOpen}
|
||||
onClose={() => setIsSidebarOpen(false)}
|
||||
onAddMangaClick={onAddMangaClick}
|
||||
/>
|
||||
|
||||
<main className="pt-16 md:ml-60">
|
||||
{children}
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
43
assets/react/app/presentation/components/MangaCard.jsx
Normal file
43
assets/react/app/presentation/components/MangaCard.jsx
Normal file
@@ -0,0 +1,43 @@
|
||||
import React from 'react';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faStar } from '@fortawesome/free-solid-svg-icons';
|
||||
|
||||
export function MangaCard({ manga, onClick }) {
|
||||
return (
|
||||
<div
|
||||
className="bg-white rounded-lg shadow-md overflow-hidden cursor-pointer transition-transform hover:scale-105"
|
||||
onClick={() => onClick?.(manga.slug)}
|
||||
>
|
||||
<div className="relative h-64">
|
||||
<img
|
||||
src={manga.imageUrl || 'https://via.placeholder.com/300x400'}
|
||||
alt={manga.title}
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
</div>
|
||||
<div className="p-4">
|
||||
<h3 className="text-lg font-semibold text-gray-800 mb-2">{manga.title}</h3>
|
||||
<p className="text-sm text-gray-600 mb-2">By {manga.author}</p>
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-sm text-gray-500">{manga.publicationYear}</span>
|
||||
{manga.rating && (
|
||||
<span className="flex items-center text-yellow-500">
|
||||
<FontAwesomeIcon icon={faStar} className="mr-1" />
|
||||
{manga.rating}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="mt-2 flex flex-wrap gap-1">
|
||||
{manga.genres.map((genre, index) => (
|
||||
<span
|
||||
key={index}
|
||||
className="px-2 py-1 text-xs bg-green-100 text-green-800 rounded-full"
|
||||
>
|
||||
{genre}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
16
assets/react/app/presentation/components/MangaGrid.jsx
Normal file
16
assets/react/app/presentation/components/MangaGrid.jsx
Normal file
@@ -0,0 +1,16 @@
|
||||
import React from 'react';
|
||||
import { MangaCard } from './MangaCard.jsx';
|
||||
|
||||
export function MangaGrid({ mangas, onMangaClick }) {
|
||||
return (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6 p-6">
|
||||
{mangas.map((manga) => (
|
||||
<MangaCard
|
||||
key={manga.id}
|
||||
manga={manga}
|
||||
onClick={onMangaClick}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
125
assets/react/app/presentation/components/SearchBar/SearchBar.jsx
Normal file
125
assets/react/app/presentation/components/SearchBar/SearchBar.jsx
Normal file
@@ -0,0 +1,125 @@
|
||||
import React, { useState, useRef, useEffect } from 'react';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faSearch, faPlus } from '@fortawesome/free-solid-svg-icons';
|
||||
import { MockMangaRepository } from '../../../infrastructure/api/mockMangaRepository.js';
|
||||
import { SearchMangas } from '../../../application/useCases/searchMangas.js';
|
||||
|
||||
const mangaRepository = new MockMangaRepository();
|
||||
const searchMangas = new SearchMangas(mangaRepository);
|
||||
|
||||
export function SearchBar({ onMangaClick, onAddMangaClick }) {
|
||||
const [query, setQuery] = useState('');
|
||||
const [results, setResults] = useState([]);
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [hasSearched, setHasSearched] = useState(false);
|
||||
const searchRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event) => {
|
||||
if (searchRef.current && !searchRef.current.contains(event.target)) {
|
||||
setIsOpen(false);
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('mousedown', handleClickOutside);
|
||||
return () => document.removeEventListener('mousedown', handleClickOutside);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const searchManga = async () => {
|
||||
if (!query.trim()) {
|
||||
setResults([]);
|
||||
setHasSearched(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const searchResults = await searchMangas.execute(query);
|
||||
setResults(searchResults);
|
||||
setHasSearched(true);
|
||||
} catch (error) {
|
||||
console.error('Search error:', error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const timeoutId = setTimeout(searchManga, 300);
|
||||
return () => clearTimeout(timeoutId);
|
||||
}, [query]);
|
||||
|
||||
return (
|
||||
<div ref={searchRef} className="relative flex-1 max-w-xl mx-4">
|
||||
<div className="flex items-center py-1">
|
||||
<FontAwesomeIcon
|
||||
icon={faSearch}
|
||||
className="text-white"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
value={query}
|
||||
onChange={(e) => {
|
||||
setQuery(e.target.value);
|
||||
setIsOpen(true);
|
||||
}}
|
||||
onFocus={() => setIsOpen(true)}
|
||||
placeholder="Rechercher"
|
||||
className="appearance-none outline-none ml-2 pl-0 bg-transparent border-b border-white w-full placeholder:text-white text-white py-1 px-2 leading-tight transition-all duration-500 ease-in-out focus:placeholder:text-opacity-0 focus:border-opacity-0"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{isOpen && query.trim() && (
|
||||
<div className="absolute w-full mt-2 bg-gray-800/95 backdrop-blur-sm rounded-lg shadow-lg border border-gray-700 max-h-96 overflow-y-auto z-50">
|
||||
{loading ? (
|
||||
<div className="p-4 text-center text-gray-400">Chargement...</div>
|
||||
) : results.length > 0 ? (
|
||||
<div className="py-2">
|
||||
<h3 className="px-4 py-2 text-sm font-semibold text-gray-400">
|
||||
Mangas existants
|
||||
</h3>
|
||||
{results.map((manga) => (
|
||||
<button
|
||||
key={manga.id}
|
||||
onClick={() => {
|
||||
onMangaClick(manga.slug);
|
||||
setIsOpen(false);
|
||||
setQuery('');
|
||||
setHasSearched(false);
|
||||
}}
|
||||
className="w-full px-4 py-2 flex items-center gap-3 hover:bg-gray-700/50 text-white"
|
||||
>
|
||||
<img
|
||||
src={manga.imageUrl}
|
||||
alt={manga.title}
|
||||
className="w-10 h-14 object-cover rounded"
|
||||
/>
|
||||
<div className="text-left">
|
||||
<div className="font-medium">{manga.title}</div>
|
||||
<div className="text-sm text-gray-400">{manga.author} ({manga.publicationYear})</div>
|
||||
</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
) : hasSearched && (
|
||||
<div className="py-2">
|
||||
<button
|
||||
onClick={() => {
|
||||
onAddMangaClick(query);
|
||||
setIsOpen(false);
|
||||
setQuery('');
|
||||
setHasSearched(false);
|
||||
}}
|
||||
className="w-full px-4 py-2 flex items-center gap-2 text-green-400 hover:bg-gray-700/50"
|
||||
>
|
||||
<FontAwesomeIcon icon={faPlus} />
|
||||
<span>Ajouter "{query}"</span>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
164
assets/react/app/presentation/components/Sidebar.jsx
Normal file
164
assets/react/app/presentation/components/Sidebar.jsx
Normal file
@@ -0,0 +1,164 @@
|
||||
import React, { useState } from 'react';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import {
|
||||
faBook,
|
||||
faPlus,
|
||||
faFileImport,
|
||||
faCompass,
|
||||
faExchangeAlt,
|
||||
faCalendar,
|
||||
faClockRotateLeft,
|
||||
faCog,
|
||||
faDesktop,
|
||||
faChevronDown,
|
||||
faChevronUp
|
||||
} from '@fortawesome/free-solid-svg-icons';
|
||||
|
||||
export function Sidebar({ isOpen, onClose, onAddMangaClick }) {
|
||||
const [expandedMenus, setExpandedMenus] = useState({
|
||||
mangas: true, // Par défaut, le menu Mangas est ouvert
|
||||
settings: false,
|
||||
system: false
|
||||
});
|
||||
|
||||
const menuItems = [
|
||||
{
|
||||
icon: faBook,
|
||||
text: 'Mangas',
|
||||
id: 'mangas',
|
||||
subItems: [
|
||||
{ icon: faPlus, text: 'Ajouter un nouveau', onClick: () => onAddMangaClick() },
|
||||
{ icon: faFileImport, text: 'Import bibliothèque', href: '#' },
|
||||
{ icon: faCompass, text: 'Découvrir', href: '#' },
|
||||
]
|
||||
},
|
||||
{
|
||||
icon: faExchangeAlt,
|
||||
text: 'Convertir CBR en CBZ',
|
||||
href: '#'
|
||||
},
|
||||
{
|
||||
icon: faCalendar,
|
||||
text: 'Calendrier',
|
||||
href: '#'
|
||||
},
|
||||
{
|
||||
icon: faClockRotateLeft,
|
||||
text: 'Activité',
|
||||
href: '#',
|
||||
badge: '3'
|
||||
},
|
||||
{
|
||||
icon: faCog,
|
||||
text: 'Paramètres',
|
||||
id: 'settings',
|
||||
subItems: [
|
||||
{ text: 'Général', href: '#' },
|
||||
{ text: 'Dossiers', href: '#' },
|
||||
{ text: 'Scrappers', href: '#' },
|
||||
{ text: 'UI', href: '#' }
|
||||
]
|
||||
},
|
||||
{
|
||||
icon: faDesktop,
|
||||
text: 'Système',
|
||||
id: 'system',
|
||||
subItems: [
|
||||
{ text: 'Status', href: '#' },
|
||||
{ text: 'Backup', href: '#' },
|
||||
{ text: 'Logs', href: '#' },
|
||||
{ text: 'Updates', href: '#' }
|
||||
]
|
||||
},
|
||||
];
|
||||
|
||||
const toggleMenu = (menuId) => {
|
||||
setExpandedMenus(prev => ({
|
||||
...prev,
|
||||
[menuId]: !prev[menuId]
|
||||
}));
|
||||
};
|
||||
|
||||
const MenuItem = ({ item }) => {
|
||||
const hasSubItems = item.subItems && item.subItems.length > 0;
|
||||
const isExpanded = item.id && expandedMenus[item.id];
|
||||
const isActive = false; // À implémenter avec un vrai système de routing
|
||||
|
||||
return (
|
||||
<div className={`border-l-4 ${isActive ? 'border-green-600' : 'border-transparent'}`}>
|
||||
<button
|
||||
onClick={() => {
|
||||
if (hasSubItems) {
|
||||
toggleMenu(item.id);
|
||||
} else if (item.onClick) {
|
||||
item.onClick();
|
||||
} else if (item.href) {
|
||||
window.location.href = item.href;
|
||||
}
|
||||
}}
|
||||
className={`
|
||||
w-full text-left pl-4 py-2 flex items-center justify-between
|
||||
${isActive ? 'text-green-600 bg-gray-800' : 'text-white hover:bg-gray-700'}
|
||||
transition-colors duration-150
|
||||
`}
|
||||
>
|
||||
<div className="flex items-center space-x-3">
|
||||
<FontAwesomeIcon icon={item.icon} className="w-5 h-5" />
|
||||
<span>{item.text}</span>
|
||||
</div>
|
||||
{hasSubItems ? (
|
||||
<FontAwesomeIcon
|
||||
icon={isExpanded ? faChevronUp : faChevronDown}
|
||||
className="w-4 h-4 mr-4"
|
||||
/>
|
||||
) : item.badge ? (
|
||||
<span className="bg-green-600 text-white text-xs px-2 py-1 rounded mr-4">
|
||||
{item.badge}
|
||||
</span>
|
||||
) : null}
|
||||
</button>
|
||||
|
||||
{hasSubItems && isExpanded && (
|
||||
<div className="ml-8 mt-2 space-y-2">
|
||||
{item.subItems.map((subItem, index) => (
|
||||
<a
|
||||
key={index}
|
||||
href={subItem.href}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
if (subItem.onClick) {
|
||||
subItem.onClick();
|
||||
} else if (subItem.href !== '#') {
|
||||
window.location.href = subItem.href;
|
||||
}
|
||||
}}
|
||||
className="block py-2 text-gray-300 hover:text-green-600 transition-colors duration-150"
|
||||
>
|
||||
{subItem.icon && (
|
||||
<FontAwesomeIcon icon={subItem.icon} className="w-4 h-4 mr-2" />
|
||||
)}
|
||||
{subItem.text}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<nav className={`
|
||||
w-60 bg-gray-600 h-full overflow-y-auto fixed left-0 top-16 transform transition-transform duration-200 ease-in-out z-40
|
||||
${isOpen ? 'translate-x-0' : '-translate-x-full'}
|
||||
md:translate-x-0
|
||||
`}>
|
||||
<div className="py-4">
|
||||
<div className="space-y-1">
|
||||
{menuItems.map((item, index) => (
|
||||
<MenuItem key={index} item={item} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
29
assets/react/app/presentation/components/Toolbar/Toolbar.jsx
Normal file
29
assets/react/app/presentation/components/Toolbar/Toolbar.jsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import React from 'react';
|
||||
import { ToolbarButton } from './ToolbarButton';
|
||||
|
||||
export function Toolbar({
|
||||
leftSection = [],
|
||||
centerSection = [],
|
||||
rightSection = [],
|
||||
className = ''
|
||||
}) {
|
||||
const renderSection = (items) => (
|
||||
<div className="flex items-center gap-2">
|
||||
{items.map((item, index) => (
|
||||
<ToolbarButton key={index} {...item} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={`bg-gray-800 shadow-sm border-b border-gray-700 ${className}`}>
|
||||
<div className="container mx-auto px-4">
|
||||
<div className="h-14 flex items-center justify-between">
|
||||
{renderSection(leftSection)}
|
||||
{renderSection(centerSection)}
|
||||
{renderSection(rightSection)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import React from 'react';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
|
||||
export function ToolbarButton({ icon, label, onClick, active = false }) {
|
||||
return (
|
||||
<button
|
||||
onClick={onClick}
|
||||
className={`
|
||||
flex items-center gap-2 px-4 py-2 rounded-lg transition-colors
|
||||
${active
|
||||
? 'bg-green-600 text-white'
|
||||
: 'text-gray-300 hover:text-green-600'
|
||||
}
|
||||
`}
|
||||
>
|
||||
<FontAwesomeIcon icon={icon} />
|
||||
{label && <span>{label}</span>}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
185
assets/react/app/presentation/pages/AddMangaPage.jsx
Normal file
185
assets/react/app/presentation/pages/AddMangaPage.jsx
Normal file
@@ -0,0 +1,185 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||
import { Layout } from '../components/Layout/Layout';
|
||||
import { Toolbar } from '../components/Toolbar/Toolbar';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faArrowLeft, faSearch, faStar } from '@fortawesome/free-solid-svg-icons';
|
||||
import { MockMangaRepository } from '../../infrastructure/api/mockMangaRepository';
|
||||
import { SearchMangas } from '../../application/useCases/searchMangas';
|
||||
|
||||
const mangaRepository = new MockMangaRepository();
|
||||
const searchMangas = new SearchMangas(mangaRepository);
|
||||
|
||||
export function AddMangaPage() {
|
||||
const navigate = useNavigate();
|
||||
const [searchParams] = useSearchParams();
|
||||
const initialQuery = searchParams.get('q') || '';
|
||||
|
||||
const [query, setQuery] = useState(initialQuery);
|
||||
const [results, setResults] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [selectedManga, setSelectedManga] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (initialQuery) {
|
||||
handleSearch(initialQuery);
|
||||
}
|
||||
}, [initialQuery]);
|
||||
|
||||
const handleSearch = async (searchQuery) => {
|
||||
if (!searchQuery.trim()) {
|
||||
setResults([]);
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const searchResults = await searchMangas.execute(searchQuery);
|
||||
setResults(searchResults);
|
||||
} catch (error) {
|
||||
console.error('Search error:', error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleMangaClick = (slug) => {
|
||||
navigate(`/manga/${slug}`);
|
||||
};
|
||||
|
||||
const handleAddMangaClick = (query = '') => {
|
||||
navigate(`/add${query ? `?q=${encodeURIComponent(query)}` : ''}`);
|
||||
};
|
||||
|
||||
const toolbarConfig = {
|
||||
leftSection: [
|
||||
{ icon: faArrowLeft, onClick: () => navigate(-1) }
|
||||
]
|
||||
};
|
||||
|
||||
return (
|
||||
<Layout onMangaClick={handleMangaClick} onAddMangaClick={handleAddMangaClick}>
|
||||
<Toolbar {...toolbarConfig} className="sticky top-16 z-10" />
|
||||
|
||||
<div className="container mx-auto px-4 py-6">
|
||||
<h1 className="text-2xl font-bold mb-6">Ajouter un manga</h1>
|
||||
|
||||
<div className="bg-white rounded-lg shadow-sm p-6">
|
||||
<div className="max-w-3xl mx-auto">
|
||||
<div className="relative">
|
||||
<input
|
||||
type="text"
|
||||
value={query}
|
||||
onChange={(e) => {
|
||||
setQuery(e.target.value);
|
||||
handleSearch(e.target.value);
|
||||
}}
|
||||
placeholder="Rechercher un manga..."
|
||||
className="w-full px-4 py-2 pl-10 border-b border-gray-300 focus:border-green-600 outline-none transition-colors"
|
||||
/>
|
||||
<FontAwesomeIcon
|
||||
icon={faSearch}
|
||||
className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{loading ? (
|
||||
<div className="text-center py-8">
|
||||
<div className="animate-spin rounded-full h-8 w-8 border-2 border-green-600 border-t-transparent mx-auto"></div>
|
||||
</div>
|
||||
) : results.length > 0 ? (
|
||||
<div className="space-y-4 mt-6">
|
||||
{results.map((manga) => (
|
||||
<div
|
||||
key={manga.id}
|
||||
onClick={() => setSelectedManga(manga)}
|
||||
className="flex gap-4 p-4 bg-gray-50 rounded-lg hover:bg-gray-100 transition-colors cursor-pointer"
|
||||
>
|
||||
<img
|
||||
src={manga.imageUrl}
|
||||
alt={manga.title}
|
||||
className="w-24 h-36 object-cover rounded-lg shadow-sm"
|
||||
/>
|
||||
<div className="flex-1">
|
||||
<div className="flex items-start justify-between">
|
||||
<div>
|
||||
<h3 className="text-lg font-semibold text-gray-900">{manga.title}</h3>
|
||||
<p className="text-gray-600">{manga.author}</p>
|
||||
</div>
|
||||
<div className="flex items-center text-yellow-500">
|
||||
<FontAwesomeIcon icon={faStar} className="mr-1" />
|
||||
<span>{manga.rating}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-2">
|
||||
<span className="text-sm text-gray-500">
|
||||
{manga.publicationYear} • {manga.status}
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-2 flex flex-wrap gap-2">
|
||||
{manga.genres.map((genre, index) => (
|
||||
<span
|
||||
key={index}
|
||||
className="px-2 py-1 text-xs bg-green-100 text-green-800 rounded-full"
|
||||
>
|
||||
{genre}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : query && !loading && (
|
||||
<div className="text-center py-8 text-gray-500">
|
||||
Aucun résultat trouvé pour "{query}"
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Modal de confirmation */}
|
||||
{selectedManga && (
|
||||
<div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50">
|
||||
<div className="bg-white rounded-lg shadow-xl max-w-lg w-full mx-4">
|
||||
<div className="p-6">
|
||||
<h2 className="text-xl font-semibold mb-4">Ajouter à la bibliothèque</h2>
|
||||
<div className="flex gap-4 mb-4">
|
||||
<img
|
||||
src={selectedManga.imageUrl}
|
||||
alt={selectedManga.title}
|
||||
className="w-24 h-36 object-cover rounded"
|
||||
/>
|
||||
<div>
|
||||
<h3 className="font-semibold">{selectedManga.title}</h3>
|
||||
<p className="text-gray-600">{selectedManga.author}</p>
|
||||
<p className="text-sm text-gray-500 mt-2">
|
||||
{selectedManga.genres.join(', ')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex justify-end gap-3">
|
||||
<button
|
||||
onClick={() => setSelectedManga(null)}
|
||||
className="px-4 py-2 text-gray-600 hover:bg-gray-100 rounded-lg transition-colors"
|
||||
>
|
||||
Annuler
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
handleMangaClick(selectedManga.slug);
|
||||
setSelectedManga(null);
|
||||
}}
|
||||
className="px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors"
|
||||
>
|
||||
Ajouter
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
80
assets/react/app/presentation/pages/HomePage.jsx
Normal file
80
assets/react/app/presentation/pages/HomePage.jsx
Normal file
@@ -0,0 +1,80 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { MangaGrid } from '../components/MangaGrid.jsx';
|
||||
import { Layout } from '../components/Layout/Layout.jsx';
|
||||
import { Toolbar } from '../components/Toolbar/Toolbar.jsx';
|
||||
import { MockMangaRepository } from '../../infrastructure/api/mockMangaRepository.js';
|
||||
import { GetMangaCollection } from '../../application/useCases/getMangaCollection.js';
|
||||
import {
|
||||
faRefresh,
|
||||
faSearch,
|
||||
faGear,
|
||||
faEye,
|
||||
faSort,
|
||||
faFilter
|
||||
} from '@fortawesome/free-solid-svg-icons';
|
||||
|
||||
const mangaRepository = new MockMangaRepository();
|
||||
const getMangaCollection = new GetMangaCollection(mangaRepository);
|
||||
|
||||
export function HomePage() {
|
||||
const navigate = useNavigate();
|
||||
const [mangaCollection, setMangaCollection] = useState(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
const handleRefresh = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const collection = await getMangaCollection.execute(1);
|
||||
setMangaCollection(collection);
|
||||
} catch (err) {
|
||||
setError('Failed to load mangas');
|
||||
console.error(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
handleRefresh();
|
||||
}, []);
|
||||
|
||||
const handleMangaClick = (slug) => {
|
||||
navigate(`/manga/${slug}`);
|
||||
};
|
||||
|
||||
const handleAddMangaClick = (query = '') => {
|
||||
navigate(`/add${query ? `?q=${encodeURIComponent(query)}` : ''}`);
|
||||
};
|
||||
|
||||
const toolbarConfig = {
|
||||
leftSection: [
|
||||
{ icon: faRefresh, label: 'Refresh', onClick: handleRefresh },
|
||||
{ icon: faSearch, label: 'Search', onClick: () => {} }
|
||||
],
|
||||
rightSection: [
|
||||
{ icon: faGear, onClick: () => {} },
|
||||
{ icon: faEye, onClick: () => {} },
|
||||
{ icon: faSort, onClick: () => {} },
|
||||
{ icon: faFilter, onClick: () => {} }
|
||||
]
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return <div className="flex justify-center items-center h-screen">Loading...</div>;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <div className="text-red-500 text-center p-4">{error}</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<Layout onMangaClick={handleMangaClick} onAddMangaClick={handleAddMangaClick}>
|
||||
<Toolbar {...toolbarConfig} className="sticky top-16 z-10" />
|
||||
<div className="container mx-auto px-4">
|
||||
<MangaGrid mangas={mangaCollection.items} onMangaClick={handleMangaClick} />
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
183
assets/react/app/presentation/pages/MangaDetailPage.jsx
Normal file
183
assets/react/app/presentation/pages/MangaDetailPage.jsx
Normal file
@@ -0,0 +1,183 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useParams, useNavigate } from 'react-router-dom';
|
||||
import { MockMangaRepository } from '../../infrastructure/api/mockMangaRepository.js';
|
||||
import { GetMangaDetail } from '../../application/useCases/getMangaDetail.js';
|
||||
import { Layout } from '../components/Layout/Layout.jsx';
|
||||
import { Toolbar } from '../components/Toolbar/Toolbar.jsx';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import {
|
||||
faStar,
|
||||
faDownload,
|
||||
faEye,
|
||||
faArrowLeft,
|
||||
faRefresh,
|
||||
faBookmark,
|
||||
faShare
|
||||
} from '@fortawesome/free-solid-svg-icons';
|
||||
|
||||
const mangaRepository = new MockMangaRepository();
|
||||
const getMangaDetail = new GetMangaDetail(mangaRepository);
|
||||
|
||||
export function MangaDetailPage() {
|
||||
const { slug } = useParams();
|
||||
const navigate = useNavigate();
|
||||
const [manga, setManga] = useState(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
const handleRefresh = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const mangaDetail = await getMangaDetail.execute(slug);
|
||||
setManga(mangaDetail);
|
||||
} catch (err) {
|
||||
setError('Failed to load manga details');
|
||||
console.error(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
handleRefresh();
|
||||
}, [slug]);
|
||||
|
||||
const handleMangaClick = (mangaSlug) => {
|
||||
navigate(`/manga/${mangaSlug}`);
|
||||
};
|
||||
|
||||
const handleAddMangaClick = (query = '') => {
|
||||
navigate(`/add${query ? `?q=${encodeURIComponent(query)}` : ''}`);
|
||||
};
|
||||
|
||||
const toolbarConfig = {
|
||||
leftSection: [
|
||||
{ icon: faArrowLeft, onClick: () => navigate(-1) },
|
||||
{ icon: faRefresh, onClick: handleRefresh }
|
||||
],
|
||||
rightSection: [
|
||||
{ icon: faBookmark, onClick: () => {} },
|
||||
{ icon: faShare, onClick: () => {} },
|
||||
{ icon: faDownload, onClick: () => {} }
|
||||
]
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return <div className="flex justify-center items-center h-screen">Loading...</div>;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <div className="text-red-500 text-center p-4">{error}</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<Layout onMangaClick={handleMangaClick} onAddMangaClick={handleAddMangaClick}>
|
||||
<Toolbar {...toolbarConfig} className="sticky top-16 z-10" />
|
||||
|
||||
{/* Hero section with manga info */}
|
||||
<div className="relative h-[400px]">
|
||||
<div className="absolute inset-0">
|
||||
<img
|
||||
src={manga.imageUrl}
|
||||
alt={manga.title}
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
<div className="absolute inset-0 bg-gradient-to-t from-black/80 to-transparent" />
|
||||
</div>
|
||||
|
||||
<div className="relative h-full container mx-auto px-4 flex items-end pb-8">
|
||||
<div className="text-white">
|
||||
<div className="flex items-center gap-4 mb-2">
|
||||
<h1 className="text-4xl font-bold">{manga.title}</h1>
|
||||
<span className="px-2 py-1 bg-green-500 rounded-full text-sm">
|
||||
{manga.status}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-6 mb-4">
|
||||
<div className="flex items-center">
|
||||
<FontAwesomeIcon icon={faStar} className="text-yellow-400 mr-2" />
|
||||
<span>{manga.rating}</span>
|
||||
</div>
|
||||
<span>{manga.publicationYear}</span>
|
||||
<span>{manga.author}</span>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-2 mb-4">
|
||||
{manga.genres.map((genre, index) => (
|
||||
<span
|
||||
key={index}
|
||||
className="px-3 py-1 bg-gray-700/50 rounded-full text-sm"
|
||||
>
|
||||
{genre}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<p className="max-w-3xl text-gray-200">
|
||||
{manga.description}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Chapters section */}
|
||||
<div className="container mx-auto px-4 py-8">
|
||||
{Array.from(manga.chapters.entries()).map(([volume, chapters]) => (
|
||||
<div key={volume} className="mb-8">
|
||||
<h2 className="text-xl font-semibold mb-4">
|
||||
Volume {volume || 'Unknown'}
|
||||
<span className="text-sm text-gray-500 ml-2">
|
||||
({chapters.length} chapters)
|
||||
</span>
|
||||
</h2>
|
||||
|
||||
<div className="bg-white rounded-lg shadow overflow-hidden">
|
||||
<table className="w-full">
|
||||
<thead className="bg-gray-50">
|
||||
<tr>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
#
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Title
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Added
|
||||
</th>
|
||||
<th className="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Actions
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-gray-200">
|
||||
{chapters.map((chapter) => (
|
||||
<tr key={chapter.id} className="hover:bg-gray-50">
|
||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
|
||||
{chapter.number}
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
|
||||
{chapter.title}
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||
{new Date(chapter.createdAt).toLocaleDateString()}
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500 text-right">
|
||||
<button className="text-gray-400 hover:text-gray-600 mx-2">
|
||||
<FontAwesomeIcon icon={faDownload} />
|
||||
</button>
|
||||
<button className="text-gray-400 hover:text-gray-600 mx-2">
|
||||
<FontAwesomeIcon icon={faEye} />
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user