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

+125
View File
@@ -0,0 +1,125 @@
import { useState, useMemo } from 'react';
import { useLibrary } from '@/hooks/useEntries';
import { useLibraryEntries } from '@/stores/useLibraryStore';
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Input } from '@/components/ui/input';
import { Skeleton } from '@/components/ui/skeleton';
import { Search } from 'lucide-react';
import { getMediaUrl } from '@/lib/api';
import type { Media } from '@/types';
export function MediaPage() {
const { isLoading } = useLibrary();
const [search, setSearch] = useState('');
const [mediaType, setMediaType] = useState<'all' | 'poster' | 'backdrop' | 'logo'>('all');
const entries = useLibraryEntries();
const allMedias = useMemo(() => {
const medias: (Media & { entryTitle: string })[] = [];
entries.forEach((entry) => {
entry.medias?.forEach((m) => {
medias.push({ ...m, entryTitle: entry.title });
});
});
return medias;
}, [entries]);
const filtered = useMemo(() => {
let result = allMedias;
if (mediaType !== 'all') {
result = result.filter((m) => m.type === mediaType);
}
if (search) {
const q = search.toLowerCase();
result = result.filter((m) => m.entryTitle.toLowerCase().includes(q));
}
return result;
}, [allMedias, mediaType, search]);
return (
<div className="space-y-6">
<h1 className="text-2xl font-bold">Media</h1>
<div className="flex flex-wrap items-center gap-3">
<Tabs
value={mediaType}
onValueChange={(v) => setMediaType(v as typeof mediaType)}
>
<TabsList>
<TabsTrigger value="all">All</TabsTrigger>
<TabsTrigger value="poster">Posters</TabsTrigger>
<TabsTrigger value="backdrop">Backdrops</TabsTrigger>
<TabsTrigger value="logo">Logos</TabsTrigger>
</TabsList>
</Tabs>
<div className="relative flex-1 max-w-xs">
<Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
<Input
placeholder="Search by title..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="pl-10"
/>
</div>
</div>
{isLoading ? (
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
{Array.from({ length: 18 }).map((_, i) => (
<Skeleton
key={i}
className={
mediaType === 'backdrop'
? 'aspect-video w-full rounded-lg'
: 'aspect-[2/3] w-full rounded-lg'
}
/>
))}
</div>
) : filtered.length === 0 ? (
<div className="flex h-40 items-center justify-center text-muted-foreground">
No media found.
</div>
) : (
<div
className={`grid gap-4 ${
mediaType === 'backdrop'
? 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-3'
: 'grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6'
}`}
>
{filtered.map((media) => (
<div
key={media.id}
className="group relative overflow-hidden rounded-lg bg-muted"
>
<img
src={getMediaUrl(
'entries',
`${media.type}s`,
'preview',
media.path
)}
alt={media.entryTitle}
className={`w-full object-cover ${
media.type === 'backdrop' ? 'aspect-video' : 'aspect-[2/3]'
}`}
loading="lazy"
/>
<div className="absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-2 opacity-0 transition-opacity group-hover:opacity-100">
<p className="text-xs text-white truncate">
{media.entryTitle}
</p>
</div>
</div>
))}
</div>
)}
</div>
);
}