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
+245 -100

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