feat: multi-page improvements, bug fixes, and new features
Library: - Exclude hidden entries from all/movies/tv/favorites tabs (only show in hidden tab) Entry Details: - Move favorite, mark watched, and more actions to top-right as icon-only buttons with tooltips - Fix season card play button — marks next unwatched episode as seen Seasons Page: - Fix episode watch button (was a TODO stub, now calls createEpisodeSeen) Episode Page: - Fix UI not updating after deleting the last watch record — invalidate season episodes query on delete Dashboard: - Fix Top Genres 404 — was calling non-existent GET /statistics, now uses /statistics/watch-time - Fix TopGenresChart genre counting (Genre objects were wrongly cast as strings) - Add LibraryGrowthChart (cumulative titles added over time) - Add MediaTypeChart (Movies vs TV Series donut chart) Home Page: - Add TrendingSlider hero at top of page with auto-advance, dots, and prev/next nav - Fix slider prev/next buttons (stable callbacks via ref, plain buttons, reactive library state) - Add debounce (400ms) to search input - Add Top Rated section (movies & TV) - Add Upcoming section (movies) - Replace inline "More" expand with link to /discover/:category Discover Page (new): - Full-page TMDB browser per category (trending/popular/top-rated/upcoming) - Movie/TV tab toggle - IntersectionObserver infinite scroll Calendar: - Fix large season numbers — use season.season_number instead of season_id (DB primary key) Backend: - Add fetchTopRated() and fetchUpcoming() to tmdbService - Add GET /entries/tmdb/top-rated/:type and /entries/tmdb/upcoming/movie routes
This commit is contained in:
1 parent
d60d142d17
commit
ab20a5e64f
23 files changed
+773
-57
No files matched your search
@@ -146,6 +146,23 @@ class EntryController {
|
|||||||
if (!data) return res.status(500).json({ message: 'Failed to search TMDB' });
|
if (!data) return res.status(500).json({ message: 'Failed to search TMDB' });
|
||||||
res.status(200).json(data);
|
res.status(200).json(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// * GET - TMDB TOP RATED
|
||||||
|
getTmdbTopRated = asyncWrapper(async (req, res) => {
|
||||||
|
const { type } = req.params;
|
||||||
|
const { page } = req.query;
|
||||||
|
const data = await tmdbService.fetchTopRated(type, page || 1);
|
||||||
|
if (!data) return res.status(500).json({ message: 'Failed to fetch top rated data' });
|
||||||
|
res.status(200).json(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
// * GET - TMDB UPCOMING
|
||||||
|
getTmdbUpcoming = asyncWrapper(async (req, res) => {
|
||||||
|
const { page } = req.query;
|
||||||
|
const data = await tmdbService.fetchUpcoming(page || 1);
|
||||||
|
if (!data) return res.status(500).json({ message: 'Failed to fetch upcoming data' });
|
||||||
|
res.status(200).json(data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = new EntryController();
|
module.exports = new EntryController();
|
||||||
@@ -14,6 +14,8 @@ const mediaOptimizerService = require('../services/mediaOptimizerService');
|
|||||||
// ! TMDB PROXY ROUTES (must be before /:id to avoid matching)
|
// ! TMDB PROXY ROUTES (must be before /:id to avoid matching)
|
||||||
entryRouter.get('/tmdb/trending/:type', entryController.getTmdbTrending);
|
entryRouter.get('/tmdb/trending/:type', entryController.getTmdbTrending);
|
||||||
entryRouter.get('/tmdb/popular/:type', entryController.getTmdbPopular);
|
entryRouter.get('/tmdb/popular/:type', entryController.getTmdbPopular);
|
||||||
|
entryRouter.get('/tmdb/top-rated/:type', entryController.getTmdbTopRated);
|
||||||
|
entryRouter.get('/tmdb/upcoming/movie', entryController.getTmdbUpcoming);
|
||||||
entryRouter.get('/tmdb/search', entryController.getTmdbSearch);
|
entryRouter.get('/tmdb/search', entryController.getTmdbSearch);
|
||||||
|
|
||||||
entryRouter.get('/sync-series', entryController.syncSeries);
|
entryRouter.get('/sync-series', entryController.syncSeries);
|
||||||
|
|||||||
@@ -173,6 +173,30 @@ async function fetchPopular(type, page = 1) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchTopRated(type, page = 1) {
|
||||||
|
try {
|
||||||
|
let url = `${TMDB_APIURL}${type}/top_rated?api_key=${TMDB_APIKEY}&language=en-US&page=${page}`;
|
||||||
|
logToFile(`Fetching Top Rated ${type} From: ${url}`);
|
||||||
|
const response = await axios.get(url);
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`Error fetching top rated ${type}.`, error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchUpcoming(page = 1) {
|
||||||
|
try {
|
||||||
|
let url = `${TMDB_APIURL}movie/upcoming?api_key=${TMDB_APIKEY}&language=en-US&page=${page}`;
|
||||||
|
logToFile(`Fetching Upcoming Movies From: ${url}`);
|
||||||
|
const response = await axios.get(url);
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.log('Error fetching upcoming movies.', error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function searchMulti(query, page = 1) {
|
async function searchMulti(query, page = 1) {
|
||||||
try {
|
try {
|
||||||
let url = `${TMDB_APIURL}search/multi?api_key=${TMDB_APIKEY}&language=en-US&query=${encodeURIComponent(query)}&page=${page}`;
|
let url = `${TMDB_APIURL}search/multi?api_key=${TMDB_APIKEY}&language=en-US&query=${encodeURIComponent(query)}&page=${page}`;
|
||||||
@@ -231,6 +255,8 @@ module.exports = {
|
|||||||
fetchPersonCombinedCredits,
|
fetchPersonCombinedCredits,
|
||||||
fetchTrending,
|
fetchTrending,
|
||||||
fetchPopular,
|
fetchPopular,
|
||||||
|
fetchTopRated,
|
||||||
|
fetchUpcoming,
|
||||||
searchMulti,
|
searchMulti,
|
||||||
searchPeople,
|
searchPeople,
|
||||||
fetchPopularPeople,
|
fetchPopularPeople,
|
||||||
|
|||||||
@@ -30,8 +30,14 @@ export interface WatchdayDistribution {
|
|||||||
movies: WatchdayItem[];
|
movies: WatchdayItem[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AllTimeWatchTime {
|
||||||
|
series: string | null;
|
||||||
|
movies: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
export const statisticsApi = {
|
export const statisticsApi = {
|
||||||
get: () => api.get('/statistics').then((r) => r.data),
|
getAllTimeWatchTime: () =>
|
||||||
|
api.get<AllTimeWatchTime>('/statistics/watch-time').then((r) => r.data),
|
||||||
getYearlyWatchCount: (year: number) =>
|
getYearlyWatchCount: (year: number) =>
|
||||||
api.get<YearlyWatchCount>(`/statistics/watch-count/year/${year}`).then((r) => r.data),
|
api.get<YearlyWatchCount>(`/statistics/watch-count/year/${year}`).then((r) => r.data),
|
||||||
getYearlyWatchTime: (year: number) =>
|
getYearlyWatchTime: (year: number) =>
|
||||||
|
|||||||
@@ -30,6 +30,27 @@ export const tmdbApi = {
|
|||||||
})
|
})
|
||||||
.then((r) => r.data),
|
.then((r) => r.data),
|
||||||
|
|
||||||
|
getTopRatedMovies: (page = 1) =>
|
||||||
|
api
|
||||||
|
.get<TmdbPaginatedResponse<TmdbEntry>>('/entries/tmdb/top-rated/movie', {
|
||||||
|
params: { page },
|
||||||
|
})
|
||||||
|
.then((r) => r.data),
|
||||||
|
|
||||||
|
getTopRatedTv: (page = 1) =>
|
||||||
|
api
|
||||||
|
.get<TmdbPaginatedResponse<TmdbEntry>>('/entries/tmdb/top-rated/tv', {
|
||||||
|
params: { page },
|
||||||
|
})
|
||||||
|
.then((r) => r.data),
|
||||||
|
|
||||||
|
getUpcomingMovies: (page = 1) =>
|
||||||
|
api
|
||||||
|
.get<TmdbPaginatedResponse<TmdbEntry>>('/entries/tmdb/upcoming/movie', {
|
||||||
|
params: { page },
|
||||||
|
})
|
||||||
|
.then((r) => r.data),
|
||||||
|
|
||||||
search: (query: string, page = 1) =>
|
search: (query: string, page = 1) =>
|
||||||
api
|
api
|
||||||
.get<TmdbPaginatedResponse<TmdbEntry>>('/entries/tmdb/search', {
|
.get<TmdbPaginatedResponse<TmdbEntry>>('/entries/tmdb/search', {
|
||||||
|
|||||||
@@ -0,0 +1,124 @@
|
|||||||
|
import { useMemo, useState } from 'react';
|
||||||
|
import {
|
||||||
|
AreaChart,
|
||||||
|
Area,
|
||||||
|
XAxis,
|
||||||
|
YAxis,
|
||||||
|
CartesianGrid,
|
||||||
|
Tooltip,
|
||||||
|
ResponsiveContainer,
|
||||||
|
} from 'recharts';
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
|
||||||
|
import { useLibraryEntries } from '@/stores/useLibraryStore';
|
||||||
|
|
||||||
|
const MONTH_LABELS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||||
|
|
||||||
|
interface CustomTooltipProps {
|
||||||
|
active?: boolean;
|
||||||
|
payload?: { value: number; payload: { month: string; count: number; cumulative: number } }[];
|
||||||
|
}
|
||||||
|
|
||||||
|
function CustomTooltip({ active, payload }: CustomTooltipProps) {
|
||||||
|
if (!active || !payload?.length) return null;
|
||||||
|
const d = payload[0].payload;
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
backgroundColor: 'var(--color-card)',
|
||||||
|
border: '1px solid var(--color-border)',
|
||||||
|
borderRadius: '8px',
|
||||||
|
padding: '8px 12px',
|
||||||
|
fontSize: '13px',
|
||||||
|
color: 'var(--color-card-foreground)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<p style={{ fontWeight: 600 }}>{d.month}</p>
|
||||||
|
<p style={{ color: 'var(--color-muted-foreground)' }}>+{d.count} added</p>
|
||||||
|
<p style={{ color: 'var(--color-muted-foreground)' }}>{d.cumulative} total</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function LibraryGrowthChart() {
|
||||||
|
const allEntries = useLibraryEntries();
|
||||||
|
const currentYear = new Date().getFullYear();
|
||||||
|
const [year, setYear] = useState(currentYear);
|
||||||
|
|
||||||
|
const years = useMemo(() => {
|
||||||
|
const set = new Set<number>();
|
||||||
|
allEntries.forEach((e) => {
|
||||||
|
if (e.createdAt) set.add(new Date(e.createdAt).getFullYear());
|
||||||
|
});
|
||||||
|
return Array.from(set).sort((a, b) => b - a);
|
||||||
|
}, [allEntries]);
|
||||||
|
|
||||||
|
const chartData = useMemo(() => {
|
||||||
|
const library = allEntries.filter((e) => !e.watchlist);
|
||||||
|
// Count entries added before this year for initial cumulative
|
||||||
|
const beforeYear = library.filter(
|
||||||
|
(e) => e.createdAt && new Date(e.createdAt).getFullYear() < year
|
||||||
|
).length;
|
||||||
|
|
||||||
|
const monthlyCounts = new Array(12).fill(0);
|
||||||
|
library.forEach((e) => {
|
||||||
|
if (!e.createdAt) return;
|
||||||
|
const d = new Date(e.createdAt);
|
||||||
|
if (d.getFullYear() === year) {
|
||||||
|
monthlyCounts[d.getMonth()]++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let cumulative = beforeYear;
|
||||||
|
return MONTH_LABELS.map((label, i) => {
|
||||||
|
cumulative += monthlyCounts[i];
|
||||||
|
return { month: label, count: monthlyCounts[i], cumulative };
|
||||||
|
});
|
||||||
|
}, [allEntries, year]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<div className="flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between">
|
||||||
|
<div>
|
||||||
|
<CardTitle>Library Growth</CardTitle>
|
||||||
|
<CardDescription className="mt-1">
|
||||||
|
Titles added to your library over time
|
||||||
|
</CardDescription>
|
||||||
|
</div>
|
||||||
|
<select
|
||||||
|
value={year}
|
||||||
|
onChange={(e) => setYear(Number(e.target.value))}
|
||||||
|
className="rounded-md border border-border bg-card text-foreground text-xs px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-ring"
|
||||||
|
>
|
||||||
|
{years.map((y) => (
|
||||||
|
<option key={y} value={y}>{y}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<ResponsiveContainer width="100%" height={260}>
|
||||||
|
<AreaChart data={chartData} margin={{ top: 4, right: 8, left: -16, bottom: 0 }}>
|
||||||
|
<defs>
|
||||||
|
<linearGradient id="colorGrowth" x1="0" y1="0" x2="0" y2="1">
|
||||||
|
<stop offset="5%" stopColor="var(--color-chart-4)" stopOpacity={0.3} />
|
||||||
|
<stop offset="95%" stopColor="var(--color-chart-4)" stopOpacity={0} />
|
||||||
|
</linearGradient>
|
||||||
|
</defs>
|
||||||
|
<CartesianGrid strokeDasharray="3 3" stroke="var(--color-border)" />
|
||||||
|
<XAxis dataKey="month" tick={{ fontSize: 12 }} stroke="var(--color-muted-foreground)" />
|
||||||
|
<YAxis tick={{ fontSize: 12 }} stroke="var(--color-muted-foreground)" allowDecimals={false} />
|
||||||
|
<Tooltip content={<CustomTooltip />} />
|
||||||
|
<Area
|
||||||
|
type="monotone"
|
||||||
|
dataKey="cumulative"
|
||||||
|
stroke="var(--color-chart-4)"
|
||||||
|
fill="url(#colorGrowth)"
|
||||||
|
strokeWidth={2}
|
||||||
|
/>
|
||||||
|
</AreaChart>
|
||||||
|
</ResponsiveContainer>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
import { useMemo } from 'react';
|
||||||
|
import {
|
||||||
|
PieChart,
|
||||||
|
Pie,
|
||||||
|
Cell,
|
||||||
|
ResponsiveContainer,
|
||||||
|
Tooltip,
|
||||||
|
Legend,
|
||||||
|
} from 'recharts';
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
|
||||||
|
import { useLibraryEntries } from '@/stores/useLibraryStore';
|
||||||
|
|
||||||
|
const COLORS = ['var(--color-chart-1)', 'var(--color-chart-2)'];
|
||||||
|
|
||||||
|
interface CustomTooltipProps {
|
||||||
|
active?: boolean;
|
||||||
|
payload?: { name: string; value: number }[];
|
||||||
|
}
|
||||||
|
|
||||||
|
function CustomTooltip({ active, payload }: CustomTooltipProps) {
|
||||||
|
if (!active || !payload?.length) return null;
|
||||||
|
const { name, value } = payload[0];
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
backgroundColor: 'var(--color-card)',
|
||||||
|
border: '1px solid var(--color-border)',
|
||||||
|
borderRadius: '8px',
|
||||||
|
padding: '8px 12px',
|
||||||
|
fontSize: '13px',
|
||||||
|
color: 'var(--color-card-foreground)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<p style={{ fontWeight: 600 }}>{name}</p>
|
||||||
|
<p style={{ color: 'var(--color-muted-foreground)' }}>{value} titles</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function MediaTypeChart() {
|
||||||
|
const allEntries = useLibraryEntries();
|
||||||
|
|
||||||
|
const chartData = useMemo(() => {
|
||||||
|
const library = allEntries.filter((e) => !e.watchlist);
|
||||||
|
const movies = library.filter((e) => !e.is_tvseries).length;
|
||||||
|
const tv = library.filter((e) => e.is_tvseries).length;
|
||||||
|
return [
|
||||||
|
{ name: 'Movies', value: movies },
|
||||||
|
{ name: 'TV Series', value: tv },
|
||||||
|
];
|
||||||
|
}, [allEntries]);
|
||||||
|
|
||||||
|
const total = chartData.reduce((s, d) => s + d.value, 0);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Movies vs TV Series</CardTitle>
|
||||||
|
<CardDescription className="mt-1">
|
||||||
|
{total} titles in your library
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<ResponsiveContainer width="100%" height={260}>
|
||||||
|
<PieChart>
|
||||||
|
<Pie
|
||||||
|
data={chartData}
|
||||||
|
cx="50%"
|
||||||
|
cy="50%"
|
||||||
|
innerRadius={60}
|
||||||
|
outerRadius={100}
|
||||||
|
paddingAngle={4}
|
||||||
|
dataKey="value"
|
||||||
|
>
|
||||||
|
{chartData.map((_, index) => (
|
||||||
|
<Cell key={`cell-${index}`} fill={COLORS[index]} />
|
||||||
|
))}
|
||||||
|
</Pie>
|
||||||
|
<Tooltip content={<CustomTooltip />} />
|
||||||
|
<Legend
|
||||||
|
formatter={(value) => (
|
||||||
|
<span style={{ color: 'var(--color-foreground)', fontSize: '13px' }}>{value}</span>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</PieChart>
|
||||||
|
</ResponsiveContainer>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -30,8 +30,10 @@ function buildGenreData(entries: Entry[]) {
|
|||||||
const counts: Record<string, number> = {};
|
const counts: Record<string, number> = {};
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
if (!entry.genres) continue;
|
if (!entry.genres) continue;
|
||||||
for (const genre of entry.genres as unknown as string[]) {
|
for (const genre of entry.genres) {
|
||||||
counts[genre] = (counts[genre] ?? 0) + 1;
|
const name = typeof genre === 'string' ? genre : genre.name;
|
||||||
|
if (!name) continue;
|
||||||
|
counts[name] = (counts[name] ?? 0) + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Object.entries(counts)
|
return Object.entries(counts)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { ChevronDown, ChevronUp, Play } from 'lucide-react';
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Progress } from '@/components/ui/progress';
|
import { Progress } from '@/components/ui/progress';
|
||||||
import { getYear, getTmdbPosterUrl } from '@/lib/media-utils';
|
import { getYear, getTmdbPosterUrl } from '@/lib/media-utils';
|
||||||
|
import { useCreateEpisodeSeen } from '@/hooks/useEpisodeSeen';
|
||||||
import type { Season } from '@/types';
|
import type { Season } from '@/types';
|
||||||
|
|
||||||
interface SeasonsContainerProps {
|
interface SeasonsContainerProps {
|
||||||
@@ -64,6 +65,7 @@ function SeasonItem({
|
|||||||
season: Season;
|
season: Season;
|
||||||
entryId: number;
|
entryId: number;
|
||||||
}) {
|
}) {
|
||||||
|
const createEpisodeSeen = useCreateEpisodeSeen();
|
||||||
const watchedCount =
|
const watchedCount =
|
||||||
season.episodes?.filter(
|
season.episodes?.filter(
|
||||||
(ep) => ep.date_first_seen || (ep.episodeSeens && ep.episodeSeens.length > 0)
|
(ep) => ep.date_first_seen || (ep.episodeSeens && ep.episodeSeens.length > 0)
|
||||||
@@ -71,6 +73,11 @@ function SeasonItem({
|
|||||||
const totalEpisodes = season.episode_count || season.episodes?.length || 0;
|
const totalEpisodes = season.episode_count || season.episodes?.length || 0;
|
||||||
const progress = totalEpisodes > 0 ? (watchedCount / totalEpisodes) * 100 : 0;
|
const progress = totalEpisodes > 0 ? (watchedCount / totalEpisodes) * 100 : 0;
|
||||||
|
|
||||||
|
const nextUnwatched = season.episodes
|
||||||
|
?.slice()
|
||||||
|
.sort((a, b) => a.episode_number - b.episode_number)
|
||||||
|
.find((ep) => !ep.date_first_seen && (!ep.episodeSeens || ep.episodeSeens.length === 0));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
to={`/entry/${entryId}/season/${season.id}`}
|
to={`/entry/${entryId}/season/${season.id}`}
|
||||||
@@ -103,7 +110,7 @@ function SeasonItem({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Quick watch button */}
|
{/* Quick watch button */}
|
||||||
{watchedCount < totalEpisodes && (
|
{nextUnwatched && (
|
||||||
<Button
|
<Button
|
||||||
size="icon"
|
size="icon"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
@@ -111,8 +118,13 @@ function SeasonItem({
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
// TODO: Mark next unwatched episode as seen
|
createEpisodeSeen.mutate({
|
||||||
|
entry_id: entryId,
|
||||||
|
episode_id: nextUnwatched.id,
|
||||||
|
date_seen: new Date().toISOString(),
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
|
disabled={createEpisodeSeen.isPending}
|
||||||
>
|
>
|
||||||
<Play className="h-4 w-4" />
|
<Play className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ interface TrendingGridProps {
|
|||||||
movieEntries: TmdbEntry[];
|
movieEntries: TmdbEntry[];
|
||||||
tvEntries: TmdbEntry[];
|
tvEntries: TmdbEntry[];
|
||||||
isLoading?: boolean;
|
isLoading?: boolean;
|
||||||
moreLink: string;
|
/** Route segment used for the "More" link, e.g. "trending" → /discover/trending */
|
||||||
|
category: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TrendingGrid({
|
export function TrendingGrid({
|
||||||
@@ -19,12 +20,10 @@ export function TrendingGrid({
|
|||||||
movieEntries,
|
movieEntries,
|
||||||
tvEntries,
|
tvEntries,
|
||||||
isLoading,
|
isLoading,
|
||||||
moreLink,
|
category,
|
||||||
}: TrendingGridProps) {
|
}: TrendingGridProps) {
|
||||||
const [activeTab, setActiveTab] = useState<'movie' | 'tv'>('movie');
|
const [activeTab, setActiveTab] = useState<'movie' | 'tv'>('movie');
|
||||||
const entries = activeTab === 'movie' ? movieEntries : tvEntries;
|
const entries = activeTab === 'movie' ? movieEntries : tvEntries;
|
||||||
|
|
||||||
// Limit to 2 rows (14 items for a 7-column grid)
|
|
||||||
const displayEntries = entries.slice(0, 14);
|
const displayEntries = entries.slice(0, 14);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -45,11 +44,13 @@ export function TrendingGrid({
|
|||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
</TabsList>
|
</TabsList>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
<Button variant="ghost" size="sm" asChild>
|
<Link
|
||||||
<Link to={moreLink}>
|
to={`/discover/${category}`}
|
||||||
More <ChevronRight className="ml-1 h-4 w-4" />
|
className="inline-flex items-center gap-1 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors"
|
||||||
|
>
|
||||||
|
More
|
||||||
|
<ChevronRight className="h-4 w-4" />
|
||||||
</Link>
|
</Link>
|
||||||
</Button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,151 @@
|
|||||||
|
import { useState, useEffect, useCallback, useRef } from 'react';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
import { ChevronLeft, ChevronRight, Star } from 'lucide-react';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { useCreateEntry } from '@/hooks/useEntries';
|
||||||
|
import { useLibraryStore } from '@/stores/useLibraryStore';
|
||||||
|
import type { TmdbEntry } from '@/types';
|
||||||
|
|
||||||
|
interface TrendingSliderProps {
|
||||||
|
entries: TmdbEntry[];
|
||||||
|
isLoading?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TrendingSlider({ entries, isLoading }: TrendingSliderProps) {
|
||||||
|
const [currentIndex, setCurrentIndex] = useState(0);
|
||||||
|
const createEntry = useCreateEntry();
|
||||||
|
const display = entries.slice(0, 10);
|
||||||
|
const countRef = useRef(display.length);
|
||||||
|
countRef.current = display.length;
|
||||||
|
|
||||||
|
const next = useCallback(() => {
|
||||||
|
if (countRef.current === 0) return;
|
||||||
|
setCurrentIndex((i) => (i + 1) % countRef.current);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const prev = useCallback(() => {
|
||||||
|
if (countRef.current === 0) return;
|
||||||
|
setCurrentIndex((i) => (i - 1 + countRef.current) % countRef.current);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Reset index when entries change so it stays in range
|
||||||
|
useEffect(() => {
|
||||||
|
setCurrentIndex(0);
|
||||||
|
}, [entries.length]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (display.length === 0) return;
|
||||||
|
const timer = setInterval(next, 6000);
|
||||||
|
return () => clearInterval(timer);
|
||||||
|
}, [next, display.length]);
|
||||||
|
|
||||||
|
if (isLoading || display.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className="relative h-85 sm:h-100 rounded-2xl bg-muted animate-pulse" />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const safeIndex = currentIndex < display.length ? currentIndex : 0;
|
||||||
|
const item = display[safeIndex];
|
||||||
|
const title = item.title || item.name || 'Untitled';
|
||||||
|
const backdropUrl = item.backdrop_path
|
||||||
|
? `https://image.tmdb.org/t/p/w1280${item.backdrop_path}`
|
||||||
|
: null;
|
||||||
|
const isTv = item.media_type === 'tv' || !!item.name;
|
||||||
|
|
||||||
|
const libraryEntries = useLibraryStore((s) => s.entries);
|
||||||
|
const matchedEntry = Array.from(libraryEntries.values()).find(
|
||||||
|
(e) => e.entryIds?.tmdb_id === item.id
|
||||||
|
);
|
||||||
|
const isInLibrary = !!matchedEntry;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="relative h-85 sm:h-100 rounded-2xl overflow-hidden group">
|
||||||
|
{/* Backdrop */}
|
||||||
|
{backdropUrl ? (
|
||||||
|
<img
|
||||||
|
src={backdropUrl}
|
||||||
|
alt=""
|
||||||
|
className="absolute inset-0 h-full w-full object-cover transition-transform duration-700 group-hover:scale-105"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="absolute inset-0 bg-linear-to-br from-primary/20 to-primary/5" />
|
||||||
|
)}
|
||||||
|
<div className="absolute inset-0 bg-linear-to-t from-black/90 via-black/40 to-transparent" />
|
||||||
|
|
||||||
|
{/* Nav arrows */}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="absolute left-3 top-1/2 -translate-y-1/2 z-20 h-10 w-10 rounded-full bg-black/40 text-white hover:bg-black/60 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center cursor-pointer"
|
||||||
|
onClick={(e) => { e.stopPropagation(); prev(); }}
|
||||||
|
>
|
||||||
|
<ChevronLeft className="h-5 w-5" />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="absolute right-3 top-1/2 -translate-y-1/2 z-20 h-10 w-10 rounded-full bg-black/40 text-white hover:bg-black/60 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center cursor-pointer"
|
||||||
|
onClick={(e) => { e.stopPropagation(); next(); }}
|
||||||
|
>
|
||||||
|
<ChevronRight className="h-5 w-5" />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{/* Content overlay */}
|
||||||
|
<div className="absolute bottom-0 left-0 right-0 p-6 sm:p-8 z-10">
|
||||||
|
<div className="max-w-2xl space-y-3">
|
||||||
|
<div className="flex items-center gap-2 text-white/70 text-sm">
|
||||||
|
<span className="uppercase font-medium tracking-wider text-xs bg-white/20 backdrop-blur-sm px-2 py-0.5 rounded">
|
||||||
|
{isTv ? 'TV Series' : 'Movie'}
|
||||||
|
</span>
|
||||||
|
{item.vote_average > 0 && (
|
||||||
|
<span className="flex items-center gap-1">
|
||||||
|
<Star className="h-3.5 w-3.5 fill-yellow-400 text-yellow-400" />
|
||||||
|
{item.vote_average.toFixed(1)}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<h2 className="text-2xl sm:text-4xl font-bold text-white leading-tight">
|
||||||
|
{title}
|
||||||
|
</h2>
|
||||||
|
{item.overview && (
|
||||||
|
<p className="text-sm text-white/80 line-clamp-2 max-w-xl">
|
||||||
|
{item.overview}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<div className="flex items-center gap-3 pt-1">
|
||||||
|
{isInLibrary && matchedEntry ? (
|
||||||
|
<Link to={`/entry/${matchedEntry.id}`}>
|
||||||
|
<Button size="sm" className="rounded-full px-5">
|
||||||
|
View Details
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
className="rounded-full px-5"
|
||||||
|
onClick={() => createEntry.mutate({ tmdb_id: item.id, is_tvserie: isTv })}
|
||||||
|
disabled={createEntry.isPending}
|
||||||
|
>
|
||||||
|
Add to Library
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Dots */}
|
||||||
|
<div className="absolute bottom-3 right-6 flex gap-1.5 z-10">
|
||||||
|
{display.map((_, i) => (
|
||||||
|
<button
|
||||||
|
key={i}
|
||||||
|
onClick={() => setCurrentIndex(i)}
|
||||||
|
className={`h-1.5 rounded-full transition-all ${
|
||||||
|
i === currentIndex
|
||||||
|
? 'w-6 bg-white'
|
||||||
|
: 'w-1.5 bg-white/40 hover:bg-white/60'
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { episodeSeenApi } from '@/api/episode-seen';
|
import { episodeSeenApi } from '@/api/episode-seen';
|
||||||
import { entryKeys } from './useEntries';
|
import { entryKeys } from './useEntries';
|
||||||
|
import { seasonKeys } from './useSeasons';
|
||||||
|
|
||||||
export const episodeSeenKeys = {
|
export const episodeSeenKeys = {
|
||||||
all: ['episode-seen'] as const,
|
all: ['episode-seen'] as const,
|
||||||
@@ -83,6 +84,7 @@ export function useDeleteEpisodeSeen() {
|
|||||||
id: number;
|
id: number;
|
||||||
entryId: number;
|
entryId: number;
|
||||||
episodeId: number;
|
episodeId: number;
|
||||||
|
seasonId?: number;
|
||||||
}) => episodeSeenApi.delete(id),
|
}) => episodeSeenApi.delete(id),
|
||||||
onSuccess: (_data, variables) => {
|
onSuccess: (_data, variables) => {
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
@@ -91,6 +93,14 @@ export function useDeleteEpisodeSeen() {
|
|||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: entryKeys.detail(variables.entryId),
|
queryKey: entryKeys.detail(variables.entryId),
|
||||||
});
|
});
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: entryKeys.seasons(variables.entryId),
|
||||||
|
});
|
||||||
|
if (variables.seasonId) {
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: seasonKeys.episodes(variables.seasonId),
|
||||||
|
});
|
||||||
|
}
|
||||||
toast.success('Episode watch record removed');
|
toast.success('Episode watch record removed');
|
||||||
},
|
},
|
||||||
onError: () => {
|
onError: () => {
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import { statisticsApi } from '@/api/statistics';
|
|||||||
|
|
||||||
export function useStatistics() {
|
export function useStatistics() {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['statistics'],
|
queryKey: ['statistics', 'watch-time-all'],
|
||||||
queryFn: statisticsApi.get,
|
queryFn: statisticsApi.getAllTimeWatchTime,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,36 @@ export function useTrendingTv() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useTopRatedMovies() {
|
||||||
|
return useInfiniteQuery({
|
||||||
|
queryKey: ['tmdb', 'top-rated', 'movie'],
|
||||||
|
queryFn: ({ pageParam }) => tmdbApi.getTopRatedMovies(pageParam),
|
||||||
|
initialPageParam: 1,
|
||||||
|
getNextPageParam: (lastPage) =>
|
||||||
|
lastPage.page < lastPage.total_pages ? lastPage.page + 1 : undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useTopRatedTv() {
|
||||||
|
return useInfiniteQuery({
|
||||||
|
queryKey: ['tmdb', 'top-rated', 'tv'],
|
||||||
|
queryFn: ({ pageParam }) => tmdbApi.getTopRatedTv(pageParam),
|
||||||
|
initialPageParam: 1,
|
||||||
|
getNextPageParam: (lastPage) =>
|
||||||
|
lastPage.page < lastPage.total_pages ? lastPage.page + 1 : undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useUpcomingMovies() {
|
||||||
|
return useInfiniteQuery({
|
||||||
|
queryKey: ['tmdb', 'upcoming', 'movie'],
|
||||||
|
queryFn: ({ pageParam }) => tmdbApi.getUpcomingMovies(pageParam),
|
||||||
|
initialPageParam: 1,
|
||||||
|
getNextPageParam: (lastPage) =>
|
||||||
|
lastPage.page < lastPage.total_pages ? lastPage.page + 1 : undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function useTmdbSearch(query: string) {
|
export function useTmdbSearch(query: string) {
|
||||||
return useInfiniteQuery({
|
return useInfiniteQuery({
|
||||||
queryKey: ['tmdb', 'search', query],
|
queryKey: ['tmdb', 'search', query],
|
||||||
|
|||||||
@@ -130,8 +130,11 @@ function EpisodeCalendarItem({ episode }: { episode: Episode }) {
|
|||||||
const entryId = entry?.id;
|
const entryId = entry?.id;
|
||||||
const entryTitle = entry?.title ?? '';
|
const entryTitle = entry?.title ?? '';
|
||||||
const seasonId = episode.season_id;
|
const seasonId = episode.season_id;
|
||||||
|
const seasonNumber = episode.season?.season_number ?? null;
|
||||||
|
|
||||||
const seasonLabel = `S${String(seasonId).padStart(2, '0')}`;
|
const seasonLabel = seasonNumber != null
|
||||||
|
? `S${String(seasonNumber).padStart(2, '0')}`
|
||||||
|
: '';
|
||||||
const episodeLabel = `E${String(episode.episode_number).padStart(2, '0')}`;
|
const episodeLabel = `E${String(episode.episode_number).padStart(2, '0')}`;
|
||||||
|
|
||||||
const thumbSrc = episode.still_path
|
const thumbSrc = episode.still_path
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import { WatchTimeChart } from '@/components/dashboard/WatchTimeChart';
|
|||||||
import { RatingsChart } from '@/components/dashboard/RatingsChart';
|
import { RatingsChart } from '@/components/dashboard/RatingsChart';
|
||||||
import { TopGenresChart } from '@/components/dashboard/TopGenresChart';
|
import { TopGenresChart } from '@/components/dashboard/TopGenresChart';
|
||||||
import { CouchDayChart } from '@/components/dashboard/CouchDayChart';
|
import { CouchDayChart } from '@/components/dashboard/CouchDayChart';
|
||||||
|
import { LibraryGrowthChart } from '@/components/dashboard/LibraryGrowthChart';
|
||||||
|
import { MediaTypeChart } from '@/components/dashboard/MediaTypeChart';
|
||||||
|
|
||||||
export function DashboardPage() {
|
export function DashboardPage() {
|
||||||
useLibrary();
|
useLibrary();
|
||||||
@@ -51,8 +53,8 @@ export function DashboardPage() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Watch Time',
|
title: 'Watch Time',
|
||||||
value: stats?.totalWatchTime
|
value: stats
|
||||||
? formatRuntime(stats.totalWatchTime)
|
? formatRuntime((parseInt(stats.series || '0') || 0) + (parseInt(stats.movies || '0') || 0))
|
||||||
: '0h',
|
: '0h',
|
||||||
icon: Clock,
|
icon: Clock,
|
||||||
color: 'text-orange-500',
|
color: 'text-orange-500',
|
||||||
@@ -91,7 +93,11 @@ export function DashboardPage() {
|
|||||||
<RatingsChart />
|
<RatingsChart />
|
||||||
<TopGenresChart />
|
<TopGenresChart />
|
||||||
</div>
|
</div>
|
||||||
|
<div className="grid gap-4 lg:grid-cols-2">
|
||||||
<CouchDayChart />
|
<CouchDayChart />
|
||||||
|
<MediaTypeChart />
|
||||||
|
</div>
|
||||||
|
<LibraryGrowthChart />
|
||||||
|
|
||||||
{/* Recently Watched */}
|
{/* Recently Watched */}
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
|
|||||||
@@ -0,0 +1,132 @@
|
|||||||
|
import { useState, useEffect, useRef, useCallback } from 'react';
|
||||||
|
import { useParams } from 'react-router-dom';
|
||||||
|
import { useInfiniteQuery } from '@tanstack/react-query';
|
||||||
|
import { tmdbApi } from '@/api/tmdb';
|
||||||
|
import { useLibrary } from '@/hooks/useEntries';
|
||||||
|
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||||
|
import { EntryCard, EntryCardSkeleton } from '@/components/entries/EntryCard';
|
||||||
|
import { Loader2 } from 'lucide-react';
|
||||||
|
import type { TmdbEntry, TmdbPaginatedResponse } from '@/types';
|
||||||
|
|
||||||
|
const CATEGORY_LABELS: Record<string, string> = {
|
||||||
|
trending: 'Trending',
|
||||||
|
popular: 'Popular',
|
||||||
|
'top-rated': 'Top Rated',
|
||||||
|
upcoming: 'Upcoming',
|
||||||
|
};
|
||||||
|
|
||||||
|
type MediaTab = 'movie' | 'tv';
|
||||||
|
|
||||||
|
function useCategoryQuery(category: string, mediaType: MediaTab) {
|
||||||
|
return useInfiniteQuery<TmdbPaginatedResponse<TmdbEntry>>({
|
||||||
|
queryKey: ['tmdb', category, mediaType],
|
||||||
|
queryFn: ({ pageParam }) => {
|
||||||
|
const page = pageParam as number;
|
||||||
|
switch (category) {
|
||||||
|
case 'trending':
|
||||||
|
return mediaType === 'movie'
|
||||||
|
? tmdbApi.getTrendingMovies(page)
|
||||||
|
: tmdbApi.getTrendingTv(page);
|
||||||
|
case 'popular':
|
||||||
|
return mediaType === 'movie'
|
||||||
|
? tmdbApi.getPopularMovies(page)
|
||||||
|
: tmdbApi.getPopularTv(page);
|
||||||
|
case 'top-rated':
|
||||||
|
return mediaType === 'movie'
|
||||||
|
? tmdbApi.getTopRatedMovies(page)
|
||||||
|
: tmdbApi.getTopRatedTv(page);
|
||||||
|
case 'upcoming':
|
||||||
|
return tmdbApi.getUpcomingMovies(page);
|
||||||
|
default:
|
||||||
|
return tmdbApi.getPopularMovies(page);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
initialPageParam: 1,
|
||||||
|
getNextPageParam: (lastPage) =>
|
||||||
|
lastPage.page < lastPage.total_pages ? lastPage.page + 1 : undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DiscoverPage() {
|
||||||
|
const { category = 'trending' } = useParams<{ category: string }>();
|
||||||
|
const [mediaType, setMediaType] = useState<MediaTab>('movie');
|
||||||
|
const sentinelRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
useLibrary();
|
||||||
|
|
||||||
|
const isUpcoming = category === 'upcoming';
|
||||||
|
const query = useCategoryQuery(category, mediaType);
|
||||||
|
const entries = query.data?.pages.flatMap((p) => p.results) ?? [];
|
||||||
|
|
||||||
|
// Infinite scroll via IntersectionObserver
|
||||||
|
const handleIntersect = useCallback(
|
||||||
|
(entries: IntersectionObserverEntry[]) => {
|
||||||
|
if (entries[0]?.isIntersecting && query.hasNextPage && !query.isFetchingNextPage) {
|
||||||
|
query.fetchNextPage();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[query.hasNextPage, query.isFetchingNextPage, query.fetchNextPage],
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const el = sentinelRef.current;
|
||||||
|
if (!el) return;
|
||||||
|
const observer = new IntersectionObserver(handleIntersect, { rootMargin: '400px' });
|
||||||
|
observer.observe(el);
|
||||||
|
return () => observer.disconnect();
|
||||||
|
}, [handleIntersect]);
|
||||||
|
|
||||||
|
const title = CATEGORY_LABELS[category] || 'Discover';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6 animate-page-enter">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<h1 className="text-2xl font-bold">{title}</h1>
|
||||||
|
{!isUpcoming && (
|
||||||
|
<Tabs
|
||||||
|
value={mediaType}
|
||||||
|
onValueChange={(v) => setMediaType(v as MediaTab)}
|
||||||
|
>
|
||||||
|
<TabsList className="h-8">
|
||||||
|
<TabsTrigger value="movie" className="text-xs px-3">
|
||||||
|
Movies
|
||||||
|
</TabsTrigger>
|
||||||
|
<TabsTrigger value="tv" className="text-xs px-3">
|
||||||
|
TV Series
|
||||||
|
</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
</Tabs>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{query.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 2xl:grid-cols-7">
|
||||||
|
{Array.from({ length: 21 }).map((_, i) => (
|
||||||
|
<EntryCardSkeleton key={i} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : entries.length === 0 ? (
|
||||||
|
<p className="text-muted-foreground">No results found.</p>
|
||||||
|
) : (
|
||||||
|
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 2xl:grid-cols-7">
|
||||||
|
{entries.map((entry, index) => (
|
||||||
|
<div
|
||||||
|
key={`${entry.id}-${index}`}
|
||||||
|
className="animate-card-enter"
|
||||||
|
style={{ animationDelay: `${Math.min(index * 20, 300)}ms` }}
|
||||||
|
>
|
||||||
|
<EntryCard tmdbEntry={entry} />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Infinite scroll sentinel */}
|
||||||
|
<div ref={sentinelRef} className="flex justify-center py-4">
|
||||||
|
{query.isFetchingNextPage && (
|
||||||
|
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -107,49 +107,50 @@ export function EntryDetailsPage() {
|
|||||||
|
|
||||||
{/* Main content */}
|
{/* Main content */}
|
||||||
<div className="mx-auto max-w-4xl">
|
<div className="mx-auto max-w-4xl">
|
||||||
{/* Two-column header: sticky poster | info */}
|
{/* Action buttons — top right */}
|
||||||
<div className="flex flex-col gap-6 -mt-16 relative items-start sm:flex-row sm:gap-8 sm:-mt-24">
|
<div className="flex justify-end gap-1 -mt-10 relative z-10 mb-2">
|
||||||
{/* LEFT: Sticky poster + actions */}
|
<TooltipProvider>
|
||||||
<div className="sm:sticky sm:top-20 w-32 sm:w-44 shrink-0 space-y-3 self-start mx-auto sm:mx-0">
|
<Tooltip>
|
||||||
<img
|
<TooltipTrigger asChild>
|
||||||
src={poster}
|
|
||||||
alt={e.title}
|
|
||||||
className="w-full aspect-2/3 rounded-xl object-cover shadow-2xl ring-1 ring-border/50"
|
|
||||||
/>
|
|
||||||
<div className="flex flex-col gap-2">
|
|
||||||
<Button
|
<Button
|
||||||
variant={e.favorit ? 'default' : 'outline'}
|
variant={e.favorit ? 'default' : 'outline'}
|
||||||
size="sm"
|
size="icon"
|
||||||
className="w-full justify-start"
|
className="h-9 w-9"
|
||||||
onClick={toggleFavorite}
|
onClick={toggleFavorite}
|
||||||
disabled={updateEntry.isPending}
|
disabled={updateEntry.isPending}
|
||||||
>
|
>
|
||||||
{updateEntry.isPending ? (
|
{updateEntry.isPending ? (
|
||||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
<Loader2 className="h-4 w-4 animate-spin" />
|
||||||
) : (
|
) : (
|
||||||
<Heart className={`mr-2 h-4 w-4 ${e.favorit ? 'fill-current' : ''}`} />
|
<Heart className={`h-4 w-4 ${e.favorit ? 'fill-current' : ''}`} />
|
||||||
)}
|
)}
|
||||||
{e.favorit ? 'Favorited' : 'Favorite'}
|
|
||||||
</Button>
|
</Button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>{e.favorit ? 'Unfavorite' : 'Favorite'}</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="icon"
|
||||||
className="w-full justify-start"
|
className="h-9 w-9"
|
||||||
onClick={() => setShowSeenDialog(true)}
|
onClick={() => setShowSeenDialog(true)}
|
||||||
>
|
>
|
||||||
<Eye className="mr-2 h-4 w-4" />
|
<Eye className="h-4 w-4" />
|
||||||
Mark Watched
|
|
||||||
</Button>
|
</Button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>Mark Watched</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</TooltipProvider>
|
||||||
|
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<Button variant="ghost" size="sm" className="w-full justify-start">
|
<Button variant="ghost" size="icon" className="h-9 w-9">
|
||||||
<MoreHorizontal className="mr-2 h-4 w-4" />
|
<MoreHorizontal className="h-4 w-4" />
|
||||||
More actions
|
|
||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="start" side="right" className="w-56">
|
<DropdownMenuContent align="end" className="w-56">
|
||||||
<DropdownMenuItem onClick={() => setShowRatingDialog(true)}>
|
<DropdownMenuItem onClick={() => setShowRatingDialog(true)}>
|
||||||
<Star className="mr-2 h-4 w-4" />
|
<Star className="mr-2 h-4 w-4" />
|
||||||
Rate this
|
Rate this
|
||||||
@@ -181,6 +182,16 @@ export function EntryDetailsPage() {
|
|||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Two-column header: sticky poster | info */}
|
||||||
|
<div className="flex flex-col gap-6 relative items-start sm:flex-row sm:gap-8 sm:-mt-8">
|
||||||
|
{/* LEFT: Sticky poster */}
|
||||||
|
<div className="sm:sticky sm:top-20 w-32 sm:w-44 shrink-0 self-start mx-auto sm:mx-0">
|
||||||
|
<img
|
||||||
|
src={poster}
|
||||||
|
alt={e.title}
|
||||||
|
className="w-full aspect-2/3 rounded-xl object-cover shadow-2xl ring-1 ring-border/50"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* RIGHT: Entry info */}
|
{/* RIGHT: Entry info */}
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ export function EpisodePage() {
|
|||||||
variant="destructive"
|
variant="destructive"
|
||||||
onConfirm={() => {
|
onConfirm={() => {
|
||||||
if (deleteTarget !== null) {
|
if (deleteTarget !== null) {
|
||||||
deleteEpisodeSeen.mutate({ id: deleteTarget, entryId: entryIdNum, episodeId: epId });
|
deleteEpisodeSeen.mutate({ id: deleteTarget, entryId: entryIdNum, episodeId: epId, seasonId: parseInt(seasonId!, 10) });
|
||||||
setDeleteTarget(null);
|
setDeleteTarget(null);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -1,13 +1,35 @@
|
|||||||
import { useTrendingMovies, useTrendingTv, usePopularMovies, usePopularTv, useTmdbSearch } from '@/hooks/useTmdb';
|
import {
|
||||||
|
useTrendingMovies,
|
||||||
|
useTrendingTv,
|
||||||
|
usePopularMovies,
|
||||||
|
usePopularTv,
|
||||||
|
useTopRatedMovies,
|
||||||
|
useTopRatedTv,
|
||||||
|
useUpcomingMovies,
|
||||||
|
useTmdbSearch,
|
||||||
|
} from '@/hooks/useTmdb';
|
||||||
import { useLibrary } from '@/hooks/useEntries';
|
import { useLibrary } from '@/hooks/useEntries';
|
||||||
import { TrendingGrid } from '@/components/entries/TrendingGrid';
|
import { TrendingGrid } from '@/components/entries/TrendingGrid';
|
||||||
|
import { TrendingSlider } from '@/components/entries/TrendingSlider';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { useState } from 'react';
|
import { useState, useEffect, useRef } from 'react';
|
||||||
import { Search } from 'lucide-react';
|
import { Search } from 'lucide-react';
|
||||||
import { EntryCard } from '@/components/entries/EntryCard';
|
import { EntryCard } from '@/components/entries/EntryCard';
|
||||||
|
|
||||||
export function HomePage() {
|
export function HomePage() {
|
||||||
const [searchQuery, setSearchQuery] = useState('');
|
const [searchInput, setSearchInput] = useState('');
|
||||||
|
const [debouncedQuery, setDebouncedQuery] = useState('');
|
||||||
|
const debounceRef = useRef<ReturnType<typeof setTimeout>>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
||||||
|
debounceRef.current = setTimeout(() => {
|
||||||
|
setDebouncedQuery(searchInput);
|
||||||
|
}, 400);
|
||||||
|
return () => {
|
||||||
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
||||||
|
};
|
||||||
|
}, [searchInput]);
|
||||||
|
|
||||||
// Pre-load library
|
// Pre-load library
|
||||||
useLibrary();
|
useLibrary();
|
||||||
@@ -16,25 +38,39 @@ export function HomePage() {
|
|||||||
const trendingTv = useTrendingTv();
|
const trendingTv = useTrendingTv();
|
||||||
const popularMovies = usePopularMovies();
|
const popularMovies = usePopularMovies();
|
||||||
const popularTv = usePopularTv();
|
const popularTv = usePopularTv();
|
||||||
const searchResults = useTmdbSearch(searchQuery);
|
const topRatedMovies = useTopRatedMovies();
|
||||||
|
const topRatedTv = useTopRatedTv();
|
||||||
|
const upcomingMovies = useUpcomingMovies();
|
||||||
|
const searchResults = useTmdbSearch(debouncedQuery);
|
||||||
|
|
||||||
const trendingMovieEntries = trendingMovies.data?.pages.flatMap((p) => p.results) ?? [];
|
const trendingMovieEntries = trendingMovies.data?.pages.flatMap((p) => p.results) ?? [];
|
||||||
const trendingTvEntries = trendingTv.data?.pages.flatMap((p) => p.results) ?? [];
|
const trendingTvEntries = trendingTv.data?.pages.flatMap((p) => p.results) ?? [];
|
||||||
const popularMovieEntries = popularMovies.data?.pages.flatMap((p) => p.results) ?? [];
|
const popularMovieEntries = popularMovies.data?.pages.flatMap((p) => p.results) ?? [];
|
||||||
const popularTvEntries = popularTv.data?.pages.flatMap((p) => p.results) ?? [];
|
const popularTvEntries = popularTv.data?.pages.flatMap((p) => p.results) ?? [];
|
||||||
|
const topRatedMovieEntries = topRatedMovies.data?.pages.flatMap((p) => p.results) ?? [];
|
||||||
|
const topRatedTvEntries = topRatedTv.data?.pages.flatMap((p) => p.results) ?? [];
|
||||||
|
const upcomingMovieEntries = upcomingMovies.data?.pages.flatMap((p) => p.results) ?? [];
|
||||||
const searchEntries = searchResults.data?.pages.flatMap((p) => p.results) ?? [];
|
const searchEntries = searchResults.data?.pages.flatMap((p) => p.results) ?? [];
|
||||||
|
|
||||||
const isSearching = searchQuery.length > 0;
|
const isSearching = debouncedQuery.length > 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-8 animate-page-enter">
|
<div className="space-y-8 animate-page-enter">
|
||||||
|
{/* Trending Slider Hero */}
|
||||||
|
{!isSearching && (
|
||||||
|
<TrendingSlider
|
||||||
|
entries={trendingMovieEntries}
|
||||||
|
isLoading={trendingMovies.isLoading}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Search */}
|
{/* Search */}
|
||||||
<div className="relative max-w-md">
|
<div className="relative max-w-md">
|
||||||
<Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
<Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
||||||
<Input
|
<Input
|
||||||
placeholder="Search movies & TV shows..."
|
placeholder="Search movies & TV shows..."
|
||||||
value={searchQuery}
|
value={searchInput}
|
||||||
onChange={(e) => setSearchQuery(e.target.value)}
|
onChange={(e) => setSearchInput(e.target.value)}
|
||||||
className="pl-10"
|
className="pl-10"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -42,7 +78,7 @@ export function HomePage() {
|
|||||||
{isSearching ? (
|
{isSearching ? (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<h2 className="text-xl font-semibold">
|
<h2 className="text-xl font-semibold">
|
||||||
Search Results for "{searchQuery}"
|
Search Results for "{debouncedQuery}"
|
||||||
</h2>
|
</h2>
|
||||||
{searchEntries.length === 0 && !searchResults.isLoading ? (
|
{searchEntries.length === 0 && !searchResults.isLoading ? (
|
||||||
<p className="text-muted-foreground">No results found.</p>
|
<p className="text-muted-foreground">No results found.</p>
|
||||||
@@ -67,7 +103,7 @@ export function HomePage() {
|
|||||||
movieEntries={trendingMovieEntries}
|
movieEntries={trendingMovieEntries}
|
||||||
tvEntries={trendingTvEntries}
|
tvEntries={trendingTvEntries}
|
||||||
isLoading={trendingMovies.isLoading || trendingTv.isLoading}
|
isLoading={trendingMovies.isLoading || trendingTv.isLoading}
|
||||||
moreLink="/library"
|
category="trending"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TrendingGrid
|
<TrendingGrid
|
||||||
@@ -75,7 +111,23 @@ export function HomePage() {
|
|||||||
movieEntries={popularMovieEntries}
|
movieEntries={popularMovieEntries}
|
||||||
tvEntries={popularTvEntries}
|
tvEntries={popularTvEntries}
|
||||||
isLoading={popularMovies.isLoading || popularTv.isLoading}
|
isLoading={popularMovies.isLoading || popularTv.isLoading}
|
||||||
moreLink="/library"
|
category="popular"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TrendingGrid
|
||||||
|
title="Top Rated"
|
||||||
|
movieEntries={topRatedMovieEntries}
|
||||||
|
tvEntries={topRatedTvEntries}
|
||||||
|
isLoading={topRatedMovies.isLoading || topRatedTv.isLoading}
|
||||||
|
category="top-rated"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TrendingGrid
|
||||||
|
title="Upcoming"
|
||||||
|
movieEntries={upcomingMovieEntries}
|
||||||
|
tvEntries={[]}
|
||||||
|
isLoading={upcomingMovies.isLoading}
|
||||||
|
category="upcoming"
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -80,15 +80,15 @@ export function LibraryPage() {
|
|||||||
const baseEntries = useMemo(() => {
|
const baseEntries = useMemo(() => {
|
||||||
switch (activeTab) {
|
switch (activeTab) {
|
||||||
case 'movies':
|
case 'movies':
|
||||||
return allEntries.filter((e) => !e.is_tvseries && !e.watchlist);
|
return allEntries.filter((e) => !e.is_tvseries && !e.watchlist && !e.hidden);
|
||||||
case 'tv':
|
case 'tv':
|
||||||
return allEntries.filter((e) => e.is_tvseries && !e.watchlist);
|
return allEntries.filter((e) => e.is_tvseries && !e.watchlist && !e.hidden);
|
||||||
case 'favorites':
|
case 'favorites':
|
||||||
return allEntries.filter((e) => e.favorit && !e.watchlist);
|
return allEntries.filter((e) => e.favorit && !e.watchlist && !e.hidden);
|
||||||
case 'hidden':
|
case 'hidden':
|
||||||
return allEntries.filter((e) => e.hidden);
|
return allEntries.filter((e) => e.hidden);
|
||||||
default:
|
default:
|
||||||
return allEntries.filter((e) => !e.watchlist);
|
return allEntries.filter((e) => !e.watchlist && !e.hidden);
|
||||||
}
|
}
|
||||||
}, [activeTab, allEntries]);
|
}, [activeTab, allEntries]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
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 { 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 { Badge } from '@/components/ui/badge';
|
||||||
@@ -14,6 +15,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();
|
||||||
|
|
||||||
if (isLoading || !season) {
|
if (isLoading || !season) {
|
||||||
return (
|
return (
|
||||||
@@ -141,8 +143,15 @@ export function SeasonPage() {
|
|||||||
onClick={(ev) => {
|
onClick={(ev) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
// TODO: Mark episode as watched
|
if (!isWatched) {
|
||||||
|
createEpisodeSeen.mutate({
|
||||||
|
entry_id: parseInt(entryId!, 10),
|
||||||
|
episode_id: episode.id,
|
||||||
|
date_seen: new Date().toISOString(),
|
||||||
|
});
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
|
disabled={isWatched || createEpisodeSeen.isPending}
|
||||||
>
|
>
|
||||||
<Eye className="h-4 w-4" />
|
<Eye className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -74,6 +74,9 @@ const PersonTmdbRedirectPage = lazy(() =>
|
|||||||
const SettingsPage = lazy(() =>
|
const SettingsPage = lazy(() =>
|
||||||
import('@/pages/SettingsPage').then((m) => ({ default: m.SettingsPage }))
|
import('@/pages/SettingsPage').then((m) => ({ default: m.SettingsPage }))
|
||||||
);
|
);
|
||||||
|
const DiscoverPage = lazy(() =>
|
||||||
|
import('@/pages/DiscoverPage').then((m) => ({ default: m.DiscoverPage }))
|
||||||
|
);
|
||||||
|
|
||||||
function SuspensePage({ children, fallback }: { children: ReactNode; fallback?: ReactNode }) {
|
function SuspensePage({ children, fallback }: { children: ReactNode; fallback?: ReactNode }) {
|
||||||
return <Suspense fallback={fallback ?? <HomeSkeleton />}>{children}</Suspense>;
|
return <Suspense fallback={fallback ?? <HomeSkeleton />}>{children}</Suspense>;
|
||||||
@@ -107,6 +110,14 @@ export const router = createBrowserRouter([
|
|||||||
</SuspensePage>
|
</SuspensePage>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/discover/:category',
|
||||||
|
element: (
|
||||||
|
<SuspensePage fallback={<HomeSkeleton />}>
|
||||||
|
<DiscoverPage />
|
||||||
|
</SuspensePage>
|
||||||
|
),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/watchlist',
|
path: '/watchlist',
|
||||||
element: (
|
element: (
|
||||||
|
|||||||
Reference in new issue
Block a user