Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c6023cc52 | ||
|
|
67c828838d | ||
|
|
cd2c135c65 | ||
|
|
f88dfdae44 | ||
|
|
6d4c3e185a | ||
|
|
834e02e76b | ||
|
|
c74e54bc2a |
No files matched your search
@@ -12,6 +12,7 @@ environment.ts
|
|||||||
circular-dependencies.png
|
circular-dependencies.png
|
||||||
.agents/skills
|
.agents/skills
|
||||||
auto_puller.py
|
auto_puller.py
|
||||||
|
/brain
|
||||||
|
|
||||||
# Compiled output
|
# Compiled output
|
||||||
.angular
|
.angular
|
||||||
|
|||||||
@@ -11,33 +11,6 @@ You can get project context from the following files:
|
|||||||
|
|
||||||
## Mandatory Task Completion Rule
|
## Mandatory Task Completion Rule
|
||||||
|
|
||||||
#### Update the `changes.md` file after completing any task requested by the user.
|
|
||||||
|
|
||||||
After completing ANY task requested by the user, you MUST update the file `changes.md`.
|
|
||||||
Append a new section at the end of `changes.md` using this exact format:
|
|
||||||
|
|
||||||
```md
|
|
||||||
### Milestone XXX
|
|
||||||
|
|
||||||
#### Backend Changes
|
|
||||||
|
|
||||||
- <change 1>
|
|
||||||
- <change 2>
|
|
||||||
- <change 3>
|
|
||||||
|
|
||||||
#### Frontend Changes
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Rules
|
|
||||||
|
|
||||||
- Always ask the user if this is a new milestone or if you should continue appending to the current milestone.
|
|
||||||
- Replace `XXX` with the task number provided by the user (example: `025`).
|
|
||||||
- The bullet list must include all important modifications made.
|
|
||||||
- Do NOT overwrite previous entries: always APPEND.
|
|
||||||
- If `changes.md` does not exist, create it.
|
|
||||||
- If no task number is provided, use the next available number based on the last entry in the file.
|
|
||||||
- Always ensure formatting matches exactly (heading + code block + bullets).
|
|
||||||
|
|
||||||
### Documentation (Skip the legacy docs, we're using obsidian docs-vault now)
|
### Documentation (Skip the legacy docs, we're using obsidian docs-vault now)
|
||||||
|
|
||||||
Update the `/backend/docs` and `/react_frontend/docs` folders with any relevant documentation changes related to the task you completed. This includes API documentation, architectural diagrams, or any other relevant docs.
|
Update the `/backend/docs` and `/react_frontend/docs` folders with any relevant documentation changes related to the task you completed. This includes API documentation, architectural diagrams, or any other relevant docs.
|
||||||
|
|||||||
Generated
+915
-2575
File diff suppressed because it is too large.
Load diff
@@ -49,9 +49,8 @@
|
|||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {},
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"electron": "^34.0.1",
|
"electron": "^45.1.0",
|
||||||
"electron-builder": "^25.1.8"
|
"electron-builder": "^26.18.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Generated
+748
-445
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,32 @@
|
|||||||
|
allowBuilds:
|
||||||
|
msw: false
|
||||||
|
overrides:
|
||||||
|
'@babel/core@<=7.29.0': ^7.29.6
|
||||||
|
'@hono/node-server@<1.19.15': ^1.19.15
|
||||||
|
'@hono/node-server@>=1.19.10 <2.1.3': ^2.1.3
|
||||||
|
'@modelcontextprotocol/sdk@<1.32.0': ^1.32.0
|
||||||
|
axios@>=1.0.0 <1.20.0: ^1.20.0
|
||||||
|
baseline-browser-mapping@>=2.0.0 <2.11.0: ^2.11.0
|
||||||
|
body-parser@>=2.0.0 <2.4.0: ^2.4.0
|
||||||
|
brace-expansion@<1.1.21: ^1.1.21
|
||||||
|
brace-expansion@>=3.0.0 <5.0.7: ^5.0.7
|
||||||
|
brace-expansion@>=4.0.0 <5.0.12: ^5.0.12
|
||||||
|
browserslist@<=4.28.6: ^4.28.7
|
||||||
|
fast-uri@>=3.0.0 <3.1.9: ^3.1.9
|
||||||
|
follow-redirects@>=1.16.0 <1.16.1: ^1.16.1
|
||||||
|
form-data@>=4.0.0 <4.0.6: ^4.0.6
|
||||||
|
hono@<4.13.7: ^4.13.7
|
||||||
|
hono@>=4.12.4 <4.13.11: ^4.13.11
|
||||||
|
ip-address@<=10.7.3: ^10.7.4
|
||||||
|
js-yaml@>=4.0.0 <4.3.2: ^4.3.2
|
||||||
|
nanoid@<3.3.18: ^3.3.18
|
||||||
|
postcss-selector-parser@>=7.0.0 <7.1.6: ^7.1.6
|
||||||
|
postcss@<=8.5.22: ^8.5.23
|
||||||
|
proxy-addr@>=1.1.0 <2.0.8: ^2.0.8
|
||||||
|
qs@>=2.2.5 <6.16.0: ^6.16.0
|
||||||
|
qs@>=6.7.0 <=6.16.0: ^6.16.1
|
||||||
|
react-router@>=6.0.0 <7.18.0: ^7.18.0
|
||||||
|
react-router@>=7.12.0 <7.18.2: ^7.18.2
|
||||||
|
source-map-js@>=1.0.0 <1.2.2: ^1.2.2
|
||||||
|
vite@>=8.0.0 <=8.1.5: ^8.1.6
|
||||||
|
zod@<4.6.6: ^4.6.6
|
||||||
@@ -13,6 +13,11 @@ import { Textarea } from "@/components/ui/textarea";
|
|||||||
import { ImageIcon } from "lucide-react";
|
import { ImageIcon } from "lucide-react";
|
||||||
import { StarRating } from "@/components/ui/star-rating";
|
import { StarRating } from "@/components/ui/star-rating";
|
||||||
import { useUpdateCollection } from "@/hooks/useCollections";
|
import { useUpdateCollection } from "@/hooks/useCollections";
|
||||||
|
import {
|
||||||
|
DEFAULT_POSTER,
|
||||||
|
getCollectionDisplayBackdropUrl,
|
||||||
|
getCollectionDisplayPosterUrl,
|
||||||
|
} from "@/lib/collection-media";
|
||||||
import type { Collection } from "@/types";
|
import type { Collection } from "@/types";
|
||||||
|
|
||||||
interface CollectionEditDialogProps {
|
interface CollectionEditDialogProps {
|
||||||
@@ -34,6 +39,14 @@ export function CollectionEditDialog({
|
|||||||
const [posterPreview, setPosterPreview] = useState<string | null>(null);
|
const [posterPreview, setPosterPreview] = useState<string | null>(null);
|
||||||
const [backdropPreview, setBackdropPreview] = useState<string | null>(null);
|
const [backdropPreview, setBackdropPreview] = useState<string | null>(null);
|
||||||
|
|
||||||
|
// What the collection page currently shows, so the user can see what an
|
||||||
|
// upload would replace. The default placeholder doesn't count as a poster.
|
||||||
|
const displayPoster = getCollectionDisplayPosterUrl(collection);
|
||||||
|
const currentPoster = displayPoster === DEFAULT_POSTER ? null : displayPoster;
|
||||||
|
const currentBackdrop = getCollectionDisplayBackdropUrl(collection);
|
||||||
|
const shownPoster = posterPreview ?? currentPoster;
|
||||||
|
const shownBackdrop = backdropPreview ?? currentBackdrop;
|
||||||
|
|
||||||
const posterInputRef = useRef<HTMLInputElement>(null);
|
const posterInputRef = useRef<HTMLInputElement>(null);
|
||||||
const backdropInputRef = useRef<HTMLInputElement>(null);
|
const backdropInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
@@ -131,15 +144,20 @@ export function CollectionEditDialog({
|
|||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="w-full h-20 flex flex-col gap-1"
|
className="group relative w-full h-32 p-0 overflow-hidden flex flex-col gap-1"
|
||||||
onClick={() => posterInputRef.current?.click()}
|
onClick={() => posterInputRef.current?.click()}
|
||||||
>
|
>
|
||||||
{posterPreview ? (
|
{shownPoster ? (
|
||||||
|
<>
|
||||||
<img
|
<img
|
||||||
src={posterPreview}
|
src={shownPoster}
|
||||||
alt="Poster preview"
|
alt="Poster preview"
|
||||||
className="h-14 w-auto rounded object-cover"
|
className="h-full w-full object-contain bg-muted"
|
||||||
/>
|
/>
|
||||||
|
<span className="absolute inset-0 flex items-center justify-center bg-black/50 text-xs font-medium text-white opacity-0 transition-opacity group-hover:opacity-100">
|
||||||
|
Change Poster
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<ImageIcon className="h-5 w-5 text-muted-foreground" />
|
<ImageIcon className="h-5 w-5 text-muted-foreground" />
|
||||||
@@ -163,15 +181,20 @@ export function CollectionEditDialog({
|
|||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="w-full h-20 flex flex-col gap-1"
|
className="group relative w-full h-32 p-0 overflow-hidden flex flex-col gap-1"
|
||||||
onClick={() => backdropInputRef.current?.click()}
|
onClick={() => backdropInputRef.current?.click()}
|
||||||
>
|
>
|
||||||
{backdropPreview ? (
|
{shownBackdrop ? (
|
||||||
|
<>
|
||||||
<img
|
<img
|
||||||
src={backdropPreview}
|
src={shownBackdrop}
|
||||||
alt="Backdrop preview"
|
alt="Backdrop preview"
|
||||||
className="h-14 w-auto rounded object-cover"
|
className="h-full w-full object-cover"
|
||||||
/>
|
/>
|
||||||
|
<span className="absolute inset-0 flex items-center justify-center bg-black/50 text-xs font-medium text-white opacity-0 transition-opacity group-hover:opacity-100">
|
||||||
|
Change Backdrop
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<ImageIcon className="h-5 w-5 text-muted-foreground" />
|
<ImageIcon className="h-5 w-5 text-muted-foreground" />
|
||||||
|
|||||||
@@ -154,28 +154,39 @@ export function CollectionDetailsSkeleton() {
|
|||||||
export function EntryDetailsSkeleton() {
|
export function EntryDetailsSkeleton() {
|
||||||
return (
|
return (
|
||||||
<div className="animate-in fade-in duration-300">
|
<div className="animate-in fade-in duration-300">
|
||||||
<div className="h-52 -mx-6 -mt-6 bg-muted animate-pulse rounded-b-lg" />
|
<div className="relative -mx-4 -mt-4 bg-muted/40 md:-mx-6 md:-mt-6">
|
||||||
<div className="max-w-4xl mx-auto flex gap-8 -mt-24">
|
<div className="mx-auto flex max-w-6xl flex-col items-center gap-6 px-4 pb-8 pt-28 sm:flex-row sm:items-end sm:gap-8 sm:pt-44 md:px-6">
|
||||||
<div className="w-44 shrink-0 space-y-3">
|
<Skeleton className="aspect-[2/3] w-40 shrink-0 rounded-xl sm:w-52 lg:w-60" />
|
||||||
<Skeleton className="aspect-[2/3] w-full rounded-xl" />
|
<div className="w-full flex-1 space-y-4">
|
||||||
<Skeleton className="h-9 w-full rounded-lg" />
|
<Skeleton className="h-5 w-24 rounded-full" />
|
||||||
<Skeleton className="h-9 w-full rounded-lg" />
|
<Skeleton className="h-12 w-3/4 max-w-md" />
|
||||||
<Skeleton className="h-9 w-full rounded-lg" />
|
<Skeleton className="h-4 w-48" />
|
||||||
</div>
|
<div className="flex gap-1.5">
|
||||||
<div className="flex-1 space-y-4 pt-24">
|
<Skeleton className="h-6 w-16 rounded-full" />
|
||||||
<Skeleton className="h-9 w-72" />
|
<Skeleton className="h-6 w-20 rounded-full" />
|
||||||
<Skeleton className="h-4 w-32" />
|
<Skeleton className="h-6 w-14 rounded-full" />
|
||||||
<div className="flex gap-2">
|
|
||||||
<Skeleton className="h-5 w-12" />
|
|
||||||
<Skeleton className="h-5 w-16" />
|
|
||||||
<Skeleton className="h-5 w-20" />
|
|
||||||
</div>
|
</div>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<Skeleton className="h-8 w-24 rounded-full" />
|
<Skeleton className="h-11 w-36 rounded-md" />
|
||||||
<Skeleton className="h-8 w-24 rounded-full" />
|
<Skeleton className="h-11 w-28 rounded-md" />
|
||||||
<Skeleton className="h-8 w-20 rounded-full" />
|
<Skeleton className="h-11 w-11 rounded-full" />
|
||||||
|
<Skeleton className="h-11 w-11 rounded-full" />
|
||||||
</div>
|
</div>
|
||||||
<Skeleton className="h-20 w-full" />
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="mx-auto mt-4 grid max-w-6xl gap-10 lg:grid-cols-[minmax(0,1fr)_300px]">
|
||||||
|
<div className="space-y-3">
|
||||||
|
<Skeleton className="h-6 w-28" />
|
||||||
|
<Skeleton className="h-24 w-full" />
|
||||||
|
</div>
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="grid grid-cols-3 gap-2">
|
||||||
|
<Skeleton className="h-20 rounded-xl" />
|
||||||
|
<Skeleton className="h-20 rounded-xl" />
|
||||||
|
<Skeleton className="h-20 rounded-xl" />
|
||||||
|
</div>
|
||||||
|
<Skeleton className="h-40 rounded-xl" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { getMediaUrl, getTmdbImageUrl } from "@/lib/api";
|
|||||||
import { getBackdropUrl, getPosterUrl } from "@/lib/media-utils";
|
import { getBackdropUrl, getPosterUrl } from "@/lib/media-utils";
|
||||||
import type { Collection, Media } from "@/types";
|
import type { Collection, Media } from "@/types";
|
||||||
|
|
||||||
const DEFAULT_POSTER = "/images/default-poster.png";
|
export const DEFAULT_POSTER = "/images/default-poster.png";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collection poster: uploaded poster, then the collection's own TMDB poster,
|
* Collection poster: uploaded poster, then the collection's own TMDB poster,
|
||||||
@@ -13,7 +13,12 @@ export function getCollectionDisplayPosterUrl(collection: Collection): string {
|
|||||||
(m: Media) => m.type === "poster" && m.is_selected,
|
(m: Media) => m.type === "poster" && m.is_selected,
|
||||||
);
|
);
|
||||||
if (selectedPoster?.path) {
|
if (selectedPoster?.path) {
|
||||||
return getMediaUrl("collections", "posters", "preview", selectedPoster.path);
|
return getMediaUrl(
|
||||||
|
"collections",
|
||||||
|
"posters",
|
||||||
|
"preview",
|
||||||
|
selectedPoster.path,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (collection.poster_path) {
|
if (collection.poster_path) {
|
||||||
@@ -39,7 +44,12 @@ export function getCollectionDisplayBackdropUrl(
|
|||||||
(m: Media) => m.type === "backdrop" && m.is_selected,
|
(m: Media) => m.type === "backdrop" && m.is_selected,
|
||||||
);
|
);
|
||||||
if (selectedBackdrop?.path) {
|
if (selectedBackdrop?.path) {
|
||||||
return getMediaUrl("collections", "backdrops", "full", selectedBackdrop.path);
|
return getMediaUrl(
|
||||||
|
"collections",
|
||||||
|
"backdrops",
|
||||||
|
"full",
|
||||||
|
selectedBackdrop.path,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (collection.backdrop_path) {
|
if (collection.backdrop_path) {
|
||||||
|
|||||||
@@ -29,6 +29,22 @@ export function getPosterUrl(entry: Entry): string {
|
|||||||
return DEFAULT_POSTER;
|
return DEFAULT_POSTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Same source as getPosterUrl, but at original resolution. */
|
||||||
|
export function getFullPosterUrl(entry: Entry): string {
|
||||||
|
const selectedPoster = entry.isInLibrary
|
||||||
|
? entry.medias?.find((m: Media) => m.type === "poster" && m.is_selected)
|
||||||
|
: undefined;
|
||||||
|
if (selectedPoster?.path) {
|
||||||
|
return getMediaUrl("entries", "posters", "full", selectedPoster.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entry.poster_path) {
|
||||||
|
return getTmdbImageUrl(entry.poster_path, "original");
|
||||||
|
}
|
||||||
|
|
||||||
|
return DEFAULT_POSTER;
|
||||||
|
}
|
||||||
|
|
||||||
export function getBackdropUrl(entry: Entry): string {
|
export function getBackdropUrl(entry: Entry): string {
|
||||||
if (entry.medias) {
|
if (entry.medias) {
|
||||||
const selectedBackdrop = entry.medias.find(
|
const selectedBackdrop = entry.medias.find(
|
||||||
@@ -121,3 +137,24 @@ export function getYear(dateStr: string | null): string {
|
|||||||
if (!dateStr) return "";
|
if (!dateStr) return "";
|
||||||
return new Date(dateStr).getFullYear().toString();
|
return new Date(dateStr).getFullYear().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function calculateAge(
|
||||||
|
birthday: string | null | undefined,
|
||||||
|
deathday?: string | null,
|
||||||
|
): number | null {
|
||||||
|
if (!birthday) return null;
|
||||||
|
|
||||||
|
const birth = new Date(birthday);
|
||||||
|
if (isNaN(birth.getTime())) return null;
|
||||||
|
|
||||||
|
let end = deathday ? new Date(deathday) : new Date();
|
||||||
|
if (deathday && isNaN(end.getTime())) end = new Date();
|
||||||
|
|
||||||
|
let age = end.getFullYear() - birth.getFullYear();
|
||||||
|
const monthDiff = end.getMonth() - birth.getMonth();
|
||||||
|
if (monthDiff < 0 || (monthDiff === 0 && end.getDate() < birth.getDate())) {
|
||||||
|
age--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return age;
|
||||||
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,49 +1,57 @@
|
|||||||
import { useState, useMemo, useCallback, useEffect, useRef } from 'react';
|
import { useState, useMemo, useCallback, useEffect, useRef } from "react";
|
||||||
import { useSearchParams, useNavigationType } from 'react-router-dom';
|
import { useSearchParams, useNavigationType } from "react-router-dom";
|
||||||
import { useLibrary } from '@/hooks/useEntries';
|
import { useLibrary } from "@/hooks/useEntries";
|
||||||
import { useLibraryEntries } from '@/stores/useLibraryStore';
|
import { useLibraryEntries } from "@/stores/useLibraryStore";
|
||||||
import {
|
import {
|
||||||
useLibraryFiltersStore,
|
useLibraryFiltersStore,
|
||||||
defaultFilters,
|
defaultFilters,
|
||||||
} from '@/stores/useLibraryFiltersStore';
|
} from "@/stores/useLibraryFiltersStore";
|
||||||
import type {
|
import type {
|
||||||
FilterTab,
|
FilterTab,
|
||||||
SortField,
|
SortField,
|
||||||
SortDir,
|
SortDir,
|
||||||
Filters,
|
Filters,
|
||||||
} from '@/stores/useLibraryFiltersStore';
|
} from "@/stores/useLibraryFiltersStore";
|
||||||
import { EntryLibraryGrid } from '@/components/entries/EntryLibraryGrid';
|
import { EntryLibraryGrid } from "@/components/entries/EntryLibraryGrid";
|
||||||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from "@/components/ui/input";
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from "@/components/ui/button";
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from "@/components/ui/badge";
|
||||||
import {
|
import {
|
||||||
Popover,
|
Popover,
|
||||||
PopoverContent,
|
PopoverContent,
|
||||||
PopoverTrigger,
|
PopoverTrigger,
|
||||||
} from '@/components/ui/popover';
|
} from "@/components/ui/popover";
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
SelectItem,
|
SelectItem,
|
||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from '@/components/ui/select';
|
} from "@/components/ui/select";
|
||||||
import { Search, X, SlidersHorizontal, ArrowUpDown, Info } from 'lucide-react';
|
import {
|
||||||
import type { Entry } from '@/types';
|
Search,
|
||||||
|
X,
|
||||||
|
SlidersHorizontal,
|
||||||
|
ArrowUpDown,
|
||||||
|
Info,
|
||||||
|
Heart,
|
||||||
|
EyeOff,
|
||||||
|
} from "lucide-react";
|
||||||
|
import type { Entry } from "@/types";
|
||||||
import {
|
import {
|
||||||
Tooltip,
|
Tooltip,
|
||||||
TooltipContent,
|
TooltipContent,
|
||||||
TooltipProvider,
|
TooltipProvider,
|
||||||
TooltipTrigger,
|
TooltipTrigger,
|
||||||
} from '@/components/ui/tooltip';
|
} from "@/components/ui/tooltip";
|
||||||
|
|
||||||
const sortLabels: Record<SortField, string> = {
|
const sortLabels: Record<SortField, string> = {
|
||||||
date_last_seen: 'Last Watched',
|
date_last_seen: "Last Watched",
|
||||||
createdAt: 'Date Added',
|
createdAt: "Date Added",
|
||||||
title: 'Title',
|
title: "Title",
|
||||||
release_date: 'Release Date',
|
release_date: "Release Date",
|
||||||
rating: 'Rating',
|
rating: "Rating",
|
||||||
};
|
};
|
||||||
|
|
||||||
function sortEntries(
|
function sortEntries(
|
||||||
@@ -54,34 +62,69 @@ function sortEntries(
|
|||||||
return [...entries].sort((a, b) => {
|
return [...entries].sort((a, b) => {
|
||||||
let cmp = 0;
|
let cmp = 0;
|
||||||
switch (field) {
|
switch (field) {
|
||||||
case 'title':
|
case "title":
|
||||||
cmp = a.title.localeCompare(b.title);
|
cmp = a.title.localeCompare(b.title);
|
||||||
break;
|
break;
|
||||||
case 'release_date':
|
case "release_date":
|
||||||
cmp =
|
cmp =
|
||||||
new Date(a.release_date || '1900').getTime() -
|
new Date(a.release_date || "1900").getTime() -
|
||||||
new Date(b.release_date || '1900').getTime();
|
new Date(b.release_date || "1900").getTime();
|
||||||
break;
|
break;
|
||||||
case 'rating':
|
case "rating":
|
||||||
cmp =
|
cmp =
|
||||||
(a.entryRatings?.user_rating ?? 0) -
|
(a.entryRatings?.user_rating ?? 0) -
|
||||||
(b.entryRatings?.user_rating ?? 0);
|
(b.entryRatings?.user_rating ?? 0);
|
||||||
break;
|
break;
|
||||||
case 'date_last_seen':
|
case "date_last_seen":
|
||||||
cmp =
|
cmp =
|
||||||
new Date(a.date_last_seen || '1900').getTime() -
|
new Date(a.date_last_seen || "1900").getTime() -
|
||||||
new Date(b.date_last_seen || '1900').getTime();
|
new Date(b.date_last_seen || "1900").getTime();
|
||||||
break;
|
break;
|
||||||
case 'createdAt':
|
case "createdAt":
|
||||||
cmp = new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime();
|
cmp = new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return dir === 'desc' ? -cmp : cmp;
|
return dir === "desc" ? -cmp : cmp;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const PAGE_SIZE = 28;
|
const PAGE_SIZE = 28;
|
||||||
|
|
||||||
|
interface FilterTogglesProps {
|
||||||
|
favoritesOnly: boolean;
|
||||||
|
onFavoritesChange: (value: boolean) => void;
|
||||||
|
hiddenOnly: boolean;
|
||||||
|
onHiddenChange: (value: boolean) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function FilterToggles({
|
||||||
|
favoritesOnly,
|
||||||
|
onFavoritesChange,
|
||||||
|
hiddenOnly,
|
||||||
|
onHiddenChange,
|
||||||
|
}: FilterTogglesProps) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Button
|
||||||
|
variant={favoritesOnly ? "default" : "outline"}
|
||||||
|
aria-pressed={favoritesOnly}
|
||||||
|
onClick={() => onFavoritesChange(!favoritesOnly)}
|
||||||
|
>
|
||||||
|
<Heart className={favoritesOnly ? "fill-current" : ""} />
|
||||||
|
Favorites
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant={hiddenOnly ? "default" : "outline"}
|
||||||
|
aria-pressed={hiddenOnly}
|
||||||
|
onClick={() => onHiddenChange(!hiddenOnly)}
|
||||||
|
>
|
||||||
|
<EyeOff />
|
||||||
|
Hidden
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function LibraryPage() {
|
export function LibraryPage() {
|
||||||
const { isLoading } = useLibrary();
|
const { isLoading } = useLibrary();
|
||||||
const [searchParams, setSearchParams] = useSearchParams();
|
const [searchParams, setSearchParams] = useSearchParams();
|
||||||
@@ -92,6 +135,10 @@ export function LibraryPage() {
|
|||||||
const setActiveTab = useLibraryFiltersStore((s) => s.setActiveTab);
|
const setActiveTab = useLibraryFiltersStore((s) => s.setActiveTab);
|
||||||
const search = useLibraryFiltersStore((s) => s.search);
|
const search = useLibraryFiltersStore((s) => s.search);
|
||||||
const setSearch = useLibraryFiltersStore((s) => s.setSearch);
|
const setSearch = useLibraryFiltersStore((s) => s.setSearch);
|
||||||
|
const favoritesOnly = useLibraryFiltersStore((s) => s.favoritesOnly);
|
||||||
|
const setFavoritesOnly = useLibraryFiltersStore((s) => s.setFavoritesOnly);
|
||||||
|
const hiddenOnly = useLibraryFiltersStore((s) => s.hiddenOnly);
|
||||||
|
const setHiddenOnly = useLibraryFiltersStore((s) => s.setHiddenOnly);
|
||||||
const sortField = useLibraryFiltersStore((s) => s.sortField);
|
const sortField = useLibraryFiltersStore((s) => s.sortField);
|
||||||
const setSortField = useLibraryFiltersStore((s) => s.setSortField);
|
const setSortField = useLibraryFiltersStore((s) => s.setSortField);
|
||||||
const sortDir = useLibraryFiltersStore((s) => s.sortDir);
|
const sortDir = useLibraryFiltersStore((s) => s.sortDir);
|
||||||
@@ -105,13 +152,13 @@ export function LibraryPage() {
|
|||||||
const [debouncedFilters, setDebouncedFilters] = useState<Filters>(filters);
|
const [debouncedFilters, setDebouncedFilters] = useState<Filters>(filters);
|
||||||
const [visibleCount, setVisibleCount] = useState(PAGE_SIZE);
|
const [visibleCount, setVisibleCount] = useState(PAGE_SIZE);
|
||||||
const filtersInitialized = useRef(false);
|
const filtersInitialized = useRef(false);
|
||||||
const [statusFilter, setStatusFilter] = useState<string>('');
|
const [statusFilter, setStatusFilter] = useState<string>("");
|
||||||
|
|
||||||
const allEntries = useLibraryEntries();
|
const allEntries = useLibraryEntries();
|
||||||
|
|
||||||
// Reset filters when navigating TO the library (not when pressing back)
|
// Reset filters when navigating TO the library (not when pressing back)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (navigationType !== 'POP') {
|
if (navigationType !== "POP") {
|
||||||
resetAll();
|
resetAll();
|
||||||
}
|
}
|
||||||
// Only run on mount
|
// Only run on mount
|
||||||
@@ -122,9 +169,9 @@ export function LibraryPage() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (filtersInitialized.current) return;
|
if (filtersInitialized.current) return;
|
||||||
filtersInitialized.current = true;
|
filtersInitialized.current = true;
|
||||||
const genre = searchParams.get('genre') || '';
|
const genre = searchParams.get("genre") || "";
|
||||||
const ratingMin = searchParams.get('ratingMin') || '';
|
const ratingMin = searchParams.get("ratingMin") || "";
|
||||||
const ratingMax = searchParams.get('ratingMax') || '';
|
const ratingMax = searchParams.get("ratingMax") || "";
|
||||||
if (genre || ratingMin || ratingMax) {
|
if (genre || ratingMin || ratingMax) {
|
||||||
const newFilters = {
|
const newFilters = {
|
||||||
...defaultFilters,
|
...defaultFilters,
|
||||||
@@ -154,7 +201,15 @@ export function LibraryPage() {
|
|||||||
// Reset visible count when filters/search/tab/sort change
|
// Reset visible count when filters/search/tab/sort change
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setVisibleCount(PAGE_SIZE);
|
setVisibleCount(PAGE_SIZE);
|
||||||
}, [activeTab, debouncedSearch, debouncedFilters, sortField, sortDir]);
|
}, [
|
||||||
|
activeTab,
|
||||||
|
favoritesOnly,
|
||||||
|
hiddenOnly,
|
||||||
|
debouncedSearch,
|
||||||
|
debouncedFilters,
|
||||||
|
sortField,
|
||||||
|
sortDir,
|
||||||
|
]);
|
||||||
|
|
||||||
// Gather unique genres from the library
|
// Gather unique genres from the library
|
||||||
const allGenres = useMemo(() => {
|
const allGenres = useMemo(() => {
|
||||||
@@ -173,31 +228,25 @@ export function LibraryPage() {
|
|||||||
filters.yearMax ||
|
filters.yearMax ||
|
||||||
!!statusFilter;
|
!!statusFilter;
|
||||||
|
|
||||||
|
// Type tab combines with the favorites/hidden toggles. Hidden mode shows
|
||||||
|
// only hidden entries (watchlist included); otherwise hidden and watchlist
|
||||||
|
// entries are excluded.
|
||||||
const baseEntries = useMemo(() => {
|
const baseEntries = useMemo(() => {
|
||||||
switch (activeTab) {
|
return allEntries.filter((e) => {
|
||||||
case 'movies':
|
if (activeTab === "movies" && e.is_tvseries) return false;
|
||||||
return allEntries.filter(
|
if (activeTab === "tv" && !e.is_tvseries) return false;
|
||||||
(e) => !e.is_tvseries && !e.watchlist && !e.hidden,
|
if (favoritesOnly && !e.favorit) return false;
|
||||||
);
|
if (hiddenOnly) return !!e.hidden;
|
||||||
case 'tv':
|
return !e.watchlist && !e.hidden;
|
||||||
return allEntries.filter(
|
});
|
||||||
(e) => e.is_tvseries && !e.watchlist && !e.hidden,
|
}, [activeTab, favoritesOnly, hiddenOnly, allEntries]);
|
||||||
);
|
|
||||||
case 'favorites':
|
|
||||||
return allEntries.filter((e) => e.favorit && !e.watchlist && !e.hidden);
|
|
||||||
case 'hidden':
|
|
||||||
return allEntries.filter((e) => e.hidden);
|
|
||||||
default:
|
|
||||||
return allEntries.filter((e) => !e.watchlist && !e.hidden);
|
|
||||||
}
|
|
||||||
}, [activeTab, allEntries]);
|
|
||||||
|
|
||||||
const filteredEntries = useMemo(() => {
|
const filteredEntries = useMemo(() => {
|
||||||
let result = baseEntries;
|
let result = baseEntries;
|
||||||
|
|
||||||
if (debouncedSearch) {
|
if (debouncedSearch) {
|
||||||
const q = debouncedSearch.toLowerCase();
|
const q = debouncedSearch.toLowerCase();
|
||||||
const directorPrefix = '@director:';
|
const directorPrefix = "@director:";
|
||||||
if (q.startsWith(directorPrefix)) {
|
if (q.startsWith(directorPrefix)) {
|
||||||
const dirQuery = q.slice(directorPrefix.length).trim();
|
const dirQuery = q.slice(directorPrefix.length).trim();
|
||||||
if (dirQuery) {
|
if (dirQuery) {
|
||||||
@@ -281,7 +330,7 @@ export function LibraryPage() {
|
|||||||
/>
|
/>
|
||||||
{search && (
|
{search && (
|
||||||
<button
|
<button
|
||||||
onClick={() => setSearch('')}
|
onClick={() => setSearch("")}
|
||||||
className="absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground"
|
className="absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground"
|
||||||
>
|
>
|
||||||
<X className="h-4 w-4" />
|
<X className="h-4 w-4" />
|
||||||
@@ -303,19 +352,19 @@ export function LibraryPage() {
|
|||||||
<p className="mb-0.5">
|
<p className="mb-0.5">
|
||||||
<code className="bg-accent px-1 rounded text-[11px]">
|
<code className="bg-accent px-1 rounded text-[11px]">
|
||||||
@director:name
|
@director:name
|
||||||
</code>{' '}
|
</code>{" "}
|
||||||
— by director
|
— by director
|
||||||
</p>
|
</p>
|
||||||
<p className="text-muted-foreground mb-0.5">
|
<p className="text-muted-foreground mb-0.5">
|
||||||
<code className="bg-accent px-1 rounded text-[11px]">
|
<code className="bg-accent px-1 rounded text-[11px]">
|
||||||
@country:name
|
@country:name
|
||||||
</code>{' '}
|
</code>{" "}
|
||||||
— coming soon
|
— coming soon
|
||||||
</p>
|
</p>
|
||||||
<p className="text-muted-foreground">
|
<p className="text-muted-foreground">
|
||||||
<code className="bg-accent px-1 rounded text-[11px]">
|
<code className="bg-accent px-1 rounded text-[11px]">
|
||||||
@year:year
|
@year:year
|
||||||
</code>{' '}
|
</code>{" "}
|
||||||
— coming soon
|
— coming soon
|
||||||
</p>
|
</p>
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
@@ -330,7 +379,7 @@ export function LibraryPage() {
|
|||||||
className="h-9 w-9 shrink-0 relative"
|
className="h-9 w-9 shrink-0 relative"
|
||||||
>
|
>
|
||||||
<ArrowUpDown className="h-4 w-4" />
|
<ArrowUpDown className="h-4 w-4" />
|
||||||
{sortField !== 'date_last_seen' && (
|
{sortField !== "date_last_seen" && (
|
||||||
<span className="absolute -top-1 -right-1 h-2 w-2 rounded-full bg-primary" />
|
<span className="absolute -top-1 -right-1 h-2 w-2 rounded-full bg-primary" />
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -346,8 +395,8 @@ export function LibraryPage() {
|
|||||||
onClick={() => setSortField(value as SortField)}
|
onClick={() => setSortField(value as SortField)}
|
||||||
className={`w-full rounded-md px-3 py-1.5 text-left text-sm transition-colors ${
|
className={`w-full rounded-md px-3 py-1.5 text-left text-sm transition-colors ${
|
||||||
sortField === value
|
sortField === value
|
||||||
? 'bg-accent text-accent-foreground font-medium'
|
? "bg-accent text-accent-foreground font-medium"
|
||||||
: 'hover:bg-accent/50'
|
: "hover:bg-accent/50"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{label}
|
{label}
|
||||||
@@ -356,18 +405,18 @@ export function LibraryPage() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex gap-1 pt-1 border-t border-border">
|
<div className="flex gap-1 pt-1 border-t border-border">
|
||||||
<Button
|
<Button
|
||||||
variant={sortDir === 'desc' ? 'default' : 'outline'}
|
variant={sortDir === "desc" ? "default" : "outline"}
|
||||||
size="sm"
|
size="sm"
|
||||||
className="flex-1 h-8 text-xs"
|
className="flex-1 h-8 text-xs"
|
||||||
onClick={() => setSortDir('desc')}
|
onClick={() => setSortDir("desc")}
|
||||||
>
|
>
|
||||||
↓ Desc
|
↓ Desc
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant={sortDir === 'asc' ? 'default' : 'outline'}
|
variant={sortDir === "asc" ? "default" : "outline"}
|
||||||
size="sm"
|
size="sm"
|
||||||
className="flex-1 h-8 text-xs"
|
className="flex-1 h-8 text-xs"
|
||||||
onClick={() => setSortDir('asc')}
|
onClick={() => setSortDir("asc")}
|
||||||
>
|
>
|
||||||
↑ Asc
|
↑ Asc
|
||||||
</Button>
|
</Button>
|
||||||
@@ -397,7 +446,7 @@ export function LibraryPage() {
|
|||||||
onValueChange={(v) =>
|
onValueChange={(v) =>
|
||||||
setFilters((f) => ({
|
setFilters((f) => ({
|
||||||
...f,
|
...f,
|
||||||
genre: v === '_all' ? '' : v || '',
|
genre: v === "_all" ? "" : v || "",
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@@ -418,7 +467,7 @@ export function LibraryPage() {
|
|||||||
<label className="text-sm font-medium">Status</label>
|
<label className="text-sm font-medium">Status</label>
|
||||||
<Select
|
<Select
|
||||||
value={statusFilter}
|
value={statusFilter}
|
||||||
onValueChange={(v) => setStatusFilter(v === '_all' ? '' : v)}
|
onValueChange={(v) => setStatusFilter(v === "_all" ? "" : v)}
|
||||||
>
|
>
|
||||||
<SelectTrigger className="h-9">
|
<SelectTrigger className="h-9">
|
||||||
<SelectValue placeholder="Any status" />
|
<SelectValue placeholder="Any status" />
|
||||||
@@ -553,13 +602,19 @@ export function LibraryPage() {
|
|||||||
value={activeTab}
|
value={activeTab}
|
||||||
onValueChange={(v) => setActiveTab(v as FilterTab)}
|
onValueChange={(v) => setActiveTab(v as FilterTab)}
|
||||||
>
|
>
|
||||||
<TabsList className="w-max">
|
<div className="flex w-max items-center gap-2">
|
||||||
|
<TabsList>
|
||||||
<TabsTrigger value="all">All</TabsTrigger>
|
<TabsTrigger value="all">All</TabsTrigger>
|
||||||
<TabsTrigger value="movies">Movies</TabsTrigger>
|
<TabsTrigger value="movies">Movies</TabsTrigger>
|
||||||
<TabsTrigger value="tv">TV</TabsTrigger>
|
<TabsTrigger value="tv">TV</TabsTrigger>
|
||||||
<TabsTrigger value="favorites">Favorites</TabsTrigger>
|
|
||||||
<TabsTrigger value="hidden">Hidden</TabsTrigger>
|
|
||||||
</TabsList>
|
</TabsList>
|
||||||
|
<FilterToggles
|
||||||
|
favoritesOnly={favoritesOnly}
|
||||||
|
onFavoritesChange={setFavoritesOnly}
|
||||||
|
hiddenOnly={hiddenOnly}
|
||||||
|
onHiddenChange={setHiddenOnly}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -587,26 +642,26 @@ export function LibraryPage() {
|
|||||||
<p className="mb-0.5">
|
<p className="mb-0.5">
|
||||||
<code className="bg-accent px-1 rounded text-[11px]">
|
<code className="bg-accent px-1 rounded text-[11px]">
|
||||||
@director:name
|
@director:name
|
||||||
</code>{' '}
|
</code>{" "}
|
||||||
— by director
|
— by director
|
||||||
</p>
|
</p>
|
||||||
<p className="text-muted-foreground mb-0.5">
|
<p className="text-muted-foreground mb-0.5">
|
||||||
<code className="bg-accent px-1 rounded text-[11px]">
|
<code className="bg-accent px-1 rounded text-[11px]">
|
||||||
@country:name
|
@country:name
|
||||||
</code>{' '}
|
</code>{" "}
|
||||||
— coming soon
|
— coming soon
|
||||||
</p>
|
</p>
|
||||||
<p className="text-muted-foreground">
|
<p className="text-muted-foreground">
|
||||||
<code className="bg-accent px-1 rounded text-[11px]">
|
<code className="bg-accent px-1 rounded text-[11px]">
|
||||||
@year:year
|
@year:year
|
||||||
</code>{' '}
|
</code>{" "}
|
||||||
— coming soon
|
— coming soon
|
||||||
</p>
|
</p>
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
|
|
||||||
{search && (
|
{search && (
|
||||||
<Button variant="ghost" size="sm" onClick={() => setSearch('')}>
|
<Button variant="ghost" size="sm" onClick={() => setSearch("")}>
|
||||||
<X className="mr-1 h-4 w-4" /> Clear
|
<X className="mr-1 h-4 w-4" /> Clear
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
@@ -620,7 +675,7 @@ export function LibraryPage() {
|
|||||||
<ArrowUpDown className="h-4 w-4" />
|
<ArrowUpDown className="h-4 w-4" />
|
||||||
{sortLabels[sortField]}
|
{sortLabels[sortField]}
|
||||||
<span className="text-xs opacity-60">
|
<span className="text-xs opacity-60">
|
||||||
{sortDir === 'desc' ? '↓' : '↑'}
|
{sortDir === "desc" ? "↓" : "↑"}
|
||||||
</span>
|
</span>
|
||||||
</Button>
|
</Button>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
@@ -635,8 +690,8 @@ export function LibraryPage() {
|
|||||||
onClick={() => setSortField(value as SortField)}
|
onClick={() => setSortField(value as SortField)}
|
||||||
className={`w-full rounded-md px-3 py-1.5 text-left text-sm transition-colors ${
|
className={`w-full rounded-md px-3 py-1.5 text-left text-sm transition-colors ${
|
||||||
sortField === value
|
sortField === value
|
||||||
? 'bg-accent text-accent-foreground font-medium'
|
? "bg-accent text-accent-foreground font-medium"
|
||||||
: 'hover:bg-accent/50'
|
: "hover:bg-accent/50"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{label}
|
{label}
|
||||||
@@ -645,18 +700,18 @@ export function LibraryPage() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex gap-1 pt-1 border-t border-border">
|
<div className="flex gap-1 pt-1 border-t border-border">
|
||||||
<Button
|
<Button
|
||||||
variant={sortDir === 'desc' ? 'default' : 'outline'}
|
variant={sortDir === "desc" ? "default" : "outline"}
|
||||||
size="sm"
|
size="sm"
|
||||||
className="flex-1 h-8 text-xs"
|
className="flex-1 h-8 text-xs"
|
||||||
onClick={() => setSortDir('desc')}
|
onClick={() => setSortDir("desc")}
|
||||||
>
|
>
|
||||||
↓ Desc
|
↓ Desc
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant={sortDir === 'asc' ? 'default' : 'outline'}
|
variant={sortDir === "asc" ? "default" : "outline"}
|
||||||
size="sm"
|
size="sm"
|
||||||
className="flex-1 h-8 text-xs"
|
className="flex-1 h-8 text-xs"
|
||||||
onClick={() => setSortDir('asc')}
|
onClick={() => setSortDir("asc")}
|
||||||
>
|
>
|
||||||
↑ Asc
|
↑ Asc
|
||||||
</Button>
|
</Button>
|
||||||
@@ -688,7 +743,7 @@ export function LibraryPage() {
|
|||||||
onValueChange={(v) =>
|
onValueChange={(v) =>
|
||||||
setFilters((f) => ({
|
setFilters((f) => ({
|
||||||
...f,
|
...f,
|
||||||
genre: v === '_all' ? '' : v || '',
|
genre: v === "_all" ? "" : v || "",
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@@ -709,7 +764,7 @@ export function LibraryPage() {
|
|||||||
<label className="text-sm font-medium">Status</label>
|
<label className="text-sm font-medium">Status</label>
|
||||||
<Select
|
<Select
|
||||||
value={statusFilter}
|
value={statusFilter}
|
||||||
onValueChange={(v) => setStatusFilter(v === '_all' ? '' : v)}
|
onValueChange={(v) => setStatusFilter(v === "_all" ? "" : v)}
|
||||||
>
|
>
|
||||||
<SelectTrigger className="h-9 w-full">
|
<SelectTrigger className="h-9 w-full">
|
||||||
<SelectValue placeholder="Any status" />
|
<SelectValue placeholder="Any status" />
|
||||||
@@ -834,10 +889,15 @@ export function LibraryPage() {
|
|||||||
<TabsTrigger value="all">All</TabsTrigger>
|
<TabsTrigger value="all">All</TabsTrigger>
|
||||||
<TabsTrigger value="movies">Movies</TabsTrigger>
|
<TabsTrigger value="movies">Movies</TabsTrigger>
|
||||||
<TabsTrigger value="tv">TV Series</TabsTrigger>
|
<TabsTrigger value="tv">TV Series</TabsTrigger>
|
||||||
<TabsTrigger value="favorites">Favorites</TabsTrigger>
|
|
||||||
<TabsTrigger value="hidden">Hidden</TabsTrigger>
|
|
||||||
</TabsList>
|
</TabsList>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
||||||
|
<FilterToggles
|
||||||
|
favoritesOnly={favoritesOnly}
|
||||||
|
onFavoritesChange={setFavoritesOnly}
|
||||||
|
hiddenOnly={hiddenOnly}
|
||||||
|
onHiddenChange={setHiddenOnly}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<EntryLibraryGrid
|
<EntryLibraryGrid
|
||||||
|
|||||||
@@ -8,8 +8,13 @@ import { Skeleton } from "@/components/ui/skeleton";
|
|||||||
import { Switch } from "@/components/ui/switch";
|
import { Switch } from "@/components/ui/switch";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||||
|
import {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from "@/components/ui/tooltip";
|
||||||
import { Search, Heart } from "lucide-react";
|
import { Search, Heart } from "lucide-react";
|
||||||
import { getProfileUrl } from "@/lib/media-utils";
|
import { getProfileUrl, formatDate, calculateAge } from "@/lib/media-utils";
|
||||||
|
|
||||||
type PeopleFilter = "all" | "favorite";
|
type PeopleFilter = "all" | "favorite";
|
||||||
|
|
||||||
@@ -207,6 +212,18 @@ export function PeoplePage() {
|
|||||||
<p className="text-sm font-medium line-clamp-2">
|
<p className="text-sm font-medium line-clamp-2">
|
||||||
{person.name}
|
{person.name}
|
||||||
</p>
|
</p>
|
||||||
|
{person.birthday && (
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger render={<span />}>
|
||||||
|
<span className="text-xs text-muted-foreground">
|
||||||
|
Born: {formatDate(person.birthday)}
|
||||||
|
</span>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>
|
||||||
|
Age: {calculateAge(person.birthday, person.deathday)}
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useParams, useNavigate, useLocation } from "react-router-dom";
|
import { useParams, useNavigate } from "react-router-dom";
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import {
|
import {
|
||||||
usePerson,
|
usePerson,
|
||||||
@@ -13,8 +13,14 @@ import { Skeleton } from "@/components/ui/skeleton";
|
|||||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
import { Separator } from "@/components/ui/separator";
|
import { Separator } from "@/components/ui/separator";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from "@/components/ui/tooltip";
|
||||||
import { EntryCard } from "@/components/entries/EntryCard";
|
import { EntryCard } from "@/components/entries/EntryCard";
|
||||||
import { getProfileUrl, formatDate } from "@/lib/media-utils";
|
import { getTmdbImageUrl } from "@/lib/api";
|
||||||
|
import { formatDate, calculateAge } from "@/lib/media-utils";
|
||||||
import {
|
import {
|
||||||
ChevronLeft,
|
ChevronLeft,
|
||||||
ChevronRight,
|
ChevronRight,
|
||||||
@@ -24,58 +30,131 @@ import {
|
|||||||
ExternalLink,
|
ExternalLink,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import type { TmdbEntry } from "@/types";
|
import type { TmdbEntry } from "@/types";
|
||||||
import type { TmdbFilmographyItem } from "@/api/people";
|
import type {
|
||||||
|
TmdbFilmographyItem,
|
||||||
|
TmdbFilmographyResponse,
|
||||||
|
} from "@/api/people";
|
||||||
|
|
||||||
const TMDB_IMG = "https://image.tmdb.org/t/p";
|
/** Person data normalized from either the local DB or a TMDB preview. */
|
||||||
|
interface PersonProfile {
|
||||||
|
name: string;
|
||||||
|
biography: string | null;
|
||||||
|
birthday: string | null;
|
||||||
|
deathday: string | null;
|
||||||
|
place_of_birth: string | null;
|
||||||
|
profile_path: string | null;
|
||||||
|
known_for_department: string | null;
|
||||||
|
tmdb_id: number | null;
|
||||||
|
favorite: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Person page for both sources:
|
||||||
|
* - `/people/:id`: the person is in the local DB, so details come from there
|
||||||
|
* and the filmography from TMDB via the local id.
|
||||||
|
* - `/people/tmdb/:tmdbId`: the person is not in the local DB, so everything
|
||||||
|
* comes from the TMDB preview. If the preview reports a local id, redirect.
|
||||||
|
*/
|
||||||
export function PersonDetailsPage() {
|
export function PersonDetailsPage() {
|
||||||
const { id, tmdbId } = useParams<{ id?: string; tmdbId?: string }>();
|
const { id, tmdbId } = useParams<{ id?: string; tmdbId?: string }>();
|
||||||
const location = useLocation();
|
|
||||||
const isTmdbMode = location.pathname.startsWith("/people/tmdb/");
|
|
||||||
|
|
||||||
if (isTmdbMode && tmdbId) {
|
|
||||||
return <TmdbPersonView tmdbId={parseInt(tmdbId, 10)} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return <LocalPersonView personId={parseInt(id!, 10)} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ─── Local DB person ─── */
|
|
||||||
|
|
||||||
function LocalPersonView({ personId }: { personId: number }) {
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { data: person, isLoading, isError } = usePerson(personId);
|
const localId = id ? parseInt(id, 10) : 0;
|
||||||
const { data: tmdbFilmography, isLoading: tmdbLoading } =
|
const isLocal = !!localId;
|
||||||
usePersonTmdbFilmography(personId);
|
const tmdbIdNum = !isLocal && tmdbId ? parseInt(tmdbId, 10) : 0;
|
||||||
|
|
||||||
|
// Queries are disabled when their id is 0, so only one source is fetched.
|
||||||
|
const localPerson = usePerson(localId);
|
||||||
|
const localFilmography = usePersonTmdbFilmography(localId);
|
||||||
|
const tmdbPreview = useTmdbPersonPreview(tmdbIdNum);
|
||||||
|
|
||||||
const updatePerson = useUpdatePerson();
|
const updatePerson = useUpdatePerson();
|
||||||
|
const fetchPerson = useFetchPersonByTmdbId();
|
||||||
useLibrary();
|
useLibrary();
|
||||||
const libraryMap = useLibraryStore((s) => s.entries);
|
const libraryMap = useLibraryStore((s) => s.entries);
|
||||||
const libraryLoaded = useLibraryStore((s) => s.isLoaded);
|
const libraryLoaded = useLibraryStore((s) => s.isLoaded);
|
||||||
|
|
||||||
|
const existingLocalId = tmdbPreview.data?.local_id;
|
||||||
|
useEffect(() => {
|
||||||
|
if (existingLocalId) {
|
||||||
|
navigate(`/people/${existingLocalId}`, { replace: true });
|
||||||
|
}
|
||||||
|
}, [existingLocalId, navigate]);
|
||||||
|
|
||||||
|
const isError = isLocal ? localPerson.isError : tmdbPreview.isError;
|
||||||
|
|
||||||
if (isError) {
|
if (isError) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-center justify-center gap-3 py-20">
|
<div className="flex flex-col items-center justify-center gap-3 py-20">
|
||||||
<p className="text-lg font-semibold">Person not found</p>
|
<p className="text-lg font-semibold">Person not found</p>
|
||||||
<p className="text-sm text-muted-foreground">
|
<p className="text-sm text-muted-foreground">
|
||||||
This person could not be loaded. They may not exist in the database.
|
{isLocal
|
||||||
|
? "This person could not be loaded. They may not exist in the database."
|
||||||
|
: "Could not load person data from TMDB."}
|
||||||
</p>
|
</p>
|
||||||
<Button variant="outline" onClick={() => navigate("/people")}>
|
<Button
|
||||||
Back to People
|
variant="outline"
|
||||||
|
onClick={() => (isLocal ? navigate("/people") : navigate(-1))}
|
||||||
|
>
|
||||||
|
{isLocal ? "Back to People" : "Go back"}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLoading || !person) {
|
let person: PersonProfile | null = null;
|
||||||
|
let filmography: TmdbFilmographyResponse | undefined;
|
||||||
|
let filmographyLoading = false;
|
||||||
|
|
||||||
|
if (isLocal && localPerson.data) {
|
||||||
|
const p = localPerson.data;
|
||||||
|
person = {
|
||||||
|
name: p.name,
|
||||||
|
biography: p.biography ?? null,
|
||||||
|
birthday: p.birthday ?? null,
|
||||||
|
deathday: p.deathday ?? null,
|
||||||
|
place_of_birth: p.place_of_birth ?? null,
|
||||||
|
profile_path: p.profile_path ?? null,
|
||||||
|
known_for_department: p.known_for_department ?? null,
|
||||||
|
tmdb_id: p.tmdb_id ?? null,
|
||||||
|
favorite: !!p.favorite,
|
||||||
|
};
|
||||||
|
filmography = localFilmography.data;
|
||||||
|
filmographyLoading = localFilmography.isLoading;
|
||||||
|
} else if (!isLocal && tmdbPreview.data && !existingLocalId) {
|
||||||
|
const p = tmdbPreview.data;
|
||||||
|
person = { ...p, favorite: false };
|
||||||
|
filmography = p.filmography;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Still loading, or about to redirect to the local page.
|
||||||
|
if (!person) {
|
||||||
return <PersonSkeleton />;
|
return <PersonSkeleton />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isFavorite = person.favorite;
|
||||||
|
|
||||||
|
const toggleFavorite = () => {
|
||||||
|
updatePerson.mutate({ id: localId, data: { favorite: !isFavorite } });
|
||||||
|
};
|
||||||
|
|
||||||
|
const addToLibrary = () => {
|
||||||
|
fetchPerson.mutate(tmdbIdNum, {
|
||||||
|
onSuccess: (added) => {
|
||||||
|
navigate(`/people/${added.id}`, { replace: true });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-8 animate-page-enter">
|
<div className="space-y-8 animate-page-enter">
|
||||||
<div className="flex flex-col items-center gap-4 sm:flex-row sm:items-start sm:gap-8">
|
<div className="flex flex-col items-center gap-4 sm:flex-row sm:items-start sm:gap-8">
|
||||||
<Avatar className="h-32 w-32 shrink-0 sm:h-48 sm:w-48">
|
<Avatar className="h-32 w-32 shrink-0 sm:h-48 sm:w-48">
|
||||||
<AvatarImage
|
<AvatarImage
|
||||||
src={getProfileUrl(person.profile_path)}
|
src={
|
||||||
|
person.profile_path
|
||||||
|
? getTmdbImageUrl(person.profile_path, "w300")
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
alt={person.name}
|
alt={person.name}
|
||||||
/>
|
/>
|
||||||
<AvatarFallback className="text-2xl sm:text-3xl">
|
<AvatarFallback className="text-2xl sm:text-3xl">
|
||||||
@@ -88,22 +167,33 @@ function LocalPersonView({ personId }: { personId: number }) {
|
|||||||
<div className="space-y-2 text-center sm:text-left sm:space-y-3">
|
<div className="space-y-2 text-center sm:text-left sm:space-y-3">
|
||||||
<div className="flex items-center gap-2 justify-center sm:justify-start">
|
<div className="flex items-center gap-2 justify-center sm:justify-start">
|
||||||
<h1 className="text-2xl font-bold sm:text-3xl">{person.name}</h1>
|
<h1 className="text-2xl font-bold sm:text-3xl">{person.name}</h1>
|
||||||
|
{isLocal ? (
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
className="h-8 w-8 shrink-0"
|
className="h-8 w-8 shrink-0"
|
||||||
onClick={() =>
|
onClick={toggleFavorite}
|
||||||
updatePerson.mutate({
|
|
||||||
id: person.id,
|
|
||||||
data: { favorite: !person.favorite },
|
|
||||||
})
|
|
||||||
}
|
|
||||||
disabled={updatePerson.isPending}
|
disabled={updatePerson.isPending}
|
||||||
>
|
>
|
||||||
<Heart
|
<Heart
|
||||||
className={`h-5 w-5 ${person.favorite ? "fill-red-500 text-red-500" : "text-muted-foreground"}`}
|
className={`h-5 w-5 ${isFavorite ? "fill-red-500 text-red-500" : "text-muted-foreground"}`}
|
||||||
/>
|
/>
|
||||||
</Button>
|
</Button>
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
onClick={addToLibrary}
|
||||||
|
disabled={fetchPerson.isPending}
|
||||||
|
size="sm"
|
||||||
|
className="ml-1"
|
||||||
|
>
|
||||||
|
{fetchPerson.isPending ? (
|
||||||
|
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||||
|
) : (
|
||||||
|
<Plus className="mr-2 h-4 w-4" />
|
||||||
|
)}
|
||||||
|
{fetchPerson.isPending ? "Adding..." : "Add to Library"}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<PersonMeta
|
<PersonMeta
|
||||||
known_for_department={person.known_for_department}
|
known_for_department={person.known_for_department}
|
||||||
@@ -123,117 +213,12 @@ function LocalPersonView({ personId }: { personId: number }) {
|
|||||||
<Separator />
|
<Separator />
|
||||||
|
|
||||||
<FilmographySection
|
<FilmographySection
|
||||||
|
// Reset pagination when moving between people on the same route
|
||||||
|
key={isLocal ? `local-${localId}` : `tmdb-${tmdbIdNum}`}
|
||||||
libraryMap={libraryMap}
|
libraryMap={libraryMap}
|
||||||
libraryLoaded={libraryLoaded}
|
libraryLoaded={libraryLoaded}
|
||||||
tmdbFilmography={tmdbFilmography}
|
tmdbFilmography={filmography}
|
||||||
tmdbLoading={tmdbLoading}
|
tmdbLoading={filmographyLoading}
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ─── TMDB person (not in library) ─── */
|
|
||||||
|
|
||||||
function TmdbPersonView({ tmdbId }: { tmdbId: number }) {
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const { data: preview, isLoading, isError } = useTmdbPersonPreview(tmdbId);
|
|
||||||
const fetchPerson = useFetchPersonByTmdbId();
|
|
||||||
useLibrary();
|
|
||||||
const libraryMap = useLibraryStore((s) => s.entries);
|
|
||||||
const libraryLoaded = useLibraryStore((s) => s.isLoaded);
|
|
||||||
|
|
||||||
// If person already exists in local DB, redirect to their local page
|
|
||||||
useEffect(() => {
|
|
||||||
if (preview?.local_id) {
|
|
||||||
navigate(`/people/${preview.local_id}`, { replace: true });
|
|
||||||
}
|
|
||||||
}, [preview?.local_id, navigate]);
|
|
||||||
|
|
||||||
if (isError) {
|
|
||||||
return (
|
|
||||||
<div className="flex flex-col items-center justify-center gap-3 py-20">
|
|
||||||
<p className="text-lg font-semibold">Person not found</p>
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
Could not load person data from TMDB.
|
|
||||||
</p>
|
|
||||||
<Button variant="outline" onClick={() => navigate(-1)}>
|
|
||||||
Go back
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isLoading || !preview) {
|
|
||||||
return <PersonSkeleton />;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Redirecting to local page, show skeleton while navigating
|
|
||||||
if (preview.local_id) {
|
|
||||||
return <PersonSkeleton />;
|
|
||||||
}
|
|
||||||
|
|
||||||
const profileUrl = preview.profile_path
|
|
||||||
? `${TMDB_IMG}/w300${preview.profile_path}`
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
const handleAddToLibrary = () => {
|
|
||||||
fetchPerson.mutate(tmdbId, {
|
|
||||||
onSuccess: (person) => {
|
|
||||||
navigate(`/people/${person.id}`, { replace: true });
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="space-y-8 animate-page-enter">
|
|
||||||
<div className="flex flex-col items-center gap-4 sm:flex-row sm:items-start sm:gap-8">
|
|
||||||
<Avatar className="h-32 w-32 shrink-0 sm:h-48 sm:w-48">
|
|
||||||
<AvatarImage src={profileUrl} alt={preview.name} />
|
|
||||||
<AvatarFallback className="text-2xl sm:text-3xl">
|
|
||||||
{preview.name
|
|
||||||
.split(" ")
|
|
||||||
.map((n: string) => n[0])
|
|
||||||
.join("")}
|
|
||||||
</AvatarFallback>
|
|
||||||
</Avatar>
|
|
||||||
<div className="space-y-2 text-center sm:text-left sm:space-y-3">
|
|
||||||
<div className="flex items-center gap-3 justify-center sm:justify-start">
|
|
||||||
<h1 className="text-2xl font-bold sm:text-3xl">{preview.name}</h1>
|
|
||||||
<Button
|
|
||||||
onClick={handleAddToLibrary}
|
|
||||||
disabled={fetchPerson.isPending}
|
|
||||||
size="sm"
|
|
||||||
>
|
|
||||||
{fetchPerson.isPending ? (
|
|
||||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
||||||
) : (
|
|
||||||
<Plus className="mr-2 h-4 w-4" />
|
|
||||||
)}
|
|
||||||
{fetchPerson.isPending ? "Adding..." : "Add to Library"}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
<PersonMeta
|
|
||||||
known_for_department={preview.known_for_department}
|
|
||||||
birthday={preview.birthday}
|
|
||||||
deathday={preview.deathday}
|
|
||||||
place_of_birth={preview.place_of_birth}
|
|
||||||
tmdb_id={preview.tmdb_id}
|
|
||||||
/>
|
|
||||||
{preview.biography && (
|
|
||||||
<p className="text-sm text-muted-foreground leading-relaxed max-w-2xl line-clamp-6">
|
|
||||||
{preview.biography}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Separator />
|
|
||||||
|
|
||||||
<FilmographySection
|
|
||||||
libraryMap={libraryMap}
|
|
||||||
libraryLoaded={libraryLoaded}
|
|
||||||
tmdbFilmography={preview.filmography}
|
|
||||||
tmdbLoading={false}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -260,7 +245,14 @@ function PersonMeta({
|
|||||||
{birthday && (
|
{birthday && (
|
||||||
<>
|
<>
|
||||||
<span>•</span>
|
<span>•</span>
|
||||||
<span>Born: {formatDate(birthday)}</span>
|
<Tooltip>
|
||||||
|
<TooltipTrigger render={<span className="cursor-default" />}>
|
||||||
|
Born: {formatDate(birthday)}
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>
|
||||||
|
Age: {calculateAge(birthday, deathday)}
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{deathday && (
|
{deathday && (
|
||||||
|
|||||||
@@ -1,364 +0,0 @@
|
|||||||
import { useState } from "react";
|
|
||||||
import { useParams, useNavigate } from "react-router-dom";
|
|
||||||
import {
|
|
||||||
useTmdbPersonPreview,
|
|
||||||
useFetchPersonByTmdbId,
|
|
||||||
} from "@/hooks/usePeople";
|
|
||||||
import { useLibrary } from "@/hooks/useEntries";
|
|
||||||
import { useLibraryStore } from "@/stores/useLibraryStore";
|
|
||||||
import { Skeleton } from "@/components/ui/skeleton";
|
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
|
||||||
import { Separator } from "@/components/ui/separator";
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { EntryCard } from "@/components/entries/EntryCard";
|
|
||||||
import { getProfileUrl, formatDate } from "@/lib/media-utils";
|
|
||||||
import { Plus, Loader2, ChevronLeft, ChevronRight } from "lucide-react";
|
|
||||||
import type { TmdbEntry } from "@/types";
|
|
||||||
import type { TmdbFilmographyItem } from "@/api/people";
|
|
||||||
|
|
||||||
const TMDB_IMG = "https://image.tmdb.org/t/p";
|
|
||||||
|
|
||||||
export function PersonTmdbRedirectPage() {
|
|
||||||
const { tmdbId } = useParams<{ tmdbId: string }>();
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const tmdbIdNum = parseInt(tmdbId!, 10);
|
|
||||||
|
|
||||||
const { data: preview, isLoading, isError } = useTmdbPersonPreview(tmdbIdNum);
|
|
||||||
const fetchPerson = useFetchPersonByTmdbId();
|
|
||||||
useLibrary();
|
|
||||||
const libraryMap = useLibraryStore((s) => s.entries);
|
|
||||||
const libraryLoaded = useLibraryStore((s) => s.isLoaded);
|
|
||||||
|
|
||||||
if (isLoading || !preview) {
|
|
||||||
return (
|
|
||||||
<div className="space-y-6">
|
|
||||||
<div className="flex flex-col items-center gap-4 sm:flex-row sm:items-start sm:gap-6">
|
|
||||||
<Skeleton className="h-32 w-32 rounded-full sm:h-48 sm:w-48" />
|
|
||||||
<div className="flex-1 space-y-3 w-full">
|
|
||||||
<Skeleton className="h-8 w-48 mx-auto sm:mx-0" />
|
|
||||||
<Skeleton className="h-4 w-32 mx-auto sm:mx-0" />
|
|
||||||
<Skeleton className="h-20 w-full" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isError) {
|
|
||||||
return (
|
|
||||||
<div className="flex flex-col items-center justify-center gap-3 py-20">
|
|
||||||
<p className="text-lg font-semibold">Person not found</p>
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
Could not load person data from TMDB.
|
|
||||||
</p>
|
|
||||||
<Button variant="outline" onClick={() => navigate(-1)}>
|
|
||||||
Go back
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const profileUrl = preview.profile_path
|
|
||||||
? `${TMDB_IMG}/w300${preview.profile_path}`
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
const handleAddToLibrary = () => {
|
|
||||||
fetchPerson.mutate(tmdbIdNum, {
|
|
||||||
onSuccess: (person) => {
|
|
||||||
navigate(`/people/${person.id}`, { replace: true });
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="space-y-8 animate-page-enter">
|
|
||||||
<div className="flex flex-col items-center gap-4 sm:flex-row sm:items-start sm:gap-8">
|
|
||||||
<Avatar className="h-32 w-32 shrink-0 sm:h-48 sm:w-48">
|
|
||||||
<AvatarImage src={profileUrl} alt={preview.name} />
|
|
||||||
<AvatarFallback className="text-2xl sm:text-3xl">
|
|
||||||
{preview.name
|
|
||||||
.split(" ")
|
|
||||||
.map((n: string) => n[0])
|
|
||||||
.join("")}
|
|
||||||
</AvatarFallback>
|
|
||||||
</Avatar>
|
|
||||||
<div className="space-y-2 text-center sm:text-left sm:space-y-3">
|
|
||||||
<div className="flex items-center gap-3 justify-center sm:justify-start">
|
|
||||||
<h1 className="text-2xl font-bold sm:text-3xl">{preview.name}</h1>
|
|
||||||
<Button
|
|
||||||
onClick={handleAddToLibrary}
|
|
||||||
disabled={fetchPerson.isPending}
|
|
||||||
size="sm"
|
|
||||||
>
|
|
||||||
{fetchPerson.isPending ? (
|
|
||||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
||||||
) : (
|
|
||||||
<Plus className="mr-2 h-4 w-4" />
|
|
||||||
)}
|
|
||||||
{fetchPerson.isPending ? "Adding..." : "Add to Library"}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
<div className="flex flex-wrap items-center justify-center gap-2 text-sm text-muted-foreground sm:justify-start sm:gap-3">
|
|
||||||
{preview.known_for_department && (
|
|
||||||
<span>{preview.known_for_department}</span>
|
|
||||||
)}
|
|
||||||
{preview.birthday && (
|
|
||||||
<>
|
|
||||||
<span>•</span>
|
|
||||||
<span>Born: {formatDate(preview.birthday)}</span>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{preview.deathday && (
|
|
||||||
<>
|
|
||||||
<span>•</span>
|
|
||||||
<span>Died: {formatDate(preview.deathday)}</span>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{preview.place_of_birth && (
|
|
||||||
<>
|
|
||||||
<span>•</span>
|
|
||||||
<span>{preview.place_of_birth}</span>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
{preview.biography && (
|
|
||||||
<p className="text-sm text-muted-foreground leading-relaxed max-w-2xl line-clamp-6">
|
|
||||||
{preview.biography}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Separator />
|
|
||||||
|
|
||||||
<TmdbFilmographySection
|
|
||||||
filmography={preview.filmography}
|
|
||||||
libraryMap={libraryMap}
|
|
||||||
libraryLoaded={libraryLoaded}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
interface TmdbFilmographySectionProps {
|
|
||||||
filmography: { cast: TmdbFilmographyItem[]; crew: TmdbFilmographyItem[] };
|
|
||||||
libraryMap: Map<number, import("@/types").Entry>;
|
|
||||||
libraryLoaded: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
function TmdbFilmographySection({
|
|
||||||
filmography,
|
|
||||||
libraryMap,
|
|
||||||
libraryLoaded,
|
|
||||||
}: TmdbFilmographySectionProps) {
|
|
||||||
const [libraryPage, setLibraryPage] = useState(0);
|
|
||||||
const [otherPage, setOtherPage] = useState(0);
|
|
||||||
const PAGE_SIZE = 6;
|
|
||||||
const GRID =
|
|
||||||
"grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6";
|
|
||||||
|
|
||||||
if (!libraryLoaded) {
|
|
||||||
return (
|
|
||||||
<div className="space-y-4">
|
|
||||||
<h2 className="text-xl font-semibold">Filmography</h2>
|
|
||||||
<div className={GRID}>
|
|
||||||
{Array.from({ length: 6 }).map((_, i) => (
|
|
||||||
<Skeleton key={i} className="aspect-2/3 rounded-lg" />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const allCredits = [
|
|
||||||
...(filmography.cast ?? []),
|
|
||||||
...(filmography.crew?.filter(
|
|
||||||
(c) => c.job === "Director" || c.department === "Directing",
|
|
||||||
) ?? []),
|
|
||||||
];
|
|
||||||
const seenIds = new Set<number>();
|
|
||||||
const deduped = allCredits.filter((c) => {
|
|
||||||
if (seenIds.has(c.id)) return false;
|
|
||||||
seenIds.add(c.id);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
const tmdbIdToLibraryEntry = new Map<number, import("@/types").Entry>();
|
|
||||||
for (const entry of libraryMap.values()) {
|
|
||||||
if (entry.entryIds?.tmdb_id != null) {
|
|
||||||
tmdbIdToLibraryEntry.set(Number(entry.entryIds.tmdb_id), entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const sorted = [...deduped].sort(
|
|
||||||
(a, b) => (b.popularity ?? 0) - (a.popularity ?? 0),
|
|
||||||
);
|
|
||||||
const libraryCredits = sorted.filter((c) => tmdbIdToLibraryEntry.has(c.id));
|
|
||||||
|
|
||||||
const isSelfRole = (character?: string) => {
|
|
||||||
if (!character) return false;
|
|
||||||
const lower = character.toLowerCase().trim();
|
|
||||||
return (
|
|
||||||
lower === "self" ||
|
|
||||||
lower.startsWith("self -") ||
|
|
||||||
lower.startsWith("self (") ||
|
|
||||||
lower === "themselves" ||
|
|
||||||
lower === "himself" ||
|
|
||||||
lower === "herself"
|
|
||||||
);
|
|
||||||
};
|
|
||||||
const otherCredits = sorted
|
|
||||||
.filter((c) => !tmdbIdToLibraryEntry.has(c.id))
|
|
||||||
.sort((a, b) => {
|
|
||||||
const aSelf = isSelfRole(a.character) ? 1 : 0;
|
|
||||||
const bSelf = isSelfRole(b.character) ? 1 : 0;
|
|
||||||
if (aSelf !== bSelf) return aSelf - bSelf;
|
|
||||||
const dateA = new Date(
|
|
||||||
a.release_date || a.first_air_date || "1900",
|
|
||||||
).getTime();
|
|
||||||
const dateB = new Date(
|
|
||||||
b.release_date || b.first_air_date || "1900",
|
|
||||||
).getTime();
|
|
||||||
return dateB - dateA;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (sorted.length === 0) {
|
|
||||||
return (
|
|
||||||
<div className="space-y-4">
|
|
||||||
<h2 className="text-xl font-semibold">Filmography</h2>
|
|
||||||
<p className="text-sm text-muted-foreground">No filmography found.</p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const librarySlice = libraryCredits.slice(
|
|
||||||
libraryPage * PAGE_SIZE,
|
|
||||||
(libraryPage + 1) * PAGE_SIZE,
|
|
||||||
);
|
|
||||||
const otherSlice = otherCredits.slice(
|
|
||||||
otherPage * PAGE_SIZE,
|
|
||||||
(otherPage + 1) * PAGE_SIZE,
|
|
||||||
);
|
|
||||||
const libraryTotalPages = Math.ceil(libraryCredits.length / PAGE_SIZE);
|
|
||||||
const otherTotalPages = Math.ceil(otherCredits.length / PAGE_SIZE);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="space-y-8">
|
|
||||||
<h2 className="text-xl font-semibold">Filmography</h2>
|
|
||||||
|
|
||||||
{libraryCredits.length > 0 && (
|
|
||||||
<div className="space-y-3">
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<h3 className="text-sm font-medium text-muted-foreground uppercase tracking-wide">
|
|
||||||
In Your Library ({libraryCredits.length})
|
|
||||||
</h3>
|
|
||||||
{libraryTotalPages > 1 && (
|
|
||||||
<div className="flex items-center gap-1">
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
className="h-7 w-7"
|
|
||||||
disabled={libraryPage === 0}
|
|
||||||
onClick={() => setLibraryPage((p) => p - 1)}
|
|
||||||
>
|
|
||||||
<ChevronLeft className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
<span className="text-xs text-muted-foreground tabular-nums">
|
|
||||||
{libraryPage + 1}/{libraryTotalPages}
|
|
||||||
</span>
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
className="h-7 w-7"
|
|
||||||
disabled={libraryPage === libraryTotalPages - 1}
|
|
||||||
onClick={() => setLibraryPage((p) => p + 1)}
|
|
||||||
>
|
|
||||||
<ChevronRight className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div className={GRID}>
|
|
||||||
{librarySlice.map((credit) => {
|
|
||||||
const entry = tmdbIdToLibraryEntry.get(credit.id)!;
|
|
||||||
return (
|
|
||||||
<div key={credit.id} className="space-y-1">
|
|
||||||
<EntryCard entry={entry} />
|
|
||||||
{credit.character && (
|
|
||||||
<p className="text-xs text-muted-foreground text-center line-clamp-1 px-1">
|
|
||||||
{credit.character}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{otherCredits.length > 0 && (
|
|
||||||
<div className="space-y-3">
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<h3 className="text-sm font-medium text-muted-foreground uppercase tracking-wide">
|
|
||||||
Not in Library ({otherCredits.length})
|
|
||||||
</h3>
|
|
||||||
{otherTotalPages > 1 && (
|
|
||||||
<div className="flex items-center gap-1">
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
className="h-7 w-7"
|
|
||||||
disabled={otherPage === 0}
|
|
||||||
onClick={() => setOtherPage((p) => p - 1)}
|
|
||||||
>
|
|
||||||
<ChevronLeft className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
<span className="text-xs text-muted-foreground tabular-nums">
|
|
||||||
{otherPage + 1}/{otherTotalPages}
|
|
||||||
</span>
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
className="h-7 w-7"
|
|
||||||
disabled={otherPage === otherTotalPages - 1}
|
|
||||||
onClick={() => setOtherPage((p) => p + 1)}
|
|
||||||
>
|
|
||||||
<ChevronRight className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div className={GRID}>
|
|
||||||
{otherSlice.map((credit) => {
|
|
||||||
const tmdbEntry: TmdbEntry = {
|
|
||||||
id: credit.id,
|
|
||||||
title: credit.title,
|
|
||||||
name: credit.name,
|
|
||||||
poster_path: credit.poster_path,
|
|
||||||
backdrop_path: null,
|
|
||||||
release_date: credit.release_date,
|
|
||||||
first_air_date: credit.first_air_date,
|
|
||||||
media_type: credit.media_type,
|
|
||||||
overview: "",
|
|
||||||
vote_average: 0,
|
|
||||||
vote_count: 0,
|
|
||||||
genre_ids: [],
|
|
||||||
popularity: credit.popularity ?? 0,
|
|
||||||
};
|
|
||||||
return (
|
|
||||||
<div key={credit.id} className="space-y-1">
|
|
||||||
<EntryCard tmdbEntry={tmdbEntry} />
|
|
||||||
{credit.character && (
|
|
||||||
<p className="text-xs text-muted-foreground text-center line-clamp-1 px-1">
|
|
||||||
{credit.character}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
|
|
||||||
type FilterTab = "all" | "movies" | "tv" | "favorites" | "hidden";
|
type FilterTab = "all" | "movies" | "tv";
|
||||||
type SortField =
|
type SortField =
|
||||||
| "date_last_seen"
|
| "date_last_seen"
|
||||||
| "createdAt"
|
| "createdAt"
|
||||||
@@ -25,9 +25,13 @@ interface LibraryFiltersState {
|
|||||||
sortField: SortField;
|
sortField: SortField;
|
||||||
sortDir: SortDir;
|
sortDir: SortDir;
|
||||||
filters: Filters;
|
filters: Filters;
|
||||||
|
favoritesOnly: boolean;
|
||||||
|
hiddenOnly: boolean;
|
||||||
|
|
||||||
setActiveTab: (tab: FilterTab) => void;
|
setActiveTab: (tab: FilterTab) => void;
|
||||||
setSearch: (search: string) => void;
|
setSearch: (search: string) => void;
|
||||||
|
setFavoritesOnly: (value: boolean) => void;
|
||||||
|
setHiddenOnly: (value: boolean) => void;
|
||||||
setSortField: (field: SortField) => void;
|
setSortField: (field: SortField) => void;
|
||||||
setSortDir: (dir: SortDir) => void;
|
setSortDir: (dir: SortDir) => void;
|
||||||
setFilters: (updater: Filters | ((prev: Filters) => Filters)) => void;
|
setFilters: (updater: Filters | ((prev: Filters) => Filters)) => void;
|
||||||
@@ -51,9 +55,13 @@ export const useLibraryFiltersStore = create<LibraryFiltersState>((set) => ({
|
|||||||
sortField: "date_last_seen",
|
sortField: "date_last_seen",
|
||||||
sortDir: "desc",
|
sortDir: "desc",
|
||||||
filters: defaultFilters,
|
filters: defaultFilters,
|
||||||
|
favoritesOnly: false,
|
||||||
|
hiddenOnly: false,
|
||||||
|
|
||||||
setActiveTab: (tab) => set({ activeTab: tab }),
|
setActiveTab: (tab) => set({ activeTab: tab }),
|
||||||
setSearch: (search) => set({ search }),
|
setSearch: (search) => set({ search }),
|
||||||
|
setFavoritesOnly: (value) => set({ favoritesOnly: value }),
|
||||||
|
setHiddenOnly: (value) => set({ hiddenOnly: value }),
|
||||||
setSortField: (field) => set({ sortField: field }),
|
setSortField: (field) => set({ sortField: field }),
|
||||||
setSortDir: (dir) => set({ sortDir: dir }),
|
setSortDir: (dir) => set({ sortDir: dir }),
|
||||||
setFilters: (updater) =>
|
setFilters: (updater) =>
|
||||||
@@ -68,6 +76,8 @@ export const useLibraryFiltersStore = create<LibraryFiltersState>((set) => ({
|
|||||||
sortField: "date_last_seen",
|
sortField: "date_last_seen",
|
||||||
sortDir: "desc",
|
sortDir: "desc",
|
||||||
filters: defaultFilters,
|
filters: defaultFilters,
|
||||||
|
favoritesOnly: false,
|
||||||
|
hiddenOnly: false,
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user