Auto-upgrade TV status on watch, full-width layout, settings tabs

Marking episode/entry as watched now auto-upgrades TV series from
plan_to_watch/null to watching. Settings page uses tabs (General/Maintenance)
with 2-column grid. AppLayout container removed for full-width pages.
This commit is contained in:
X4Lo committed 2026-06-23 03:53:22 +01:00
1 parent cdbaedd7d0
commit b001ee2240
4 files changed
+267 -215

No files matched your search

+18 -8
View File
@@ -1,5 +1,5 @@
const Entry = require("../models/Entry"); const Entry = require('../models/Entry');
const EntrySeen = require("../models/EntrySeen"); const EntrySeen = require('../models/EntrySeen');
class EntrySeenController { class EntrySeenController {
constructor() { constructor() {
@@ -18,7 +18,7 @@ class EntrySeenController {
const entrySeen = await EntrySeen.findByPk(req.params.id); const entrySeen = await EntrySeen.findByPk(req.params.id);
if (!entrySeen) { if (!entrySeen) {
res.status(404).json({ message: "Entry seen record not found." }); res.status(404).json({ message: 'Entry seen record not found.' });
} }
res.status(200).json(entrySeen); res.status(200).json(entrySeen);
@@ -30,7 +30,7 @@ class EntrySeenController {
// ? checking the an entry with the given id does exist // ? checking the an entry with the given id does exist
const entry = await Entry.findByPk(entry_id); const entry = await Entry.findByPk(entry_id);
if (!entry) { if (!entry) {
return res.status(404).json({ error: "Entry not found" }); return res.status(404).json({ error: 'Entry not found' });
} }
// Create a new EntrySeen record // Create a new EntrySeen record
@@ -39,6 +39,16 @@ class EntrySeenController {
date_seen, date_seen,
seen_with, seen_with,
}); });
// Auto-upgrade TV series status when first watched
if (
entry.is_tvseries &&
(!entry.watch_status || entry.watch_status === 'plan_to_watch')
) {
entry.watch_status = 'watching';
await entry.save();
}
res.status(201).json(newEntrySeen); res.status(201).json(newEntrySeen);
} }
@@ -46,7 +56,7 @@ class EntrySeenController {
const { entryId } = req.params; const { entryId } = req.params;
const entrySeens = await EntrySeen.findAll({ const entrySeens = await EntrySeen.findAll({
where: { entry_id: entryId }, where: { entry_id: entryId },
order: [["date_seen", "DESC"]], order: [['date_seen', 'DESC']],
}); });
if (entrySeens.length > 0) { if (entrySeens.length > 0) {
@@ -54,7 +64,7 @@ class EntrySeenController {
} else { } else {
res res
.status(404) .status(404)
.json({ message: "No records found for the given entry ID." }); .json({ message: 'No records found for the given entry ID.' });
} }
} }
@@ -69,7 +79,7 @@ class EntrySeenController {
const updatedEntrySeen = await EntrySeen.findByPk(req.params.id); const updatedEntrySeen = await EntrySeen.findByPk(req.params.id);
res.status(200).json(updatedEntrySeen); res.status(200).json(updatedEntrySeen);
} else { } else {
res.status(404).json({ message: "Entry seen record not found." }); res.status(404).json({ message: 'Entry seen record not found.' });
} }
} }
@@ -77,7 +87,7 @@ class EntrySeenController {
const entrySeen = await EntrySeen.findByPk(req.params.id); const entrySeen = await EntrySeen.findByPk(req.params.id);
if (!entrySeen) if (!entrySeen)
res.status(404).json({ message: "Entry seen record not found." }); res.status(404).json({ message: 'Entry seen record not found.' });
const deleted = await entrySeen.destroy(); const deleted = await entrySeen.destroy();
+27 -17
View File
@@ -1,7 +1,7 @@
const Entry = require("../models/Entry"); const Entry = require('../models/Entry');
const Episode = require("../models/Episode"); const Episode = require('../models/Episode');
const EpisodeSeen = require("../models/EpisodeSeen"); const EpisodeSeen = require('../models/EpisodeSeen');
const Season = require("../models/Season"); const Season = require('../models/Season');
class EpisodeSeenController { class EpisodeSeenController {
constructor() { constructor() {
@@ -25,7 +25,7 @@ class EpisodeSeenController {
const episodeSeen = await EpisodeSeen.findByPk(req.params.id); const episodeSeen = await EpisodeSeen.findByPk(req.params.id);
if (!episodeSeen) { if (!episodeSeen) {
res.status(404).json({ message: "Episode seen record not found." }); res.status(404).json({ message: 'Episode seen record not found.' });
} }
res.status(200).json(episodeSeen); res.status(200).json(episodeSeen);
@@ -39,10 +39,10 @@ class EpisodeSeenController {
const { entry_id, episode_id, date_seen, seen_with } = req.body; const { entry_id, episode_id, date_seen, seen_with } = req.body;
const entry = await Entry.findByPk(entry_id); const entry = await Entry.findByPk(entry_id);
if (!entry) return res.status(404).json({ error: "Entry not found" }); if (!entry) return res.status(404).json({ error: 'Entry not found' });
const episode = await Episode.findByPk(episode_id); const episode = await Episode.findByPk(episode_id);
if (!episode) return res.status(404).json({ error: "Episode not found" }); if (!episode) return res.status(404).json({ error: 'Episode not found' });
// Create a new EpisodeSeen record // Create a new EpisodeSeen record
const newEpisodeSeen = await EpisodeSeen.create({ const newEpisodeSeen = await EpisodeSeen.create({
@@ -51,6 +51,16 @@ class EpisodeSeenController {
date_seen, date_seen,
seen_with, seen_with,
}); });
// Auto-upgrade: plan_to_watch or null → watching when first episode is marked
if (
entry.is_tvseries &&
(!entry.watch_status || entry.watch_status === 'plan_to_watch')
) {
entry.watch_status = 'watching';
await entry.save();
}
res.status(201).json(newEpisodeSeen); res.status(201).json(newEpisodeSeen);
} catch (error) { } catch (error) {
res.status(400).json({ error: error.message }); res.status(400).json({ error: error.message });
@@ -63,7 +73,7 @@ class EpisodeSeenController {
const { episodeId } = req.params; const { episodeId } = req.params;
const episodeSeens = await EpisodeSeen.findAll({ const episodeSeens = await EpisodeSeen.findAll({
where: { episode_id: episodeId }, where: { episode_id: episodeId },
order: [["date_seen", "DESC"]], order: [['date_seen', 'DESC']],
}); });
if (episodeSeens.length > 0) { if (episodeSeens.length > 0) {
@@ -71,7 +81,7 @@ class EpisodeSeenController {
} else { } else {
res res
.status(404) .status(404)
.json({ message: "No records found for the given episode ID." }); .json({ message: 'No records found for the given episode ID.' });
} }
} catch (error) { } catch (error) {
res.status(500).json({ error: error.message }); res.status(500).json({ error: error.message });
@@ -89,17 +99,17 @@ class EpisodeSeenController {
include: [ include: [
{ {
model: Season, model: Season,
attributes: ["season_number"], attributes: ['season_number'],
}, },
], ],
attributes: ["episode_number"], attributes: ['episode_number'],
}, },
], ],
order: [ order: [
["date_seen", "DESC"], ['date_seen', 'DESC'],
[{ model: Episode }, { model: Season }, "season_number", "DESC"], [{ model: Episode }, { model: Season }, 'season_number', 'DESC'],
// [Sequelize.literal('"Episode->Season"."season_number"'), 'DESC'], // ! or this // [Sequelize.literal('"Episode->Season"."season_number"'), 'DESC'], // ! or this
[Episode, "episode_number", "DESC"], [Episode, 'episode_number', 'DESC'],
], ],
}); });
@@ -118,14 +128,14 @@ class EpisodeSeenController {
if (!episodeSeen) if (!episodeSeen)
return res return res
.status(404) .status(404)
.json({ message: "Episode seen record not found." }); .json({ message: 'Episode seen record not found.' });
const updated = await episodeSeen.update({ date_seen, seen_with }); const updated = await episodeSeen.update({ date_seen, seen_with });
if (updated) { if (updated) {
res.status(200).json(updated); res.status(200).json(updated);
} else { } else {
res.status(404).json({ message: "Episode seen record not found." }); res.status(404).json({ message: 'Episode seen record not found.' });
} }
} catch (error) { } catch (error) {
res.status(500).json({ error: error.message }); res.status(500).json({ error: error.message });
@@ -137,7 +147,7 @@ class EpisodeSeenController {
// ? getting the episode seen object // ? getting the episode seen object
const oldEpisodeSeen = await EpisodeSeen.findByPk(req.params.id); const oldEpisodeSeen = await EpisodeSeen.findByPk(req.params.id);
if (!oldEpisodeSeen) if (!oldEpisodeSeen)
res.status(404).json({ message: "Episode seen record not found." }); res.status(404).json({ message: 'Episode seen record not found.' });
// ?deleting the episode seen // ?deleting the episode seen
const deleted = await oldEpisodeSeen.destroy(); const deleted = await oldEpisodeSeen.destroy();
@@ -1,20 +1,20 @@
import { Outlet, useLocation } from "react-router-dom"; import { Outlet, useLocation } from 'react-router-dom';
import { useState, useRef, useEffect } from "react"; import { useState, useRef, useEffect } from 'react';
import { Menu } from "lucide-react"; import { Menu } from 'lucide-react';
import { Button } from "@/components/ui/button"; import { Button } from '@/components/ui/button';
import { import {
Sheet, Sheet,
SheetContent, SheetContent,
SheetHeader, SheetHeader,
SheetTitle, SheetTitle,
} from "@/components/ui/sheet"; } from '@/components/ui/sheet';
import { Sidebar, MobileSidebarContent } from "./Sidebar"; import { Sidebar, MobileSidebarContent } from './Sidebar';
import { TitleBar } from "./TitleBar"; import { TitleBar } from './TitleBar';
import { CommandPalette } from "@/components/CommandPalette"; import { CommandPalette } from '@/components/CommandPalette';
import { useCommandPaletteStore } from "@/stores/useCommandPaletteStore"; import { useCommandPaletteStore } from '@/stores/useCommandPaletteStore';
const isElectron = const isElectron =
import.meta.env.VITE_ELECTRON === "true" || !!window.electron?.isElectron; import.meta.env.VITE_ELECTRON === 'true' || !!window.electron?.isElectron;
export function AppLayout() { export function AppLayout() {
const [mobileOpen, setMobileOpen] = useState(false); const [mobileOpen, setMobileOpen] = useState(false);
@@ -29,13 +29,13 @@ export function AppLayout() {
// Global keyboard shortcut: Ctrl+P or "/" when not in input // Global keyboard shortcut: Ctrl+P or "/" when not in input
useEffect(() => { useEffect(() => {
function handleKeyDown(e: KeyboardEvent) { function handleKeyDown(e: KeyboardEvent) {
if ((e.ctrlKey || e.metaKey) && e.key === "p") { if ((e.ctrlKey || e.metaKey) && e.key === 'p') {
e.preventDefault(); e.preventDefault();
openPalette(); openPalette();
return; return;
} }
if ( if (
e.key === "/" && e.key === '/' &&
!e.ctrlKey && !e.ctrlKey &&
!e.metaKey && !e.metaKey &&
!e.altKey && !e.altKey &&
@@ -47,8 +47,8 @@ export function AppLayout() {
openPalette(); openPalette();
} }
} }
document.addEventListener("keydown", handleKeyDown); document.addEventListener('keydown', handleKeyDown);
return () => document.removeEventListener("keydown", handleKeyDown); return () => document.removeEventListener('keydown', handleKeyDown);
}, [openPalette]); }, [openPalette]);
return ( return (
@@ -89,7 +89,7 @@ export function AppLayout() {
</Sheet> </Sheet>
<main ref={mainRef} className="flex-1 overflow-y-auto md:ml-20"> <main ref={mainRef} className="flex-1 overflow-y-auto md:ml-20">
<div className="container mx-auto px-4 py-4 pt-18 md:px-6 md:py-6 md:pt-6"> <div className="w-full px-4 py-4 pt-18 md:px-6 md:py-6 md:pt-6">
<Outlet /> <Outlet />
</div> </div>
</main> </main>
+207 -175
View File
@@ -16,6 +16,7 @@ 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 { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Save, Search, Trash2, Loader2 } from 'lucide-react'; import { Save, Search, Trash2, Loader2 } from 'lucide-react';
import type { Settings } from '@/types'; import type { Settings } from '@/types';
@@ -275,189 +276,220 @@ export function SettingsPage() {
} }
return ( return (
<div className="space-y-6 max-w-2xl"> <div className="space-y-6">
<h1 className="text-2xl font-bold">Settings</h1> <h1 className="text-2xl font-bold">Settings</h1>
<form onSubmit={handleSubmit(onSubmit)}> <Tabs defaultValue="general">
<Card> <TabsList>
<CardHeader> <TabsTrigger value="general">General</TabsTrigger>
<CardTitle>General</CardTitle> <TabsTrigger value="maintenance">Maintenance</TabsTrigger>
</CardHeader> </TabsList>
<CardContent className="space-y-4">
<div className="space-y-2">
<Label htmlFor="tmdbApiKey">TMDB API Key</Label>
<Input
id="tmdbApiKey"
type="password"
{...register('tmdbApiKey')}
/>
{errors.tmdbApiKey && (
<p className="text-xs text-destructive">
{errors.tmdbApiKey.message}
</p>
)}
</div>
<div className="space-y-2"> <TabsContent value="general" className="mt-4">
<Label htmlFor="backPort">Backend Port</Label> <form onSubmit={handleSubmit(onSubmit)}>
<Input id="backPort" type="number" {...register('backPort')} /> <Card>
{errors.backPort && ( <CardHeader>
<p className="text-xs text-destructive"> <CardTitle>General</CardTitle>
{errors.backPort.message} </CardHeader>
</p> <CardContent className="space-y-4">
)} <div className="space-y-2">
</div> <Label htmlFor="tmdbApiKey">TMDB API Key</Label>
<Input
<Button id="tmdbApiKey"
type="submit" type="password"
disabled={!isDirty || updateSettings.isPending} {...register('tmdbApiKey')}
> />
<Save className="mr-2 h-4 w-4" /> {errors.tmdbApiKey && (
{updateSettings.isPending ? 'Saving...' : 'Save Settings'} <p className="text-xs text-destructive">
</Button> {errors.tmdbApiKey.message}
</CardContent> </p>
</Card>
</form>
{/* Cleanup Section */}
<Card>
<CardHeader>
<CardTitle>Media 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 </div>
</Button>
)}
</div>
{orphanFilesResult && (
<p className="text-xs text-muted-foreground">
{formatOrphanResult(orphanFilesResult)}
</p>
)}
</div>
{/* Orphan Media Records */} <div className="space-y-2">
<div className="space-y-2"> <Label htmlFor="backPort">Backend Port</Label>
<Label className="text-sm font-medium">Orphan Media Records</Label> <Input
<p className="text-xs text-muted-foreground"> id="backPort"
Database records that have no matching file on disk. type="number"
</p> {...register('backPort')}
<div className="flex items-center gap-2"> />
<Button {errors.backPort && (
variant="outline" <p className="text-xs text-destructive">
size="sm" {errors.backPort.message}
onClick={() => scanOrphanRecords.mutate()} </p>
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 </div>
<Button
type="submit"
disabled={!isDirty || updateSettings.isPending}
>
<Save className="mr-2 h-4 w-4" />
{updateSettings.isPending ? 'Saving...' : 'Save Settings'}
</Button> </Button>
)} </CardContent>
</div> </Card>
{orphanRecordsResult && ( </form>
<p className="text-xs text-muted-foreground"> </TabsContent>
{formatOrphanResult(orphanRecordsResult)}
</p> <TabsContent value="maintenance" className="mt-4">
)} <div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
<Card>
<CardHeader>
<CardTitle>Media 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">
<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>
<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>
<Card>
<CardHeader>
<CardTitle>Watch Statuses</CardTitle>
<CardDescription>
Auto-fix watch statuses for TV series based on watched
episodes (excl. season 0).
</CardDescription>
</CardHeader>
<CardContent>
<ul className="text-xs text-muted-foreground list-disc pl-4 mb-3 space-y-0.5">
<li>
Entries with all episodes watched → set to{' '}
<strong>Completed</strong>
</li>
<li>
Entries marked Completed but missing episodes → downgrade to{' '}
<strong>Watching</strong>
</li>
<li>
Entries with at least one episode watched and no status →
set to <strong>Watching</strong>
</li>
<li>
Entries in Watchlist with no status → set to{' '}
<strong>Plan to Watch</strong>
</li>
</ul>
<WatchStatusesSection />
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle>Duplicate Credits</CardTitle>
<CardDescription>
Find and remove duplicate credits where the same person
appears multiple times with the same role on the same entry.
</CardDescription>
</CardHeader>
<CardContent>
<DuplicateCreditsSection />
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle>Missing Directors</CardTitle>
<CardDescription>
Populate the director field for entries that don't have one
yet, using existing credit data.
</CardDescription>
</CardHeader>
<CardContent>
<MissingDirectorsSection />
</CardContent>
</Card>
</div> </div>
</CardContent> </TabsContent>
</Card> </Tabs>
{/* Missing Directors */}
<Card>
<CardHeader>
<CardTitle>Missing Directors</CardTitle>
<CardDescription>
Populate the director field for entries that don't have one yet,
using existing credit data.
</CardDescription>
</CardHeader>
<CardContent>
<MissingDirectorsSection />
</CardContent>
</Card>
{/* Duplicate Credits */}
<Card>
<CardHeader>
<CardTitle>Duplicate Credits</CardTitle>
<CardDescription>
Find and remove duplicate credits where the same person appears
multiple times with the same role on the same entry.
</CardDescription>
</CardHeader>
<CardContent>
<DuplicateCreditsSection />
</CardContent>
</Card>
{/* Watch Statuses */}
<Card>
<CardHeader>
<CardTitle>Watch Statuses</CardTitle>
<CardDescription>
Initialize or auto-fix watch statuses for TV series based on watched
episodes.
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<WatchStatusesSection />
</CardContent>
</Card>
</div> </div>
); );
} }