feat: progressbar everywhere

This commit is contained in:
Julien Froidefond
2025-02-26 08:35:07 +01:00
parent 7c8fa6bf72
commit c79214853a
4 changed files with 21 additions and 8 deletions

View File

@@ -25,27 +25,32 @@ export function HomeContent({ data, refreshHome }: HomeContentProps) {
// }); // });
const optimizeSeriesData = (series: KomgaSeries[]) => { const optimizeSeriesData = (series: KomgaSeries[]) => {
return series.map(({ id, metadata, booksCount }) => ({ return series.map(({ id, metadata, booksCount, booksReadCount }) => ({
id, id,
metadata: { title: metadata.title }, metadata: { title: metadata.title },
booksCount, booksCount,
booksReadCount
})); }));
}; };
const optimizeHeroSeriesData = (series: KomgaSeries[]) => { const optimizeHeroSeriesData = (series: KomgaSeries[]) => {
return series.map(({ id, metadata }) => ({ return series.map(({ id, metadata, booksCount, booksReadCount }) => ({
id, id,
metadata: { title: metadata.title }, metadata: { title: metadata.title },
booksCount,
booksReadCount
})); }));
}; };
const optimizeBookData = (books: KomgaBook[]) => { const optimizeBookData = (books: KomgaBook[]) => {
return books.map(({ id, metadata }) => ({ return books.map(({ id, metadata, readProgress, media }) => ({
id, id,
metadata: { metadata: {
title: metadata.title, title: metadata.title,
number: metadata.number, number: metadata.number,
}, },
readProgress,
media
})); }));
}; };

View File

@@ -14,6 +14,7 @@ interface BaseItem {
interface OptimizedSeries extends BaseItem { interface OptimizedSeries extends BaseItem {
booksCount: number; booksCount: number;
booksReadCount: number;
} }
interface OptimizedBook extends BaseItem { interface OptimizedBook extends BaseItem {
@@ -124,6 +125,9 @@ function MediaCard({ item, onClick }: MediaCardProps) {
id={item.id} id={item.id}
alt={`Couverture de ${title}`} alt={`Couverture de ${title}`}
quality={100} quality={100}
readBooks={isSeries ? item.booksReadCount : undefined}
totalBooks={isSeries ? item.booksCount : undefined}
isCompleted={isSeries ? item.booksCount === item.booksReadCount : undefined}
/> />
{/* Overlay avec les informations au survol */} {/* Overlay avec les informations au survol */}
<div className="absolute inset-0 bg-black/60 opacity-0 hover:opacity-100 transition-opacity duration-200 flex flex-col justify-end p-3"> <div className="absolute inset-0 bg-black/60 opacity-0 hover:opacity-100 transition-opacity duration-200 flex flex-col justify-end p-3">

View File

@@ -44,19 +44,19 @@ export function Cover(props: CoverProps) {
} = props; } = props;
const imageUrl = getImageUrl(type, id); const imageUrl = getImageUrl(type, id);
const showProgress = () => { const showProgress = () => {
if (type === "book") { if (type === "book") {
const { currentPage, totalPages } = props; const { currentPage, totalPages } = props;
return currentPage && totalPages && currentPage > 0 && !isCompleted ? ( return currentPage && totalPages && currentPage > 0 && !isCompleted ? (
<ProgressBar progress={currentPage} total={totalPages} /> <ProgressBar progress={currentPage} total={totalPages} type="book" />
) : null; ) : null;
} }
if (type === "series") { if (type === "series") {
const { readBooks, totalBooks } = props; const { readBooks, totalBooks } = props;
return readBooks && totalBooks && readBooks > 0 && !isCompleted ? ( return readBooks && totalBooks && readBooks > 0 && !isCompleted ? (
<ProgressBar progress={readBooks} total={totalBooks} /> <ProgressBar progress={readBooks} total={totalBooks} type="series" />
) : null; ) : null;
} }
}; };

View File

@@ -1,16 +1,20 @@
interface ProgressBarProps { interface ProgressBarProps {
progress: number; progress: number;
total: number; total: number;
type: "series" | "book";
} }
export function ProgressBar({ progress, total }: ProgressBarProps) { export function ProgressBar({ progress, total, type }: ProgressBarProps) {
const percentage = Math.round((progress / total) * 100); const percentage = Math.round((progress / total) * 100);
const barColor = type === "series"
? "bg-gradient-to-r from-purple-500 to-pink-500"
: "bg-gradient-to-r from-blue-500 to-cyan-500";
return ( return (
<div className="absolute bottom-0 left-0 right-0 px-3 py-2 bg-black/50 backdrop-blur-sm border-t border-white/10"> <div className="absolute bottom-0 left-0 right-0 px-3 py-2 bg-black/50 backdrop-blur-sm border-t border-white/10">
<div className="h-2 bg-white/30 rounded-full overflow-hidden"> <div className="h-2 bg-white/30 rounded-full overflow-hidden">
<div <div
className="h-full bg-white rounded-full transition-all duration-300" className={`h-full transition-all duration-300 ${barColor}`}
style={{ width: `${percentage}%` }} style={{ width: `${percentage}%` }}
/> />
</div> </div>