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
+114 -62

No files matched your search

+18 -8
View File
@@ -1,5 +1,5 @@
const Entry = require("../models/Entry");
const EntrySeen = require("../models/EntrySeen");
const Entry = require('../models/Entry');
const EntrySeen = require('../models/EntrySeen');
class EntrySeenController {
constructor() {
@@ -18,7 +18,7 @@ class EntrySeenController {
const entrySeen = await EntrySeen.findByPk(req.params.id);
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);
@@ -30,7 +30,7 @@ class EntrySeenController {
// ? checking the an entry with the given id does exist
const entry = await Entry.findByPk(entry_id);
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
@@ -39,6 +39,16 @@ class EntrySeenController {
date_seen,
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);
}
@@ -46,7 +56,7 @@ class EntrySeenController {
const { entryId } = req.params;
const entrySeens = await EntrySeen.findAll({
where: { entry_id: entryId },
order: [["date_seen", "DESC"]],
order: [['date_seen', 'DESC']],
});
if (entrySeens.length > 0) {
@@ -54,7 +64,7 @@ class EntrySeenController {
} else {
res
.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);
res.status(200).json(updatedEntrySeen);
} 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);
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();
+27 -17
View File
@@ -1,7 +1,7 @@
const Entry = require("../models/Entry");
const Episode = require("../models/Episode");
const EpisodeSeen = require("../models/EpisodeSeen");
const Season = require("../models/Season");
const Entry = require('../models/Entry');
const Episode = require('../models/Episode');
const EpisodeSeen = require('../models/EpisodeSeen');
const Season = require('../models/Season');
class EpisodeSeenController {
constructor() {
@@ -25,7 +25,7 @@ class EpisodeSeenController {
const episodeSeen = await EpisodeSeen.findByPk(req.params.id);
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);
@@ -39,10 +39,10 @@ class EpisodeSeenController {
const { entry_id, episode_id, date_seen, seen_with } = req.body;
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);
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
const newEpisodeSeen = await EpisodeSeen.create({
@@ -51,6 +51,16 @@ class EpisodeSeenController {
date_seen,
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);
} catch (error) {
res.status(400).json({ error: error.message });
@@ -63,7 +73,7 @@ class EpisodeSeenController {
const { episodeId } = req.params;
const episodeSeens = await EpisodeSeen.findAll({
where: { episode_id: episodeId },
order: [["date_seen", "DESC"]],
order: [['date_seen', 'DESC']],
});
if (episodeSeens.length > 0) {
@@ -71,7 +81,7 @@ class EpisodeSeenController {
} else {
res
.status(404)
.json({ message: "No records found for the given episode ID." });
.json({ message: 'No records found for the given episode ID.' });
}
} catch (error) {
res.status(500).json({ error: error.message });
@@ -89,17 +99,17 @@ class EpisodeSeenController {
include: [
{
model: Season,
attributes: ["season_number"],
attributes: ['season_number'],
},
],
attributes: ["episode_number"],
attributes: ['episode_number'],
},
],
order: [
["date_seen", "DESC"],
[{ model: Episode }, { model: Season }, "season_number", "DESC"],
['date_seen', 'DESC'],
[{ model: Episode }, { model: Season }, 'season_number', 'DESC'],
// [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)
return res
.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 });
if (updated) {
res.status(200).json(updated);
} else {
res.status(404).json({ message: "Episode seen record not found." });
res.status(404).json({ message: 'Episode seen record not found.' });
}
} catch (error) {
res.status(500).json({ error: error.message });
@@ -137,7 +147,7 @@ class EpisodeSeenController {
// ? getting the episode seen object
const oldEpisodeSeen = await EpisodeSeen.findByPk(req.params.id);
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
const deleted = await oldEpisodeSeen.destroy();
@@ -1,20 +1,20 @@
import { Outlet, useLocation } from "react-router-dom";
import { useState, useRef, useEffect } from "react";
import { Menu } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Outlet, useLocation } from 'react-router-dom';
import { useState, useRef, useEffect } from 'react';
import { Menu } from 'lucide-react';
import { Button } from '@/components/ui/button';
import {
Sheet,
SheetContent,
SheetHeader,
SheetTitle,
} from "@/components/ui/sheet";
import { Sidebar, MobileSidebarContent } from "./Sidebar";
import { TitleBar } from "./TitleBar";
import { CommandPalette } from "@/components/CommandPalette";
import { useCommandPaletteStore } from "@/stores/useCommandPaletteStore";
} from '@/components/ui/sheet';
import { Sidebar, MobileSidebarContent } from './Sidebar';
import { TitleBar } from './TitleBar';
import { CommandPalette } from '@/components/CommandPalette';
import { useCommandPaletteStore } from '@/stores/useCommandPaletteStore';
const isElectron =
import.meta.env.VITE_ELECTRON === "true" || !!window.electron?.isElectron;
import.meta.env.VITE_ELECTRON === 'true' || !!window.electron?.isElectron;
export function AppLayout() {
const [mobileOpen, setMobileOpen] = useState(false);
@@ -29,13 +29,13 @@ export function AppLayout() {
// Global keyboard shortcut: Ctrl+P or "/" when not in input
useEffect(() => {
function handleKeyDown(e: KeyboardEvent) {
if ((e.ctrlKey || e.metaKey) && e.key === "p") {
if ((e.ctrlKey || e.metaKey) && e.key === 'p') {
e.preventDefault();
openPalette();
return;
}
if (
e.key === "/" &&
e.key === '/' &&
!e.ctrlKey &&
!e.metaKey &&
!e.altKey &&
@@ -47,8 +47,8 @@ export function AppLayout() {
openPalette();
}
}
document.addEventListener("keydown", handleKeyDown);
return () => document.removeEventListener("keydown", handleKeyDown);
document.addEventListener('keydown', handleKeyDown);
return () => document.removeEventListener('keydown', handleKeyDown);
}, [openPalette]);
return (
@@ -89,7 +89,7 @@ export function AppLayout() {
</Sheet>
<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 />
</div>
</main>
+54 -22
View File
@@ -16,6 +16,7 @@ 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 { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Save, Search, Trash2, Loader2 } from 'lucide-react';
import type { Settings } from '@/types';
@@ -275,9 +276,16 @@ export function SettingsPage() {
}
return (
<div className="space-y-6 max-w-2xl">
<div className="space-y-6">
<h1 className="text-2xl font-bold">Settings</h1>
<Tabs defaultValue="general">
<TabsList>
<TabsTrigger value="general">General</TabsTrigger>
<TabsTrigger value="maintenance">Maintenance</TabsTrigger>
</TabsList>
<TabsContent value="general" className="mt-4">
<form onSubmit={handleSubmit(onSubmit)}>
<Card>
<CardHeader>
@@ -300,7 +308,11 @@ export function SettingsPage() {
<div className="space-y-2">
<Label htmlFor="backPort">Backend Port</Label>
<Input id="backPort" type="number" {...register('backPort')} />
<Input
id="backPort"
type="number"
{...register('backPort')}
/>
{errors.backPort && (
<p className="text-xs text-destructive">
{errors.backPort.message}
@@ -318,18 +330,19 @@ export function SettingsPage() {
</CardContent>
</Card>
</form>
</TabsContent>
{/* Cleanup Section */}
<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.
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">
@@ -372,9 +385,10 @@ export function SettingsPage() {
)}
</div>
{/* Orphan Media Records */}
<div className="space-y-2">
<Label className="text-sm font-medium">Orphan Media Records</Label>
<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>
@@ -417,27 +431,43 @@ export function SettingsPage() {
</CardContent>
</Card>
{/* Missing Directors */}
<Card>
<CardHeader>
<CardTitle>Missing Directors</CardTitle>
<CardTitle>Watch Statuses</CardTitle>
<CardDescription>
Populate the director field for entries that don't have one yet,
using existing credit data.
Auto-fix watch statuses for TV series based on watched
episodes (excl. season 0).
</CardDescription>
</CardHeader>
<CardContent>
<MissingDirectorsSection />
<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>
{/* 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.
Find and remove duplicate credits where the same person
appears multiple times with the same role on the same entry.
</CardDescription>
</CardHeader>
<CardContent>
@@ -445,19 +475,21 @@ export function SettingsPage() {
</CardContent>
</Card>
{/* Watch Statuses */}
<Card>
<CardHeader>
<CardTitle>Watch Statuses</CardTitle>
<CardTitle>Missing Directors</CardTitle>
<CardDescription>
Initialize or auto-fix watch statuses for TV series based on watched
episodes.
Populate the director field for entries that don't have one
yet, using existing credit data.
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<WatchStatusesSection />
<CardContent>
<MissingDirectorsSection />
</CardContent>
</Card>
</div>
</TabsContent>
</Tabs>
</div>
);
}