Normalize to double quotes across all files with Prettier
This commit is contained in:
1 parent
73bff72cec
commit
a5659cf4c8
190 files changed
+9523
-8859
No files matched your search
@@ -1,69 +1,83 @@
|
||||
import { useState, useMemo, useEffect, useRef } from 'react';
|
||||
import { useParams, Link } from 'react-router-dom';
|
||||
import { useEntry, useEntryCredits } from '@/hooks/useEntries';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { useState, useMemo, useEffect, useRef } from "react";
|
||||
import { useParams, Link } from "react-router-dom";
|
||||
import { useEntry, useEntryCredits } from "@/hooks/useEntries";
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { getProfileUrl } from '@/lib/media-utils';
|
||||
import { ArrowUpDown } from 'lucide-react';
|
||||
import type { Credit } from '@/types';
|
||||
} from "@/components/ui/select";
|
||||
import { getProfileUrl } from "@/lib/media-utils";
|
||||
import { ArrowUpDown } from "lucide-react";
|
||||
import type { Credit } from "@/types";
|
||||
|
||||
type SortField = 'order' | 'popularity' | 'name' | 'birthday' | 'gender' | 'episode_count';
|
||||
type SortDir = 'asc' | 'desc';
|
||||
type CastFilter = 'all' | 'cast' | 'crew';
|
||||
type SortField =
|
||||
| "order"
|
||||
| "popularity"
|
||||
| "name"
|
||||
| "birthday"
|
||||
| "gender"
|
||||
| "episode_count";
|
||||
type SortDir = "asc" | "desc";
|
||||
type CastFilter = "all" | "cast" | "crew";
|
||||
|
||||
const PAGE_SIZE = 24;
|
||||
|
||||
const SORT_LABELS: Record<SortField, string> = {
|
||||
order: 'Credit Order',
|
||||
popularity: 'Popularity',
|
||||
name: 'Name',
|
||||
birthday: 'Birthday',
|
||||
gender: 'Gender',
|
||||
episode_count: 'Episodes',
|
||||
order: "Credit Order",
|
||||
popularity: "Popularity",
|
||||
name: "Name",
|
||||
birthday: "Birthday",
|
||||
gender: "Gender",
|
||||
episode_count: "Episodes",
|
||||
};
|
||||
|
||||
const FILTER_LABELS: Record<CastFilter, string> = {
|
||||
all: 'All',
|
||||
cast: 'Cast',
|
||||
crew: 'Crew',
|
||||
all: "All",
|
||||
cast: "Cast",
|
||||
crew: "Crew",
|
||||
};
|
||||
|
||||
function sortCredits(credits: Credit[], field: SortField, dir: SortDir): Credit[] {
|
||||
function sortCredits(
|
||||
credits: Credit[],
|
||||
field: SortField,
|
||||
dir: SortDir,
|
||||
): Credit[] {
|
||||
return [...credits].sort((a, b) => {
|
||||
let cmp = 0;
|
||||
switch (field) {
|
||||
case 'order':
|
||||
case "order":
|
||||
cmp = (a.order ?? 9999) - (b.order ?? 9999);
|
||||
break;
|
||||
case 'popularity':
|
||||
case "popularity":
|
||||
cmp = (b.people?.popularity ?? 0) - (a.people?.popularity ?? 0);
|
||||
break;
|
||||
case 'name':
|
||||
cmp = (a.people?.name ?? '').localeCompare(b.people?.name ?? '');
|
||||
case "name":
|
||||
cmp = (a.people?.name ?? "").localeCompare(b.people?.name ?? "");
|
||||
break;
|
||||
case 'birthday': {
|
||||
const da = a.people?.birthday ? new Date(a.people.birthday).getTime() : 0;
|
||||
const db = b.people?.birthday ? new Date(b.people.birthday).getTime() : 0;
|
||||
case "birthday": {
|
||||
const da = a.people?.birthday
|
||||
? new Date(a.people.birthday).getTime()
|
||||
: 0;
|
||||
const db = b.people?.birthday
|
||||
? new Date(b.people.birthday).getTime()
|
||||
: 0;
|
||||
cmp = da - db;
|
||||
break;
|
||||
}
|
||||
case 'gender':
|
||||
case "gender":
|
||||
cmp = (a.people?.gender ?? 0) - (b.people?.gender ?? 0);
|
||||
break;
|
||||
case 'episode_count':
|
||||
case "episode_count":
|
||||
cmp = (b.episode_count ?? 0) - (a.episode_count ?? 0);
|
||||
break;
|
||||
}
|
||||
return dir === 'asc' ? cmp : -cmp;
|
||||
return dir === "asc" ? cmp : -cmp;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -71,38 +85,51 @@ export function EntryCastsPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const entryId = parseInt(id!, 10);
|
||||
const { data: entry, isLoading } = useEntry(entryId);
|
||||
const { data: allCredits = [], isLoading: creditsLoading } = useEntryCredits(entryId);
|
||||
const { data: allCredits = [], isLoading: creditsLoading } =
|
||||
useEntryCredits(entryId);
|
||||
|
||||
const [sortField, setSortField] = useState<SortField>('episode_count');
|
||||
const [sortDir, setSortDir] = useState<SortDir>('asc');
|
||||
const [filter, setFilter] = useState<CastFilter>('cast');
|
||||
const [search, setSearch] = useState('');
|
||||
const [sortField, setSortField] = useState<SortField>("episode_count");
|
||||
const [sortDir, setSortDir] = useState<SortDir>("asc");
|
||||
const [filter, setFilter] = useState<CastFilter>("cast");
|
||||
const [search, setSearch] = useState("");
|
||||
const [visibleCount, setVisibleCount] = useState(PAGE_SIZE);
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
if (!allCredits) return [];
|
||||
let result = allCredits;
|
||||
if (filter === 'cast') result = result.filter((c) => c.cast_type === 'cast');
|
||||
else if (filter === 'crew') result = result.filter((c) => c.cast_type === 'crew');
|
||||
if (filter === "cast")
|
||||
result = result.filter((c) => c.cast_type === "cast");
|
||||
else if (filter === "crew")
|
||||
result = result.filter((c) => c.cast_type === "crew");
|
||||
if (search.trim()) {
|
||||
const q = search.trim().toLowerCase();
|
||||
result = result.filter((c) => {
|
||||
const name = c.people?.name?.toLowerCase() ?? '';
|
||||
const role = (c.cast_type === 'cast' ? c.character : (c.job || c.department))?.toLowerCase() ?? '';
|
||||
const name = c.people?.name?.toLowerCase() ?? "";
|
||||
const role =
|
||||
(c.cast_type === "cast"
|
||||
? c.character
|
||||
: c.job || c.department
|
||||
)?.toLowerCase() ?? "";
|
||||
return name.includes(q) || role.includes(q);
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}, [allCredits, filter, search]);
|
||||
|
||||
const sorted = useMemo(() => sortCredits(filtered, sortField, sortDir), [filtered, sortField, sortDir]);
|
||||
const sorted = useMemo(
|
||||
() => sortCredits(filtered, sortField, sortDir),
|
||||
[filtered, sortField, sortDir],
|
||||
);
|
||||
|
||||
// Reset visible window whenever filter/sort/search changes
|
||||
useEffect(() => {
|
||||
setVisibleCount(PAGE_SIZE);
|
||||
}, [filter, sortField, sortDir, search]);
|
||||
|
||||
const visible = useMemo(() => sorted.slice(0, visibleCount), [sorted, visibleCount]);
|
||||
const visible = useMemo(
|
||||
() => sorted.slice(0, visibleCount),
|
||||
[sorted, visibleCount],
|
||||
);
|
||||
const hasMore = visibleCount < sorted.length;
|
||||
|
||||
// IntersectionObserver-based lazy load on scroll
|
||||
@@ -117,7 +144,7 @@ export function EntryCastsPage() {
|
||||
setVisibleCount((c) => Math.min(c + PAGE_SIZE, sorted.length));
|
||||
}
|
||||
},
|
||||
{ rootMargin: '400px 0px' }
|
||||
{ rootMargin: "400px 0px" },
|
||||
);
|
||||
observer.observe(node);
|
||||
return () => observer.disconnect();
|
||||
@@ -165,12 +192,15 @@ export function EntryCastsPage() {
|
||||
className="w-48"
|
||||
/>
|
||||
<span className="text-sm text-muted-foreground whitespace-nowrap">
|
||||
{sorted.length} {sorted.length === 1 ? 'credit' : 'credits'}
|
||||
{sorted.length} {sorted.length === 1 ? "credit" : "credits"}
|
||||
</span>
|
||||
|
||||
{/* Right: filter + sort */}
|
||||
<div className="flex items-center gap-3 ml-auto">
|
||||
<Select value={filter} onValueChange={(v) => setFilter(v as CastFilter)}>
|
||||
<Select
|
||||
value={filter}
|
||||
onValueChange={(v) => setFilter(v as CastFilter)}
|
||||
>
|
||||
<SelectTrigger className="w-32">
|
||||
<SelectValue>{FILTER_LABELS[filter]}</SelectValue>
|
||||
</SelectTrigger>
|
||||
@@ -181,7 +211,10 @@ export function EntryCastsPage() {
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
<Select value={sortField} onValueChange={(v) => setSortField(v as SortField)}>
|
||||
<Select
|
||||
value={sortField}
|
||||
onValueChange={(v) => setSortField(v as SortField)}
|
||||
>
|
||||
<SelectTrigger className="w-40">
|
||||
<SelectValue>{SORT_LABELS[sortField]}</SelectValue>
|
||||
</SelectTrigger>
|
||||
@@ -199,7 +232,7 @@ export function EntryCastsPage() {
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-9 w-9"
|
||||
onClick={() => setSortDir((d) => (d === 'asc' ? 'desc' : 'asc'))}
|
||||
onClick={() => setSortDir((d) => (d === "asc" ? "desc" : "asc"))}
|
||||
>
|
||||
<ArrowUpDown className="h-4 w-4" />
|
||||
</Button>
|
||||
@@ -208,7 +241,9 @@ export function EntryCastsPage() {
|
||||
|
||||
{/* Grid */}
|
||||
{sorted.length === 0 ? (
|
||||
<p className="text-center text-muted-foreground py-12">No credits found.</p>
|
||||
<p className="text-center text-muted-foreground py-12">
|
||||
No credits found.
|
||||
</p>
|
||||
) : (
|
||||
<>
|
||||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5">
|
||||
@@ -219,7 +254,9 @@ export function EntryCastsPage() {
|
||||
{hasMore && (
|
||||
<div ref={sentinelRef} className="flex justify-center py-6">
|
||||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 w-full">
|
||||
{Array.from({ length: Math.min(PAGE_SIZE, sorted.length - visibleCount) }).map((_, i) => (
|
||||
{Array.from({
|
||||
length: Math.min(PAGE_SIZE, sorted.length - visibleCount),
|
||||
}).map((_, i) => (
|
||||
<div key={i} className="flex flex-col items-center gap-2 p-2">
|
||||
<Skeleton className="h-32 w-32 rounded-full" />
|
||||
<Skeleton className="h-3 w-16" />
|
||||
@@ -244,7 +281,7 @@ function CreditCard({ credit, isTv }: { credit: Credit; isTv: boolean }) {
|
||||
: `/people/tmdb/${credit.people?.tmdb_id ?? credit.people_id}`;
|
||||
|
||||
const roleLabel =
|
||||
credit.cast_type === 'cast'
|
||||
credit.cast_type === "cast"
|
||||
? credit.character
|
||||
: credit.job || credit.department;
|
||||
|
||||
@@ -257,13 +294,15 @@ function CreditCard({ credit, isTv }: { credit: Credit; isTv: boolean }) {
|
||||
<AvatarImage src={profileUrl} alt={credit.people?.name} />
|
||||
<AvatarFallback className="text-sm">
|
||||
{credit.people?.name
|
||||
?.split(' ')
|
||||
?.split(" ")
|
||||
.map((n) => n[0])
|
||||
.join('')}
|
||||
.join("")}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="min-w-0 w-full">
|
||||
<p className="text-sm font-medium leading-tight line-clamp-2">{credit.people?.name}</p>
|
||||
<p className="text-sm font-medium leading-tight line-clamp-2">
|
||||
{credit.people?.name}
|
||||
</p>
|
||||
{roleLabel && (
|
||||
<p className="text-xs text-muted-foreground leading-tight line-clamp-1 mt-0.5">
|
||||
{roleLabel}
|
||||
@@ -271,7 +310,8 @@ function CreditCard({ credit, isTv }: { credit: Credit; isTv: boolean }) {
|
||||
)}
|
||||
{isTv && credit.episode_count != null && credit.episode_count > 0 && (
|
||||
<p className="text-xs text-muted-foreground/70 leading-tight mt-0.5">
|
||||
{credit.episode_count} {credit.episode_count === 1 ? 'episode' : 'episodes'}
|
||||
{credit.episode_count}{" "}
|
||||
{credit.episode_count === 1 ? "episode" : "episodes"}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user