Implemented the new react version of the frontend

This commit is contained in:
Mohammed Abad committed 2026-03-31 01:56:38 +01:00
1 parent 236e6e06fb
commit ffe7e52527
65 files changed
+5228 -177

No files matched your search

@@ -0,0 +1,176 @@
import { useState } from 'react';
import { Link } from 'react-router-dom';
import { Plus, Trash2, Star } from 'lucide-react';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Skeleton } from '@/components/ui/skeleton';
import { getPosterUrl, getYear, formatRuntime } from '@/lib/media-utils';
import { useCreateEntry, useDeleteEntry } from '@/hooks/useEntries';
import { useLibraryStore } from '@/stores/useLibraryStore';
import { ConfirmDialog } from '@/components/dialogs/ConfirmDialog';
import type { Entry, TmdbEntry } from '@/types';
interface EntryCardProps {
entry?: Entry;
tmdbEntry?: TmdbEntry;
}
export function EntryCard({ entry, tmdbEntry }: EntryCardProps) {
const [showConfirm, setShowConfirm] = useState(false);
const createEntry = useCreateEntry();
const deleteEntry = useDeleteEntry();
const libraryEntry = useLibraryStore((s) => {
if (entry?.isInLibrary) return entry;
if (tmdbEntry) {
for (const e of s.entries.values()) {
if (e.entryIds?.tmdb_id === tmdbEntry.id) return e;
}
}
return null;
});
const isInLibrary = !!libraryEntry;
const displayEntry = libraryEntry || entry;
// Resolve display data
const title =
displayEntry?.title || tmdbEntry?.title || tmdbEntry?.name || 'Untitled';
const year = displayEntry
? getYear(displayEntry.release_date)
: getYear(tmdbEntry?.release_date || tmdbEntry?.first_air_date || null);
const rating =
displayEntry?.entryRatings?.user_rating ||
displayEntry?.entryRatings?.tmdb_rating ||
tmdbEntry?.vote_average;
const runtime =
displayEntry && !displayEntry.is_tvseries
? formatRuntime(displayEntry.runtime)
: '';
const isTv =
displayEntry?.is_tvseries ||
tmdbEntry?.media_type === 'tv' ||
!!tmdbEntry?.name;
const posterUrl = displayEntry
? getPosterUrl(displayEntry)
: tmdbEntry?.poster_path
? `https://image.tmdb.org/t/p/w342${tmdbEntry.poster_path}`
: '/images/default-poster.png';
const entryLink = displayEntry
? `/entry/${displayEntry.id}`
: undefined;
const handleAdd = (e: React.MouseEvent) => {
e.preventDefault();
e.stopPropagation();
if (!tmdbEntry) return;
createEntry.mutate({ tmdb_id: tmdbEntry.id, is_tvserie: isTv });
};
const handleRemove = (e: React.MouseEvent) => {
e.preventDefault();
e.stopPropagation();
setShowConfirm(true);
};
const confirmRemove = () => {
if (libraryEntry) {
deleteEntry.mutate(libraryEntry.id);
}
setShowConfirm(false);
};
const card = (
<div className="group relative overflow-hidden rounded-lg transition-all duration-200 hover:scale-[1.02] hover:shadow-xl">
{/* Poster */}
<div className="relative aspect-[2/3] w-full overflow-hidden rounded-lg bg-muted">
<img
src={posterUrl}
alt={title}
className="h-full w-full object-cover transition-transform duration-300 group-hover:scale-105"
loading="lazy"
/>
{/* Library badge – only on home / search (tmdbEntry context) */}
{isInLibrary && tmdbEntry && (
<Badge className="absolute left-2 top-2 bg-primary text-primary-foreground text-[10px] px-1.5 py-0.5">
In Library
</Badge>
)}
{/* Favorite indicator */}
{libraryEntry?.favorit && (
<Star className="absolute right-2 top-2 h-4 w-4 fill-yellow-400 text-yellow-400" />
)}
{/* Hover overlay */}
<div className="absolute inset-0 flex flex-col justify-end bg-gradient-to-t from-black/90 via-black/40 to-transparent opacity-0 transition-opacity duration-200 group-hover:opacity-100">
<div className="p-3 space-y-1">
<p className="text-sm font-semibold text-white line-clamp-2">
{title}
</p>
<div className="flex items-center gap-2 text-xs text-white/70">
{rating != null && rating > 0 && (
<span className="flex items-center gap-1">
<Star className="h-3 w-3 fill-yellow-400 text-yellow-400" />
{typeof rating === 'number' ? rating.toFixed(1) : rating}
</span>
)}
{year && <span>{year}</span>}
{runtime && <span>{runtime}</span>}
</div>
{/* Actions */}
<div className="pt-1">
{isInLibrary ? (
<Button
size="sm"
variant="destructive"
className="h-7 w-full text-xs"
onClick={handleRemove}
>
<Trash2 className="mr-1 h-3 w-3" />
Remove
</Button>
) : tmdbEntry ? (
<Button
size="sm"
className="h-7 w-full text-xs"
onClick={handleAdd}
disabled={createEntry.isPending}
>
<Plus className="mr-1 h-3 w-3" />
{createEntry.isPending ? 'Adding...' : 'Add to Library'}
</Button>
) : null}
</div>
</div>
</div>
</div>
</div>
);
return (
<>
{entryLink ? <Link to={entryLink}>{card}</Link> : card}
<ConfirmDialog
open={showConfirm}
onOpenChange={setShowConfirm}
title="Remove from Library"
description={`Are you sure you want to remove "${title}" from your library? This action cannot be undone.`}
confirmLabel="Remove"
onConfirm={confirmRemove}
variant="destructive"
/>
</>
);
}
export function EntryCardSkeleton() {
return (
<div className="space-y-2">
<Skeleton className="aspect-[2/3] w-full rounded-lg" />
</div>
);
}