Frontend: UI improvements, dashboard fixes, and settings cleanup

- EntrySeenDialog: native date input, merged date+accuracy row
- EpisodeSeenEditDialog: merged date+accuracy row
- LibraryGrowthChart: use createdAt only, include all entries
- SeasonPage/EpisodePage: max-w-4xl, improved breadcrumbs ("Title / Season x / Episode x"), fixed season number display
- SettingsPage: added Cleanup section for orphan files/media records
- Added maintenance API client
- Updated docs-vault and project documentation
This commit is contained in:
Mohammed Abad committed 2026-04-22 02:08:54 +01:00
1 parent cd695ef4cf
commit 3c4958df50
7 files changed
+233 -88

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
import { api } from '@/lib/api';
export interface OrphanResult {
posters: number;
logos: number;
backdrops: number;
stills: number;
}
export const maintenanceApi = {
scanOrphanFiles: () =>
api.get<OrphanResult>('/maintenance/orphan-files').then((r) => r.data),
deleteOrphanFiles: () =>
api.delete<OrphanResult>('/maintenance/orphan-files').then((r) => r.data),
scanOrphanMediaRecords: () =>
api.get<OrphanResult>('/maintenance/orphan-media-records').then((r) => r.data),
deleteOrphanMediaRecords: () =>
api.delete<OrphanResult>('/maintenance/orphan-media-records').then((r) => r.data),
};
@@ -43,8 +43,8 @@ export function LibraryGrowthChart() {
const allEntries = useLibraryEntries();
const currentYear = new Date().getFullYear();
const getEntryDate = (e: { createdAt?: string; date_first_seen?: string | null }) =>
e.date_first_seen || e.createdAt || null;
const getEntryDate = (e: { createdAt?: string }) =>
e.createdAt || null;
const years = useMemo(() => {
const set = new Set<number>();
@@ -62,11 +62,12 @@ export function LibraryGrowthChart() {
const effectiveYear = year === 'all' ? 'all' : (years.includes(year) ? year : years[0]);
const chartData = useMemo(() => {
const library = allEntries.filter((e) => !e.watchlist);
// Include all entries (library + watchlist)
const entries = allEntries;
if (effectiveYear === 'all') {
// Build monthly data across all years
const dateEntries = library
const dateEntries = entries
.map((e) => {
const d = getEntryDate(e);
return d ? new Date(d) : null;
@@ -100,13 +101,13 @@ export function LibraryGrowthChart() {
return data;
}
const beforeYear = library.filter((e) => {
const beforeYear = entries.filter((e) => {
const d = getEntryDate(e);
return d && new Date(d).getFullYear() < effectiveYear;
}).length;
const monthlyCounts = new Array(12).fill(0);
library.forEach((e) => {
entries.forEach((e) => {
const d = getEntryDate(e);
if (!d) return;
const date = new Date(d);
@@ -3,7 +3,7 @@ import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
import { format } from 'date-fns';
import { CalendarIcon, Loader2 } from 'lucide-react';
import { Loader2 } from 'lucide-react';
import {
Dialog,
DialogContent,
@@ -14,12 +14,6 @@ import {
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import {
Popover,
PopoverContent,
PopoverTrigger,
} from '@/components/ui/popover';
import { Calendar } from '@/components/ui/calendar';
import {
Select,
SelectContent,
@@ -27,7 +21,6 @@ import {
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import { cn } from '@/lib/utils';
import { useCreateEntrySeen, useUpdateEntrySeen } from '@/hooks/useEntrySeen';
import { useCreateEpisodeSeen } from '@/hooks/useEpisodeSeen';
import type { Entry, Season, EntrySeen, SeenAccuracy } from '@/types';
@@ -57,9 +50,6 @@ export function EntrySeenDialog({
mode,
editRecord,
}: EntrySeenDialogProps) {
const [date, setDate] = useState<Date | undefined>(
editRecord?.date_seen ? new Date(editRecord.date_seen) : new Date()
);
const [selectedSeasonId, setSelectedSeasonId] = useState<string>('');
const isTV = entry.is_tvseries;
@@ -196,34 +186,33 @@ export function EntrySeenDialog({
</>
)}
{/* Date picker */}
{/* Date + Accuracy */}
<div className="space-y-2">
<Label>Date Seen</Label>
<Popover>
<PopoverTrigger asChild>
<Button
variant="outline"
className={cn(
'w-full justify-start text-left font-normal',
!date && 'text-muted-foreground'
)}
>
<CalendarIcon className="mr-2 h-4 w-4" />
{date ? format(date, 'PPP') : <span>Pick a date</span>}
</Button>
</PopoverTrigger>
<PopoverContent className="w-auto p-0" align="start">
<Calendar
mode="single"
selected={date}
onSelect={(d) => {
setDate(d);
if (d) setValue('date_seen', format(d, 'yyyy-MM-dd'));
<div className="flex items-center gap-2">
<Input
type="date"
value={watch('date_seen')}
onChange={(e) => {
setValue('date_seen', e.target.value);
setDate(e.target.value ? new Date(e.target.value) : undefined);
}}
initialFocus
className="flex-1"
/>
</PopoverContent>
</Popover>
<Select
value={accuracyValue}
onValueChange={(v) => setValue('accuracy', v as SeenAccuracy)}
>
<SelectTrigger className="w-[120px] shrink-0">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="EXACT">Exact</SelectItem>
<SelectItem value="ESTIMATED">Estimated</SelectItem>
<SelectItem value="UNKNOWN">Unknown</SelectItem>
</SelectContent>
</Select>
</div>
{errors.date_seen && (
<p className="text-xs text-destructive">
{errors.date_seen.message}
@@ -237,24 +226,6 @@ export function EntrySeenDialog({
<Input id="seen_with" {...register('seen_with')} placeholder="e.g. John, Jane" />
</div>
{/* Accuracy */}
<div className="space-y-2">
<Label>Date Accuracy</Label>
<Select
value={accuracyValue}
onValueChange={(v) => setValue('accuracy', v as SeenAccuracy)}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="EXACT">Exact</SelectItem>
<SelectItem value="ESTIMATED">Estimated</SelectItem>
<SelectItem value="UNKNOWN">Unknown</SelectItem>
</SelectContent>
</Select>
</div>
<DialogFooter>
<Button
type="button"
@@ -91,12 +91,25 @@ export function EpisodeSeenEditDialog({
<div className="space-y-4 py-2">
<div className="space-y-1.5">
<Label htmlFor="date">Date Watched</Label>
<div className="flex items-center gap-2">
<Input
id="date"
type="date"
value={date}
onChange={(e) => setDate(e.target.value)}
className="flex-1"
/>
<Select value={accuracy} onValueChange={(v) => setAccuracy(v as SeenAccuracy)}>
<SelectTrigger className="w-[120px] shrink-0">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="EXACT">Exact</SelectItem>
<SelectItem value="ESTIMATED">Estimated</SelectItem>
<SelectItem value="UNKNOWN">Unknown</SelectItem>
</SelectContent>
</Select>
</div>
</div>
<div className="space-y-1.5">
<Label htmlFor="seen-with">Seen With</Label>
@@ -107,19 +120,6 @@ export function EpisodeSeenEditDialog({
placeholder="Optional"
/>
</div>
<div className="space-y-1.5">
<Label>Date Accuracy</Label>
<Select value={accuracy} onValueChange={(v) => setAccuracy(v as SeenAccuracy)}>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="EXACT">Exact</SelectItem>
<SelectItem value="ESTIMATED">Estimated</SelectItem>
<SelectItem value="UNKNOWN">Unknown</SelectItem>
</SelectContent>
</Select>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => onOpenChange(false)}>Cancel</Button>
+15 -7
View File
@@ -2,6 +2,8 @@ import { useState } from 'react';
import { useParams, useNavigate, Link } from 'react-router-dom';
import { useQuery } from '@tanstack/react-query';
import { seasonsApi } from '@/api/seasons';
import { useSeason } from '@/hooks/useSeasons';
import { useLibraryStore } from '@/stores/useLibraryStore';
import {
useEpisodeSeenByEpisode,
useDeleteEpisodeSeen,
@@ -29,6 +31,10 @@ export function EpisodePage() {
queryFn: () => seasonsApi.getEpisodes(parseInt(seasonId!, 10)),
});
const { data: season } = useSeason(parseInt(seasonId!, 10));
const entryTitle = useLibraryStore((s) => s.entries.get(parseInt(entryId!, 10))?.title);
const seasonNumber = season?.season_number;
const epId = parseInt(episodeId!, 10);
const entryIdNum = parseInt(entryId!, 10);
const episode: Episode | undefined = episodes.find((ep: Episode) => ep.id === epId);
@@ -56,29 +62,31 @@ export function EpisodePage() {
}
return (
<div className="space-y-8">
{/* Back navigation */}
<div className="flex items-center gap-3 text-sm text-muted-foreground">
<div className="space-y-8 mx-auto max-w-4xl">
{/* Breadcrumb: Title / Season x / Episode x */}
<div className="flex items-center gap-1.5 text-sm text-muted-foreground">
<Link
to={`/entry/${entryId}`}
className="hover:text-foreground transition-colors"
className="hover:text-foreground transition-colors truncate max-w-50"
>
Entry
{entryTitle || 'Entry'}
</Link>
<span>/</span>
<Link
to={`/entry/${entryId}/season/${seasonId}`}
className="hover:text-foreground transition-colors"
>
Season
Season {seasonNumber ?? '?'}
</Link>
<span>/</span>
<span className="text-foreground font-medium">Episode {episode.episode_number}</span>
</div>
{/* Top bar: nav breadcrumb + Mark Watched */}
<div className="flex items-center justify-between gap-4">
<div className="flex items-center gap-2 text-sm text-muted-foreground">
<span className="font-medium text-foreground">
S{String(parseInt(seasonId!, 10)).padStart(2, '0')} E{String(episode.episode_number).padStart(2, '0')}
S{String(seasonNumber ?? 0).padStart(2, '0')} E{String(episode.episode_number).padStart(2, '0')}
</span>
</div>
<Button size="sm" onClick={() => setShowAddDialog(true)}>
+11 -7
View File
@@ -2,13 +2,13 @@ import { useState } from 'react';
import { useParams, Link } from 'react-router-dom';
import { useSeason, useSeasonEpisodes } from '@/hooks/useSeasons';
import { useCreateEpisodeSeen } from '@/hooks/useEpisodeSeen';
import { useLibraryStore } from '@/stores/useLibraryStore';
import { EpisodeSeenEditDialog } from '@/components/dialogs/EpisodeSeenEditDialog';
import { ConfirmDialog } from '@/components/dialogs/ConfirmDialog';
import { Skeleton } from '@/components/ui/skeleton';
import { Progress } from '@/components/ui/progress';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Eye, CheckCircle2, ListChecks, ArrowLeft } from 'lucide-react';
import { Eye, CheckCircle2, ListChecks } from 'lucide-react';
import { getTmdbPosterUrl, getYear, formatDate } from '@/lib/media-utils';
import type { Episode } from '@/types';
import type { SeenAccuracy } from '@/types';
@@ -21,6 +21,7 @@ export function SeasonPage() {
const { data: season, isLoading } = useSeason(parseInt(seasonId!, 10));
const { data: episodes = [] } = useSeasonEpisodes(parseInt(seasonId!, 10));
const createEpisodeSeen = useCreateEpisodeSeen();
const entryTitle = useLibraryStore((s) => s.entries.get(parseInt(entryId!, 10))?.title);
const [dialogEpisode, setDialogEpisode] = useState<Episode | null>(null);
const [markingAll, setMarkingAll] = useState(false);
const [showMarkAllDialog, setShowMarkAllDialog] = useState(false);
@@ -53,15 +54,18 @@ export function SeasonPage() {
const progress = totalEpisodes > 0 ? (watchedCount / totalEpisodes) * 100 : 0;
return (
<div className="space-y-8 animate-page-enter">
{/* Back to entry */}
<div className="space-y-8 animate-page-enter mx-auto max-w-4xl">
{/* Breadcrumb: Title / Season x */}
<div className="flex items-center gap-1.5 text-sm text-muted-foreground">
<Link
to={`/entry/${entryId}`}
className="inline-flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors"
className="hover:text-foreground transition-colors truncate max-w-50"
>
<ArrowLeft className="h-4 w-4" />
Back to entry
{entryTitle || 'Entry'}
</Link>
<span>/</span>
<span className="text-foreground font-medium">Season {season.season_number}</span>
</div>
{/* Header */}
<div className="flex gap-6">
+141 -2
View File
@@ -1,14 +1,16 @@
import { useState } from 'react';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { settingsApi } from '@/api/settings';
import { maintenanceApi, type OrphanResult } from '@/api/maintenance';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Button } from '@/components/ui/button';
import { Skeleton } from '@/components/ui/skeleton';
import { Save } from 'lucide-react';
import { Save, Search, Trash2, Loader2 } from 'lucide-react';
import type { Settings } from '@/types';
const settingsSchema = z.object({
@@ -16,6 +18,20 @@ const settingsSchema = z.object({
backPort: z.coerce.number().int().positive(),
});
function formatOrphanResult(result: OrphanResult): string {
const parts: string[] = [];
if (result.posters) parts.push(`${result.posters} poster(s)`);
if (result.logos) parts.push(`${result.logos} logo(s)`);
if (result.backdrops) parts.push(`${result.backdrops} backdrop(s)`);
if (result.stills) parts.push(`${result.stills} still(s)`);
return parts.length > 0 ? parts.join(', ') : 'None found';
}
function hasOrphans(result: OrphanResult | null): boolean {
if (!result) return false;
return result.posters + result.logos + result.backdrops + result.stills > 0;
}
export function SettingsPage() {
const queryClient = useQueryClient();
const { data: settings, isLoading } = useQuery({
@@ -30,6 +46,32 @@ export function SettingsPage() {
},
});
// Orphan files cleanup
const [orphanFilesResult, setOrphanFilesResult] = useState<OrphanResult | null>(null);
const scanOrphanFiles = useMutation({
mutationFn: maintenanceApi.scanOrphanFiles,
onSuccess: (data) => setOrphanFilesResult(data),
});
const deleteOrphanFiles = useMutation({
mutationFn: maintenanceApi.deleteOrphanFiles,
onSuccess: (data) => {
setOrphanFilesResult(data);
},
});
// Orphan media records cleanup
const [orphanRecordsResult, setOrphanRecordsResult] = useState<OrphanResult | null>(null);
const scanOrphanRecords = useMutation({
mutationFn: maintenanceApi.scanOrphanMediaRecords,
onSuccess: (data) => setOrphanRecordsResult(data),
});
const deleteOrphanRecords = useMutation({
mutationFn: maintenanceApi.deleteOrphanMediaRecords,
onSuccess: (data) => {
setOrphanRecordsResult(data);
},
});
const {
register,
handleSubmit,
@@ -99,6 +141,103 @@ export function SettingsPage() {
</CardContent>
</Card>
</form>
{/* Cleanup Section */}
<Card>
<CardHeader>
<CardTitle>Cleanup</CardTitle>
<CardDescription>
Scan and remove orphan files or database records that no longer have a matching counterpart.
</CardDescription>
</CardHeader>
<CardContent className="space-y-6">
{/* Orphan Files */}
<div className="space-y-2">
<Label className="text-sm font-medium">Orphan Files</Label>
<p className="text-xs text-muted-foreground">
Files on disk that have no matching database record.
</p>
<div className="flex items-center gap-2">
<Button
variant="outline"
size="sm"
onClick={() => scanOrphanFiles.mutate()}
disabled={scanOrphanFiles.isPending}
>
{scanOrphanFiles.isPending ? (
<Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" />
) : (
<Search className="mr-1.5 h-3.5 w-3.5" />
)}
Scan
</Button>
{hasOrphans(orphanFilesResult) && (
<Button
variant="destructive"
size="sm"
onClick={() => deleteOrphanFiles.mutate()}
disabled={deleteOrphanFiles.isPending}
>
{deleteOrphanFiles.isPending ? (
<Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" />
) : (
<Trash2 className="mr-1.5 h-3.5 w-3.5" />
)}
Delete
</Button>
)}
</div>
{orphanFilesResult && (
<p className="text-xs text-muted-foreground">
{formatOrphanResult(orphanFilesResult)}
</p>
)}
</div>
{/* Orphan Media Records */}
<div className="space-y-2">
<Label className="text-sm font-medium">Orphan Media Records</Label>
<p className="text-xs text-muted-foreground">
Database records that have no matching file on disk.
</p>
<div className="flex items-center gap-2">
<Button
variant="outline"
size="sm"
onClick={() => scanOrphanRecords.mutate()}
disabled={scanOrphanRecords.isPending}
>
{scanOrphanRecords.isPending ? (
<Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" />
) : (
<Search className="mr-1.5 h-3.5 w-3.5" />
)}
Scan
</Button>
{hasOrphans(orphanRecordsResult) && (
<Button
variant="destructive"
size="sm"
onClick={() => deleteOrphanRecords.mutate()}
disabled={deleteOrphanRecords.isPending}
>
{deleteOrphanRecords.isPending ? (
<Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" />
) : (
<Trash2 className="mr-1.5 h-3.5 w-3.5" />
)}
Delete
</Button>
)}
</div>
{orphanRecordsResult && (
<p className="text-xs text-muted-foreground">
{formatOrphanResult(orphanRecordsResult)}
</p>
)}
</div>
</CardContent>
</Card>
</div>
);
}