mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 01:35:39 -04:00
Implement full Couch Potato movie & TV tracking app
Add all 10 milestones: Drizzle ORM + SQLite database with WAL mode, Better Auth email/password authentication, TMDB API integration for search and metadata import, TV season/episode caching, user tracking (watchlist/status/watches/ratings with auto-transitions), discovery feeds (continue watching, library, recommendations), US streaming availability via TMDB providers, background job scheduler with instrumentation hook, and dark cinema-themed frontend with DM Serif Display + DM Sans typography and amber accent design system. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
DATABASE_URL=sqlite.db
|
||||||
|
TMDB_API_KEY=your_tmdb_api_key_here
|
||||||
|
BETTER_AUTH_SECRET=your_secret_here
|
||||||
|
BETTER_AUTH_URL=http://localhost:3000
|
||||||
@@ -23,6 +23,9 @@
|
|||||||
# misc
|
# misc
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*.pem
|
*.pem
|
||||||
|
*.db
|
||||||
|
*.db-shm
|
||||||
|
*.db-wal
|
||||||
|
|
||||||
# debug
|
# debug
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
@@ -32,6 +35,7 @@ yarn-error.log*
|
|||||||
|
|
||||||
# env files (can opt-in for committing if needed)
|
# env files (can opt-in for committing if needed)
|
||||||
.env*
|
.env*
|
||||||
|
!.env.example
|
||||||
|
|
||||||
# vercel
|
# vercel
|
||||||
.vercel
|
.vercel
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { NavBar } from "@/components/nav-bar";
|
||||||
|
|
||||||
|
export default function PagesLayout({
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen">
|
||||||
|
<NavBar />
|
||||||
|
<main className="mx-auto max-w-6xl px-4 py-6">{children}</main>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { AuthForm } from "@/components/auth-form";
|
||||||
|
|
||||||
|
export default function LoginPage() {
|
||||||
|
return (
|
||||||
|
<div className="flex min-h-[80vh] items-center justify-center px-4">
|
||||||
|
<AuthForm mode="login" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,244 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import {
|
||||||
|
IconDeviceTv,
|
||||||
|
IconPlayerPlay,
|
||||||
|
IconSparkles,
|
||||||
|
} from "@tabler/icons-react";
|
||||||
|
import Image from "next/image";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useCallback, useEffect, useState } from "react";
|
||||||
|
import { TitleCard } from "@/components/title-card";
|
||||||
|
import { useSession } from "@/lib/auth/client";
|
||||||
|
|
||||||
|
interface ContinueWatchingItem {
|
||||||
|
title: {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
posterPath: string | null;
|
||||||
|
type: string;
|
||||||
|
};
|
||||||
|
nextEpisode: {
|
||||||
|
id: string;
|
||||||
|
seasonNumber: number;
|
||||||
|
episodeNumber: number;
|
||||||
|
name: string | null;
|
||||||
|
} | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FeedTitle {
|
||||||
|
id?: string;
|
||||||
|
titleId?: string;
|
||||||
|
title: string;
|
||||||
|
type: string;
|
||||||
|
tmdbId?: number;
|
||||||
|
posterPath: string | null;
|
||||||
|
releaseDate?: string | null;
|
||||||
|
firstAirDate?: string | null;
|
||||||
|
voteAverage?: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function DashboardPage() {
|
||||||
|
const { data: session, isPending } = useSession();
|
||||||
|
const router = useRouter();
|
||||||
|
const [continueWatching, setContinueWatching] = useState<
|
||||||
|
ContinueWatchingItem[]
|
||||||
|
>([]);
|
||||||
|
const [newAvailable, setNewAvailable] = useState<FeedTitle[]>([]);
|
||||||
|
const [recommendations, setRecommendations] = useState<FeedTitle[]>([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
|
const fetchFeeds = useCallback(async () => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const [cwRes, naRes, recRes] = await Promise.all([
|
||||||
|
fetch("/api/feed/continue-watching"),
|
||||||
|
fetch("/api/feed/new-available"),
|
||||||
|
fetch("/api/feed/recommendations"),
|
||||||
|
]);
|
||||||
|
if (cwRes.ok) setContinueWatching(await cwRes.json());
|
||||||
|
if (naRes.ok) setNewAvailable(await naRes.json());
|
||||||
|
if (recRes.ok) setRecommendations(await recRes.json());
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isPending) return;
|
||||||
|
if (!session?.user) {
|
||||||
|
router.replace("/login");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fetchFeeds();
|
||||||
|
}, [session, isPending, router, fetchFeeds]);
|
||||||
|
|
||||||
|
if (isPending || loading) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center justify-center py-24">
|
||||||
|
<div className="h-6 w-6 animate-spin rounded-full border-2 border-amber border-t-transparent" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const isEmpty =
|
||||||
|
continueWatching.length === 0 &&
|
||||||
|
newAvailable.length === 0 &&
|
||||||
|
recommendations.length === 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-10">
|
||||||
|
<div>
|
||||||
|
<h1 className="font-display text-3xl tracking-tight">
|
||||||
|
Welcome back{session?.user?.name ? `, ${session.user.name}` : ""}
|
||||||
|
</h1>
|
||||||
|
<p className="mt-1 text-sm text-muted-foreground">
|
||||||
|
Here's what's happening with your library
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{isEmpty && (
|
||||||
|
<div className="flex flex-col items-center gap-4 rounded-xl border border-dashed border-border/50 py-16 text-center">
|
||||||
|
<div className="rounded-full bg-amber/10 p-4">
|
||||||
|
<IconDeviceTv size={32} className="text-amber" />
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<p className="font-medium">Your library is empty</p>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Search for movies and TV shows to start tracking
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Link
|
||||||
|
href="/search"
|
||||||
|
className="inline-flex h-9 items-center rounded-lg bg-amber px-4 text-sm font-medium text-background transition-all hover:shadow-md hover:shadow-amber/20"
|
||||||
|
>
|
||||||
|
Start searching
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Continue Watching */}
|
||||||
|
{continueWatching.length > 0 && (
|
||||||
|
<FeedSection
|
||||||
|
title="Continue Watching"
|
||||||
|
icon={<IconPlayerPlay size={20} className="text-amber" />}
|
||||||
|
>
|
||||||
|
<div className="feed-scroll flex gap-4 overflow-x-auto pb-2">
|
||||||
|
{continueWatching.map((item) => (
|
||||||
|
<ContinueWatchingCard key={item.title.id} item={item} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</FeedSection>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* New on Streaming */}
|
||||||
|
{newAvailable.length > 0 && (
|
||||||
|
<FeedSection
|
||||||
|
title="In Your Library"
|
||||||
|
icon={<IconSparkles size={20} className="text-amber" />}
|
||||||
|
>
|
||||||
|
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5">
|
||||||
|
{newAvailable.slice(0, 10).map((t) => (
|
||||||
|
<TitleCard
|
||||||
|
key={t.titleId ?? t.id}
|
||||||
|
id={t.titleId ?? t.id}
|
||||||
|
tmdbId={t.tmdbId ?? 0}
|
||||||
|
type={t.type}
|
||||||
|
title={t.title}
|
||||||
|
posterPath={t.posterPath}
|
||||||
|
releaseDate={t.releaseDate ?? t.firstAirDate}
|
||||||
|
voteAverage={t.voteAverage}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</FeedSection>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Recommendations */}
|
||||||
|
{recommendations.length > 0 && (
|
||||||
|
<FeedSection
|
||||||
|
title="Recommended for You"
|
||||||
|
icon={<IconSparkles size={20} className="text-amber" />}
|
||||||
|
>
|
||||||
|
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5">
|
||||||
|
{recommendations.slice(0, 10).map((t) => (
|
||||||
|
<TitleCard
|
||||||
|
key={t.id}
|
||||||
|
id={t.id}
|
||||||
|
tmdbId={t.tmdbId ?? 0}
|
||||||
|
type={t.type}
|
||||||
|
title={t.title}
|
||||||
|
posterPath={t.posterPath}
|
||||||
|
releaseDate={t.releaseDate ?? t.firstAirDate}
|
||||||
|
voteAverage={t.voteAverage}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</FeedSection>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function FeedSection({
|
||||||
|
title,
|
||||||
|
icon,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
title: string;
|
||||||
|
icon: React.ReactNode;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<section className="space-y-4">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
{icon}
|
||||||
|
<h2 className="font-display text-xl tracking-tight">{title}</h2>
|
||||||
|
</div>
|
||||||
|
{children}
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ContinueWatchingCard({ item }: { item: ContinueWatchingItem }) {
|
||||||
|
const posterUrl = item.title.posterPath
|
||||||
|
? `https://image.tmdb.org/t/p/w300${item.title.posterPath}`
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
href={`/titles/${item.title.id}`}
|
||||||
|
className="group flex w-56 shrink-0 gap-3 rounded-lg border border-border/30 bg-card/50 p-3 transition-all hover:border-amber/20 hover:bg-card"
|
||||||
|
>
|
||||||
|
<div className="h-20 w-14 shrink-0 overflow-hidden rounded-md bg-muted">
|
||||||
|
{posterUrl ? (
|
||||||
|
<Image
|
||||||
|
src={posterUrl}
|
||||||
|
alt={item.title.title}
|
||||||
|
width={56}
|
||||||
|
height={80}
|
||||||
|
className="h-full w-full object-cover"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="flex h-full items-center justify-center text-[8px] text-muted-foreground">
|
||||||
|
?
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="min-w-0 flex-1 space-y-1">
|
||||||
|
<p className="line-clamp-2 text-sm font-medium leading-snug">
|
||||||
|
{item.title.title}
|
||||||
|
</p>
|
||||||
|
{item.nextEpisode && (
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
S{item.nextEpisode.seasonNumber} E{item.nextEpisode.episodeNumber}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<p className="text-[10px] font-medium uppercase tracking-wider text-amber">
|
||||||
|
Up next
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { AuthForm } from "@/components/auth-form";
|
||||||
|
|
||||||
|
export default function RegisterPage() {
|
||||||
|
return (
|
||||||
|
<div className="flex min-h-[80vh] items-center justify-center px-4">
|
||||||
|
<AuthForm mode="register" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { IconDeviceTv, IconMovie } from "@tabler/icons-react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useCallback, useState } from "react";
|
||||||
|
import { SearchBar } from "@/components/search-bar";
|
||||||
|
import { TitleCard } from "@/components/title-card";
|
||||||
|
|
||||||
|
interface SearchResult {
|
||||||
|
tmdbId: number;
|
||||||
|
type: "movie" | "tv";
|
||||||
|
title: string;
|
||||||
|
overview: string;
|
||||||
|
releaseDate: string | null;
|
||||||
|
posterPath: string | null;
|
||||||
|
popularity: number;
|
||||||
|
voteAverage: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function SearchPage() {
|
||||||
|
const router = useRouter();
|
||||||
|
const [results, setResults] = useState<SearchResult[]>([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [importing, setImporting] = useState<number | null>(null);
|
||||||
|
const [searched, setSearched] = useState(false);
|
||||||
|
|
||||||
|
const handleSearch = useCallback(async (query: string) => {
|
||||||
|
setLoading(true);
|
||||||
|
setSearched(true);
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/search?query=${encodeURIComponent(query)}`);
|
||||||
|
const data = await res.json();
|
||||||
|
setResults(data.results ?? []);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function handleImport(tmdbId: number, type: "movie" | "tv") {
|
||||||
|
setImporting(tmdbId);
|
||||||
|
try {
|
||||||
|
const res = await fetch("/api/titles/import", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ tmdbId, type }),
|
||||||
|
});
|
||||||
|
const title = await res.json();
|
||||||
|
if (title.id) {
|
||||||
|
router.push(`/titles/${title.id}`);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setImporting(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-8">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<h1 className="font-display text-3xl tracking-tight">Search</h1>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Find movies and TV shows to add to your library
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<SearchBar onSearch={handleSearch} />
|
||||||
|
|
||||||
|
{loading && (
|
||||||
|
<div className="flex items-center justify-center py-16">
|
||||||
|
<div className="h-6 w-6 animate-spin rounded-full border-2 border-amber border-t-transparent" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!loading && searched && results.length === 0 && (
|
||||||
|
<div className="flex flex-col items-center gap-3 py-16 text-center">
|
||||||
|
<div className="flex gap-2 text-muted-foreground/40">
|
||||||
|
<IconMovie size={32} />
|
||||||
|
<IconDeviceTv size={32} />
|
||||||
|
</div>
|
||||||
|
<p className="text-muted-foreground">No results found</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!loading && results.length > 0 && (
|
||||||
|
<div className="grid grid-cols-2 gap-5 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5">
|
||||||
|
{results.map((r) => (
|
||||||
|
<div key={`${r.type}-${r.tmdbId}`} className="relative">
|
||||||
|
<TitleCard
|
||||||
|
tmdbId={r.tmdbId}
|
||||||
|
type={r.type}
|
||||||
|
title={r.title}
|
||||||
|
posterPath={r.posterPath}
|
||||||
|
releaseDate={r.releaseDate}
|
||||||
|
voteAverage={r.voteAverage}
|
||||||
|
onImport={() => handleImport(r.tmdbId, r.type)}
|
||||||
|
/>
|
||||||
|
{importing === r.tmdbId && (
|
||||||
|
<div className="absolute inset-0 flex items-center justify-center rounded-lg bg-background/80 backdrop-blur-sm">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="h-4 w-4 animate-spin rounded-full border-2 border-amber border-t-transparent" />
|
||||||
|
<span className="text-sm font-medium text-amber">
|
||||||
|
Importing
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,478 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import {
|
||||||
|
IconCheck,
|
||||||
|
IconChevronDown,
|
||||||
|
IconChevronUp,
|
||||||
|
IconPlayerPlay,
|
||||||
|
} from "@tabler/icons-react";
|
||||||
|
import Image from "next/image";
|
||||||
|
import { useParams } from "next/navigation";
|
||||||
|
import { useCallback, useEffect, useState } from "react";
|
||||||
|
import { StarRating } from "@/components/star-rating";
|
||||||
|
import { StatusButton } from "@/components/status-button";
|
||||||
|
import { TitleCard } from "@/components/title-card";
|
||||||
|
|
||||||
|
interface Episode {
|
||||||
|
id: string;
|
||||||
|
episodeNumber: number;
|
||||||
|
name: string | null;
|
||||||
|
overview: string | null;
|
||||||
|
airDate: string | null;
|
||||||
|
runtimeMinutes: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Season {
|
||||||
|
id: string;
|
||||||
|
seasonNumber: number;
|
||||||
|
name: string | null;
|
||||||
|
episodes: Episode[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AvailabilityOffer {
|
||||||
|
providerId: number;
|
||||||
|
providerName: string;
|
||||||
|
logoPath: string | null;
|
||||||
|
offerType: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RecommendedTitle {
|
||||||
|
id: string;
|
||||||
|
tmdbId: number;
|
||||||
|
type: "movie" | "tv";
|
||||||
|
title: string;
|
||||||
|
posterPath: string | null;
|
||||||
|
releaseDate: string | null;
|
||||||
|
firstAirDate: string | null;
|
||||||
|
voteAverage: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Title {
|
||||||
|
id: string;
|
||||||
|
tmdbId: number;
|
||||||
|
type: "movie" | "tv";
|
||||||
|
title: string;
|
||||||
|
originalTitle: string | null;
|
||||||
|
overview: string | null;
|
||||||
|
releaseDate: string | null;
|
||||||
|
firstAirDate: string | null;
|
||||||
|
posterPath: string | null;
|
||||||
|
backdropPath: string | null;
|
||||||
|
popularity: number | null;
|
||||||
|
voteAverage: number | null;
|
||||||
|
voteCount: number | null;
|
||||||
|
status: string | null;
|
||||||
|
seasons: Season[];
|
||||||
|
availability: AvailabilityOffer[];
|
||||||
|
userStatus?: string | null;
|
||||||
|
userRating?: number | null;
|
||||||
|
episodeWatches?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function TitleDetailPage() {
|
||||||
|
const { id } = useParams<{ id: string }>();
|
||||||
|
const [title, setTitle] = useState<Title | null>(null);
|
||||||
|
const [recommendations, setRecommendations] = useState<RecommendedTitle[]>(
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [openSeason, setOpenSeason] = useState<number | null>(null);
|
||||||
|
const [watchingEp, setWatchingEp] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const fetchTitle = useCallback(async () => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const [titleRes, statusRes] = await Promise.all([
|
||||||
|
fetch(`/api/titles/${id}`),
|
||||||
|
fetch(`/api/titles/${id}/status`),
|
||||||
|
]);
|
||||||
|
const titleData = await titleRes.json();
|
||||||
|
let statusData = { status: null, rating: null, episodeWatches: [] };
|
||||||
|
if (statusRes.ok) {
|
||||||
|
statusData = await statusRes.json();
|
||||||
|
}
|
||||||
|
setTitle({
|
||||||
|
...titleData,
|
||||||
|
userStatus: statusData.status,
|
||||||
|
userRating: statusData.rating,
|
||||||
|
episodeWatches: statusData.episodeWatches ?? [],
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
|
const fetchRecommendations = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/titles/${id}/recommendations`);
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json();
|
||||||
|
setRecommendations(data ?? []);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// silent
|
||||||
|
}
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchTitle();
|
||||||
|
fetchRecommendations();
|
||||||
|
}, [fetchTitle, fetchRecommendations]);
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center justify-center py-24">
|
||||||
|
<div className="h-6 w-6 animate-spin rounded-full border-2 border-amber border-t-transparent" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!title) {
|
||||||
|
return (
|
||||||
|
<p className="py-24 text-center text-muted-foreground">Title not found</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const posterUrl = title.posterPath
|
||||||
|
? `https://image.tmdb.org/t/p/w500${title.posterPath}`
|
||||||
|
: null;
|
||||||
|
const backdropUrl = title.backdropPath
|
||||||
|
? `https://image.tmdb.org/t/p/w1280${title.backdropPath}`
|
||||||
|
: null;
|
||||||
|
const dateStr = title.releaseDate ?? title.firstAirDate;
|
||||||
|
const year = dateStr?.slice(0, 4);
|
||||||
|
|
||||||
|
async function handleStatusChange(status: string | null) {
|
||||||
|
await fetch(`/api/titles/${id}/status`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ status }),
|
||||||
|
});
|
||||||
|
setTitle((t) => (t ? { ...t, userStatus: status } : t));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleRating(ratingStars: number) {
|
||||||
|
await fetch(`/api/titles/${id}/rating`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ ratingStars }),
|
||||||
|
});
|
||||||
|
setTitle((t) => (t ? { ...t, userRating: ratingStars } : t));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleWatchMovie() {
|
||||||
|
await fetch(`/api/movies/${id}/watch`, { method: "POST" });
|
||||||
|
setTitle((t) => (t ? { ...t, userStatus: "completed" } : t));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleWatchEpisode(episodeId: string) {
|
||||||
|
setWatchingEp(episodeId);
|
||||||
|
await fetch(`/api/episodes/${episodeId}/watch`, { method: "POST" });
|
||||||
|
setTitle((t) => {
|
||||||
|
if (!t) return t;
|
||||||
|
const watches = [...(t.episodeWatches ?? [])];
|
||||||
|
if (!watches.includes(episodeId)) watches.push(episodeId);
|
||||||
|
return {
|
||||||
|
...t,
|
||||||
|
episodeWatches: watches,
|
||||||
|
userStatus: t.userStatus ?? "in_progress",
|
||||||
|
};
|
||||||
|
});
|
||||||
|
setWatchingEp(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group availability by offerType
|
||||||
|
const availByType: Record<string, AvailabilityOffer[]> = {};
|
||||||
|
for (const offer of title.availability ?? []) {
|
||||||
|
if (!availByType[offer.offerType]) availByType[offer.offerType] = [];
|
||||||
|
availByType[offer.offerType].push(offer);
|
||||||
|
}
|
||||||
|
|
||||||
|
const offerLabels: Record<string, string> = {
|
||||||
|
flatrate: "Stream",
|
||||||
|
rent: "Rent",
|
||||||
|
buy: "Buy",
|
||||||
|
free: "Free",
|
||||||
|
ads: "With Ads",
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-10">
|
||||||
|
{/* Backdrop hero */}
|
||||||
|
{backdropUrl && (
|
||||||
|
<div className="relative -mx-4 -mt-6 h-72 overflow-hidden sm:h-96">
|
||||||
|
<Image
|
||||||
|
src={backdropUrl}
|
||||||
|
alt=""
|
||||||
|
fill
|
||||||
|
className="object-cover"
|
||||||
|
priority
|
||||||
|
/>
|
||||||
|
<div className="absolute inset-0 bg-gradient-to-t from-background via-background/60 to-background/20" />
|
||||||
|
<div className="absolute inset-0 bg-gradient-to-r from-background/80 to-transparent" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Title header */}
|
||||||
|
<div
|
||||||
|
className={`flex flex-col gap-8 sm:flex-row ${backdropUrl ? "-mt-32 relative z-10" : ""}`}
|
||||||
|
>
|
||||||
|
{posterUrl && (
|
||||||
|
<div className="shrink-0">
|
||||||
|
<div className="overflow-hidden rounded-xl shadow-2xl shadow-black/40">
|
||||||
|
<Image
|
||||||
|
src={posterUrl}
|
||||||
|
alt={title.title}
|
||||||
|
width={220}
|
||||||
|
height={330}
|
||||||
|
className="h-auto w-[180px] sm:w-[220px]"
|
||||||
|
priority
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="flex-1 space-y-5">
|
||||||
|
<div>
|
||||||
|
<h1 className="font-display text-4xl tracking-tight sm:text-5xl">
|
||||||
|
{title.title}
|
||||||
|
</h1>
|
||||||
|
<div className="mt-2 flex flex-wrap items-center gap-3 text-sm text-muted-foreground">
|
||||||
|
<span className="rounded bg-amber/10 px-2 py-0.5 text-xs font-semibold uppercase tracking-wider text-amber">
|
||||||
|
{title.type}
|
||||||
|
</span>
|
||||||
|
{year && <span>{year}</span>}
|
||||||
|
{title.voteAverage != null && title.voteAverage > 0 && (
|
||||||
|
<span className="flex items-center gap-1 text-amber">
|
||||||
|
★ {title.voteAverage.toFixed(1)}
|
||||||
|
{title.voteCount != null && (
|
||||||
|
<span className="text-muted-foreground">
|
||||||
|
({title.voteCount.toLocaleString()})
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{title.status && (
|
||||||
|
<span className="rounded border border-border/50 px-2 py-0.5 text-xs">
|
||||||
|
{title.status}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{title.overview && (
|
||||||
|
<p className="max-w-2xl leading-relaxed text-muted-foreground">
|
||||||
|
{title.overview}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Actions */}
|
||||||
|
<div className="flex flex-wrap items-center gap-3">
|
||||||
|
<StatusButton
|
||||||
|
currentStatus={title.userStatus ?? null}
|
||||||
|
onChange={handleStatusChange}
|
||||||
|
/>
|
||||||
|
{title.type === "movie" && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleWatchMovie}
|
||||||
|
className="inline-flex h-9 items-center gap-2 rounded-lg bg-amber px-4 text-sm font-medium text-background transition-all hover:shadow-md hover:shadow-amber/20"
|
||||||
|
>
|
||||||
|
<IconPlayerPlay size={15} />
|
||||||
|
Mark Watched
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="text-xs text-muted-foreground">Rate:</span>
|
||||||
|
<StarRating
|
||||||
|
value={title.userRating ?? 0}
|
||||||
|
onChange={handleRating}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Availability */}
|
||||||
|
{Object.keys(availByType).length > 0 && (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<h3 className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">
|
||||||
|
Where to Watch
|
||||||
|
</h3>
|
||||||
|
<div className="flex flex-wrap gap-4">
|
||||||
|
{Object.entries(availByType).map(([type, offers]) => (
|
||||||
|
<div key={type} className="space-y-1.5">
|
||||||
|
<span className="text-[10px] font-medium uppercase tracking-wider text-muted-foreground/60">
|
||||||
|
{offerLabels[type] ?? type}
|
||||||
|
</span>
|
||||||
|
<div className="flex gap-1.5">
|
||||||
|
{offers.map((offer) => (
|
||||||
|
<ProviderBadge
|
||||||
|
key={offer.providerId}
|
||||||
|
name={offer.providerName}
|
||||||
|
logoPath={offer.logoPath}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Seasons & Episodes (TV) */}
|
||||||
|
{title.type === "tv" && title.seasons.length > 0 && (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<h2 className="font-display text-2xl tracking-tight">Seasons</h2>
|
||||||
|
<div className="space-y-2">
|
||||||
|
{title.seasons.map((season) => {
|
||||||
|
const isOpen = openSeason === season.seasonNumber;
|
||||||
|
const watchedCount = season.episodes.filter((ep) =>
|
||||||
|
title.episodeWatches?.includes(ep.id),
|
||||||
|
).length;
|
||||||
|
const totalCount = season.episodes.length;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={season.id}
|
||||||
|
className="overflow-hidden rounded-lg border border-border/50 bg-card/50"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() =>
|
||||||
|
setOpenSeason(isOpen ? null : season.seasonNumber)
|
||||||
|
}
|
||||||
|
className="flex w-full items-center justify-between p-4 text-left transition-colors hover:bg-accent/50"
|
||||||
|
>
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<span className="font-medium">
|
||||||
|
{season.name ?? `Season ${season.seasonNumber}`}
|
||||||
|
</span>
|
||||||
|
{watchedCount > 0 && (
|
||||||
|
<span className="text-xs text-amber">
|
||||||
|
{watchedCount}/{totalCount}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="text-xs text-muted-foreground">
|
||||||
|
{totalCount} ep
|
||||||
|
</span>
|
||||||
|
{isOpen ? (
|
||||||
|
<IconChevronUp
|
||||||
|
size={16}
|
||||||
|
className="text-muted-foreground"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<IconChevronDown
|
||||||
|
size={16}
|
||||||
|
className="text-muted-foreground"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{isOpen && (
|
||||||
|
<div className="border-t border-border/50">
|
||||||
|
{season.episodes.map((ep) => {
|
||||||
|
const isWatched = title.episodeWatches?.includes(ep.id);
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={ep.id}
|
||||||
|
className="flex items-center gap-3 border-b border-border/30 px-4 py-3 last:border-b-0"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => handleWatchEpisode(ep.id)}
|
||||||
|
disabled={watchingEp === ep.id}
|
||||||
|
className={`flex h-6 w-6 shrink-0 items-center justify-center rounded-md border transition-all ${
|
||||||
|
isWatched
|
||||||
|
? "border-amber bg-amber text-background"
|
||||||
|
: "border-border/50 hover:border-amber/50 hover:bg-amber/5"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{isWatched && <IconCheck size={14} />}
|
||||||
|
</button>
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<p className="truncate text-sm">
|
||||||
|
<span className="font-mono text-xs text-muted-foreground">
|
||||||
|
E{String(ep.episodeNumber).padStart(2, "0")}
|
||||||
|
</span>{" "}
|
||||||
|
<span className="font-medium">
|
||||||
|
{ep.name ?? "Untitled"}
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
{ep.airDate && (
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
{ep.airDate}
|
||||||
|
{ep.runtimeMinutes
|
||||||
|
? ` · ${ep.runtimeMinutes}m`
|
||||||
|
: ""}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Recommendations */}
|
||||||
|
{recommendations.length > 0 && (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h2 className="font-display text-2xl tracking-tight">Recommended</h2>
|
||||||
|
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6">
|
||||||
|
{recommendations.slice(0, 12).map((rec) => (
|
||||||
|
<TitleCard
|
||||||
|
key={rec.id}
|
||||||
|
id={rec.id}
|
||||||
|
tmdbId={rec.tmdbId}
|
||||||
|
type={rec.type}
|
||||||
|
title={rec.title}
|
||||||
|
posterPath={rec.posterPath}
|
||||||
|
releaseDate={rec.releaseDate ?? rec.firstAirDate}
|
||||||
|
voteAverage={rec.voteAverage}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ProviderBadge({
|
||||||
|
name,
|
||||||
|
logoPath,
|
||||||
|
}: {
|
||||||
|
name: string;
|
||||||
|
logoPath: string | null;
|
||||||
|
}) {
|
||||||
|
const logoUrl = logoPath ? `https://image.tmdb.org/t/p/w92${logoPath}` : null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="flex h-10 w-10 items-center justify-center overflow-hidden rounded-lg border border-border/30 bg-card transition-transform hover:scale-105"
|
||||||
|
title={name}
|
||||||
|
>
|
||||||
|
{logoUrl ? (
|
||||||
|
<Image
|
||||||
|
src={logoUrl}
|
||||||
|
alt={name}
|
||||||
|
width={40}
|
||||||
|
height={40}
|
||||||
|
className="h-full w-full object-cover"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<span className="text-[8px] font-medium text-muted-foreground">
|
||||||
|
{name.slice(0, 2)}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import type { NextRequest } from "next/server";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { badRequest } from "@/lib/api/errors";
|
||||||
|
import { registerJobs } from "@/lib/jobs/registry";
|
||||||
|
import { scheduler } from "@/lib/jobs/scheduler";
|
||||||
|
|
||||||
|
// Ensure jobs are registered for manual triggering
|
||||||
|
registerJobs();
|
||||||
|
|
||||||
|
export async function POST(
|
||||||
|
_req: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ name: string }> },
|
||||||
|
) {
|
||||||
|
const { name } = await params;
|
||||||
|
const jobNames = scheduler.getJobNames();
|
||||||
|
|
||||||
|
if (!jobNames.includes(name)) {
|
||||||
|
return badRequest(
|
||||||
|
`Unknown job: ${name}. Available: ${jobNames.join(", ")}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await scheduler.runNow(name);
|
||||||
|
return NextResponse.json({ ok: true, job: name });
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import { toNextJsHandler } from "better-auth/next-js";
|
||||||
|
import { auth } from "@/lib/auth/server";
|
||||||
|
|
||||||
|
export const { GET, POST } = toNextJsHandler(auth);
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import type { NextRequest } from "next/server";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { AuthError, requireAuth } from "@/lib/api/auth-guard";
|
||||||
|
import { unauthorized } from "@/lib/api/errors";
|
||||||
|
import { logEpisodeWatch } from "@/lib/services/tracking";
|
||||||
|
|
||||||
|
export async function POST(
|
||||||
|
_req: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ id: string }> },
|
||||||
|
) {
|
||||||
|
let userId: string;
|
||||||
|
try {
|
||||||
|
userId = await requireAuth();
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof AuthError) return unauthorized();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
const { id } = await params;
|
||||||
|
logEpisodeWatch(userId, id);
|
||||||
|
return NextResponse.json({ ok: true });
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { AuthError, requireAuth } from "@/lib/api/auth-guard";
|
||||||
|
import { unauthorized } from "@/lib/api/errors";
|
||||||
|
import { getContinueWatchingFeed } from "@/lib/services/discovery";
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
let userId: string;
|
||||||
|
try {
|
||||||
|
userId = await requireAuth();
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof AuthError) return unauthorized();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
const feed = getContinueWatchingFeed(userId);
|
||||||
|
return NextResponse.json(feed);
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import type { NextRequest } from "next/server";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { AuthError, requireAuth } from "@/lib/api/auth-guard";
|
||||||
|
import { unauthorized } from "@/lib/api/errors";
|
||||||
|
import { getNewAvailableFeed } from "@/lib/services/discovery";
|
||||||
|
|
||||||
|
export async function GET(req: NextRequest) {
|
||||||
|
let userId: string;
|
||||||
|
try {
|
||||||
|
userId = await requireAuth();
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof AuthError) return unauthorized();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
const days = Number(req.nextUrl.searchParams.get("days") ?? 14);
|
||||||
|
const feed = getNewAvailableFeed(userId, days);
|
||||||
|
return NextResponse.json(feed);
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { AuthError, requireAuth } from "@/lib/api/auth-guard";
|
||||||
|
import { unauthorized } from "@/lib/api/errors";
|
||||||
|
import { getRecommendationsFeed } from "@/lib/services/discovery";
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
let userId: string;
|
||||||
|
try {
|
||||||
|
userId = await requireAuth();
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof AuthError) return unauthorized();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
const feed = getRecommendationsFeed(userId);
|
||||||
|
return NextResponse.json(feed);
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import type { NextRequest } from "next/server";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { AuthError, requireAuth } from "@/lib/api/auth-guard";
|
||||||
|
import { unauthorized } from "@/lib/api/errors";
|
||||||
|
import { logMovieWatch } from "@/lib/services/tracking";
|
||||||
|
|
||||||
|
export async function POST(
|
||||||
|
_req: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ id: string }> },
|
||||||
|
) {
|
||||||
|
let userId: string;
|
||||||
|
try {
|
||||||
|
userId = await requireAuth();
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof AuthError) return unauthorized();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
const { id } = await params;
|
||||||
|
logMovieWatch(userId, id);
|
||||||
|
return NextResponse.json({ ok: true });
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { type NextRequest, NextResponse } from "next/server";
|
||||||
|
import { badRequest } from "@/lib/api/errors";
|
||||||
|
import { searchMovies, searchMulti, searchTv } from "@/lib/tmdb/client";
|
||||||
|
import type { TmdbSearchResponse } from "@/lib/tmdb/types";
|
||||||
|
|
||||||
|
export async function GET(req: NextRequest) {
|
||||||
|
const query = req.nextUrl.searchParams.get("query");
|
||||||
|
const type = req.nextUrl.searchParams.get("type");
|
||||||
|
|
||||||
|
if (!query) return badRequest("query parameter is required");
|
||||||
|
|
||||||
|
let results: TmdbSearchResponse;
|
||||||
|
if (type === "movie") {
|
||||||
|
results = await searchMovies(query);
|
||||||
|
} else if (type === "tv") {
|
||||||
|
results = await searchTv(query);
|
||||||
|
} else {
|
||||||
|
results = await searchMulti(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter out person results from multi search
|
||||||
|
const filtered = results.results.filter(
|
||||||
|
(r) => r.media_type !== "person" || type,
|
||||||
|
);
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
results: filtered.map((r) => ({
|
||||||
|
tmdbId: r.id,
|
||||||
|
type: r.media_type ?? type,
|
||||||
|
title: r.title ?? r.name,
|
||||||
|
overview: r.overview,
|
||||||
|
releaseDate: r.release_date ?? r.first_air_date,
|
||||||
|
posterPath: r.poster_path,
|
||||||
|
popularity: r.popularity,
|
||||||
|
voteAverage: r.vote_average,
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import type { NextRequest } from "next/server";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { AuthError, requireAuth } from "@/lib/api/auth-guard";
|
||||||
|
import { badRequest, unauthorized } from "@/lib/api/errors";
|
||||||
|
import { rateTitleStars } from "@/lib/services/tracking";
|
||||||
|
|
||||||
|
export async function POST(
|
||||||
|
req: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ id: string }> },
|
||||||
|
) {
|
||||||
|
let userId: string;
|
||||||
|
try {
|
||||||
|
userId = await requireAuth();
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof AuthError) return unauthorized();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
const { id } = await params;
|
||||||
|
const body = await req.json();
|
||||||
|
const { ratingStars } = body;
|
||||||
|
|
||||||
|
if (typeof ratingStars !== "number" || ratingStars < 0 || ratingStars > 5) {
|
||||||
|
return badRequest("ratingStars must be 0-5");
|
||||||
|
}
|
||||||
|
|
||||||
|
rateTitleStars(userId, id, ratingStars);
|
||||||
|
return NextResponse.json({ ok: true });
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { eq } from "drizzle-orm";
|
||||||
|
import type { NextRequest } from "next/server";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { notFound } from "@/lib/api/errors";
|
||||||
|
import { db } from "@/lib/db/client";
|
||||||
|
import { titleRecommendations, titles } from "@/lib/db/schema";
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
_req: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ id: string }> },
|
||||||
|
) {
|
||||||
|
const { id } = await params;
|
||||||
|
const title = db.select().from(titles).where(eq(titles.id, id)).get();
|
||||||
|
if (!title) return notFound("Title not found");
|
||||||
|
|
||||||
|
const recs = db
|
||||||
|
.select({
|
||||||
|
recommendedTitleId: titleRecommendations.recommendedTitleId,
|
||||||
|
source: titleRecommendations.source,
|
||||||
|
rank: titleRecommendations.rank,
|
||||||
|
})
|
||||||
|
.from(titleRecommendations)
|
||||||
|
.where(eq(titleRecommendations.titleId, id))
|
||||||
|
.orderBy(titleRecommendations.rank)
|
||||||
|
.all();
|
||||||
|
|
||||||
|
const results = recs
|
||||||
|
.map((rec) => {
|
||||||
|
const recTitle = db
|
||||||
|
.select()
|
||||||
|
.from(titles)
|
||||||
|
.where(eq(titles.id, rec.recommendedTitleId))
|
||||||
|
.get();
|
||||||
|
return recTitle
|
||||||
|
? { ...recTitle, source: rec.source, rank: rec.rank }
|
||||||
|
: null;
|
||||||
|
})
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
|
return NextResponse.json(results);
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import { eq } from "drizzle-orm";
|
||||||
|
import { type NextRequest, NextResponse } from "next/server";
|
||||||
|
import { notFound } from "@/lib/api/errors";
|
||||||
|
import { db } from "@/lib/db/client";
|
||||||
|
import { availabilityOffers, episodes, seasons, titles } from "@/lib/db/schema";
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
_req: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ id: string }> },
|
||||||
|
) {
|
||||||
|
const { id } = await params;
|
||||||
|
const title = db.select().from(titles).where(eq(titles.id, id)).get();
|
||||||
|
if (!title) return notFound("Title not found");
|
||||||
|
|
||||||
|
let titleSeasons: Array<{
|
||||||
|
id: string;
|
||||||
|
seasonNumber: number;
|
||||||
|
name: string | null;
|
||||||
|
overview: string | null;
|
||||||
|
posterPath: string | null;
|
||||||
|
airDate: string | null;
|
||||||
|
episodes: Array<{
|
||||||
|
id: string;
|
||||||
|
episodeNumber: number;
|
||||||
|
name: string | null;
|
||||||
|
overview: string | null;
|
||||||
|
stillPath: string | null;
|
||||||
|
airDate: string | null;
|
||||||
|
runtimeMinutes: number | null;
|
||||||
|
}>;
|
||||||
|
}> = [];
|
||||||
|
|
||||||
|
if (title.type === "tv") {
|
||||||
|
const seasonRows = db
|
||||||
|
.select()
|
||||||
|
.from(seasons)
|
||||||
|
.where(eq(seasons.titleId, title.id))
|
||||||
|
.orderBy(seasons.seasonNumber)
|
||||||
|
.all();
|
||||||
|
|
||||||
|
titleSeasons = seasonRows.map((s) => ({
|
||||||
|
...s,
|
||||||
|
episodes: db
|
||||||
|
.select()
|
||||||
|
.from(episodes)
|
||||||
|
.where(eq(episodes.seasonId, s.id))
|
||||||
|
.orderBy(episodes.episodeNumber)
|
||||||
|
.all(),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
const availability = db
|
||||||
|
.select()
|
||||||
|
.from(availabilityOffers)
|
||||||
|
.where(eq(availabilityOffers.titleId, title.id))
|
||||||
|
.all();
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
...title,
|
||||||
|
seasons: titleSeasons,
|
||||||
|
availability,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import type { NextRequest } from "next/server";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { AuthError, requireAuth } from "@/lib/api/auth-guard";
|
||||||
|
import { unauthorized } from "@/lib/api/errors";
|
||||||
|
import {
|
||||||
|
getUserTitleInfo,
|
||||||
|
removeTitleStatus,
|
||||||
|
setTitleStatus,
|
||||||
|
} from "@/lib/services/tracking";
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
_req: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ id: string }> },
|
||||||
|
) {
|
||||||
|
let userId: string;
|
||||||
|
try {
|
||||||
|
userId = await requireAuth();
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof AuthError) return unauthorized();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
const { id } = await params;
|
||||||
|
const info = getUserTitleInfo(userId, id);
|
||||||
|
return NextResponse.json(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST(
|
||||||
|
req: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ id: string }> },
|
||||||
|
) {
|
||||||
|
let userId: string;
|
||||||
|
try {
|
||||||
|
userId = await requireAuth();
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof AuthError) return unauthorized();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
const { id } = await params;
|
||||||
|
const body = await req.json();
|
||||||
|
const { status } = body;
|
||||||
|
|
||||||
|
if (status === null || status === undefined) {
|
||||||
|
removeTitleStatus(userId, id);
|
||||||
|
} else {
|
||||||
|
setTitleStatus(userId, id, status);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({ ok: true });
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import type { NextRequest } from "next/server";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { AuthError, requireAuth } from "@/lib/api/auth-guard";
|
||||||
|
import { badRequest, unauthorized } from "@/lib/api/errors";
|
||||||
|
import { importTitle } from "@/lib/services/metadata";
|
||||||
|
|
||||||
|
export async function POST(req: NextRequest) {
|
||||||
|
try {
|
||||||
|
await requireAuth();
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof AuthError) return unauthorized();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = await req.json();
|
||||||
|
const { tmdbId, type } = body;
|
||||||
|
|
||||||
|
if (!tmdbId || !type || !["movie", "tv"].includes(type)) {
|
||||||
|
return badRequest("tmdbId and type (movie|tv) are required");
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = await importTitle(tmdbId, type);
|
||||||
|
return NextResponse.json(title);
|
||||||
|
}
|
||||||
+65
-68
@@ -7,8 +7,9 @@
|
|||||||
@theme inline {
|
@theme inline {
|
||||||
--color-background: var(--background);
|
--color-background: var(--background);
|
||||||
--color-foreground: var(--foreground);
|
--color-foreground: var(--foreground);
|
||||||
--font-sans: var(--font-sans);
|
--font-sans: var(--font-dm-sans);
|
||||||
--font-mono: var(--font-geist-mono);
|
--font-mono: var(--font-geist-mono);
|
||||||
|
--font-display: var(--font-dm-serif);
|
||||||
--color-sidebar-ring: var(--sidebar-ring);
|
--color-sidebar-ring: var(--sidebar-ring);
|
||||||
--color-sidebar-border: var(--sidebar-border);
|
--color-sidebar-border: var(--sidebar-border);
|
||||||
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
||||||
@@ -38,6 +39,8 @@
|
|||||||
--color-popover: var(--popover);
|
--color-popover: var(--popover);
|
||||||
--color-card-foreground: var(--card-foreground);
|
--color-card-foreground: var(--card-foreground);
|
||||||
--color-card: var(--card);
|
--color-card: var(--card);
|
||||||
|
--color-amber: var(--amber);
|
||||||
|
--color-amber-muted: var(--amber-muted);
|
||||||
--radius-sm: calc(var(--radius) - 4px);
|
--radius-sm: calc(var(--radius) - 4px);
|
||||||
--radius-md: calc(var(--radius) - 2px);
|
--radius-md: calc(var(--radius) - 2px);
|
||||||
--radius-lg: var(--radius);
|
--radius-lg: var(--radius);
|
||||||
@@ -47,73 +50,42 @@
|
|||||||
--radius-4xl: calc(var(--radius) + 16px);
|
--radius-4xl: calc(var(--radius) + 16px);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Dark cinema — always dark */
|
||||||
:root {
|
:root {
|
||||||
--background: oklch(1 0 0);
|
--background: oklch(0.12 0.005 250);
|
||||||
--foreground: oklch(0.145 0 0);
|
--foreground: oklch(0.93 0.01 80);
|
||||||
--card: oklch(1 0 0);
|
--card: oklch(0.16 0.005 250);
|
||||||
--card-foreground: oklch(0.145 0 0);
|
--card-foreground: oklch(0.93 0.01 80);
|
||||||
--popover: oklch(1 0 0);
|
--popover: oklch(0.18 0.005 250);
|
||||||
--popover-foreground: oklch(0.145 0 0);
|
--popover-foreground: oklch(0.93 0.01 80);
|
||||||
--primary: oklch(0.205 0 0);
|
--primary: oklch(0.82 0.12 70);
|
||||||
--primary-foreground: oklch(0.985 0 0);
|
--primary-foreground: oklch(0.12 0.005 250);
|
||||||
--secondary: oklch(0.97 0 0);
|
--secondary: oklch(0.2 0.005 250);
|
||||||
--secondary-foreground: oklch(0.205 0 0);
|
--secondary-foreground: oklch(0.85 0.02 80);
|
||||||
--muted: oklch(0.97 0 0);
|
--muted: oklch(0.2 0.005 250);
|
||||||
--muted-foreground: oklch(0.556 0 0);
|
--muted-foreground: oklch(0.6 0.02 80);
|
||||||
--accent: oklch(0.97 0 0);
|
--accent: oklch(0.22 0.008 250);
|
||||||
--accent-foreground: oklch(0.205 0 0);
|
--accent-foreground: oklch(0.93 0.01 80);
|
||||||
--destructive: oklch(0.58 0.22 27);
|
--destructive: oklch(0.65 0.2 25);
|
||||||
--border: oklch(0.922 0 0);
|
--border: oklch(1 0 0 / 8%);
|
||||||
--input: oklch(0.922 0 0);
|
--input: oklch(1 0 0 / 10%);
|
||||||
--ring: oklch(0.708 0 0);
|
--ring: oklch(0.82 0.12 70);
|
||||||
--chart-1: oklch(0.809 0.105 251.813);
|
--amber: oklch(0.82 0.12 70);
|
||||||
--chart-2: oklch(0.623 0.214 259.815);
|
--amber-muted: oklch(0.82 0.12 70 / 15%);
|
||||||
--chart-3: oklch(0.546 0.245 262.881);
|
--chart-1: oklch(0.82 0.12 70);
|
||||||
--chart-4: oklch(0.488 0.243 264.376);
|
--chart-2: oklch(0.65 0.15 30);
|
||||||
--chart-5: oklch(0.424 0.199 265.638);
|
--chart-3: oklch(0.55 0.12 260);
|
||||||
--radius: 0.625rem;
|
--chart-4: oklch(0.72 0.1 160);
|
||||||
--sidebar: oklch(0.985 0 0);
|
--chart-5: oklch(0.6 0.15 310);
|
||||||
--sidebar-foreground: oklch(0.145 0 0);
|
--radius: 0.5rem;
|
||||||
--sidebar-primary: oklch(0.205 0 0);
|
--sidebar: oklch(0.14 0.005 250);
|
||||||
--sidebar-primary-foreground: oklch(0.985 0 0);
|
--sidebar-foreground: oklch(0.93 0.01 80);
|
||||||
--sidebar-accent: oklch(0.97 0 0);
|
--sidebar-primary: oklch(0.82 0.12 70);
|
||||||
--sidebar-accent-foreground: oklch(0.205 0 0);
|
--sidebar-primary-foreground: oklch(0.12 0.005 250);
|
||||||
--sidebar-border: oklch(0.922 0 0);
|
--sidebar-accent: oklch(0.2 0.005 250);
|
||||||
--sidebar-ring: oklch(0.708 0 0);
|
--sidebar-accent-foreground: oklch(0.93 0.01 80);
|
||||||
}
|
--sidebar-border: oklch(1 0 0 / 8%);
|
||||||
|
--sidebar-ring: oklch(0.82 0.12 70);
|
||||||
.dark {
|
|
||||||
--background: oklch(0.145 0 0);
|
|
||||||
--foreground: oklch(0.985 0 0);
|
|
||||||
--card: oklch(0.205 0 0);
|
|
||||||
--card-foreground: oklch(0.985 0 0);
|
|
||||||
--popover: oklch(0.205 0 0);
|
|
||||||
--popover-foreground: oklch(0.985 0 0);
|
|
||||||
--primary: oklch(0.87 0.00 0);
|
|
||||||
--primary-foreground: oklch(0.205 0 0);
|
|
||||||
--secondary: oklch(0.269 0 0);
|
|
||||||
--secondary-foreground: oklch(0.985 0 0);
|
|
||||||
--muted: oklch(0.269 0 0);
|
|
||||||
--muted-foreground: oklch(0.708 0 0);
|
|
||||||
--accent: oklch(0.371 0 0);
|
|
||||||
--accent-foreground: oklch(0.985 0 0);
|
|
||||||
--destructive: oklch(0.704 0.191 22.216);
|
|
||||||
--border: oklch(1 0 0 / 10%);
|
|
||||||
--input: oklch(1 0 0 / 15%);
|
|
||||||
--ring: oklch(0.556 0 0);
|
|
||||||
--chart-1: oklch(0.809 0.105 251.813);
|
|
||||||
--chart-2: oklch(0.623 0.214 259.815);
|
|
||||||
--chart-3: oklch(0.546 0.245 262.881);
|
|
||||||
--chart-4: oklch(0.488 0.243 264.376);
|
|
||||||
--chart-5: oklch(0.424 0.199 265.638);
|
|
||||||
--sidebar: oklch(0.205 0 0);
|
|
||||||
--sidebar-foreground: oklch(0.985 0 0);
|
|
||||||
--sidebar-primary: oklch(0.488 0.243 264.376);
|
|
||||||
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
||||||
--sidebar-accent: oklch(0.269 0 0);
|
|
||||||
--sidebar-accent-foreground: oklch(0.985 0 0);
|
|
||||||
--sidebar-border: oklch(1 0 0 / 10%);
|
|
||||||
--sidebar-ring: oklch(0.556 0 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@layer base {
|
@layer base {
|
||||||
@@ -121,6 +93,31 @@
|
|||||||
@apply border-border outline-ring/50;
|
@apply border-border outline-ring/50;
|
||||||
}
|
}
|
||||||
body {
|
body {
|
||||||
@apply bg-background text-foreground;
|
@apply bg-background text-foreground antialiased;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Scrollbar styling */
|
||||||
|
::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
height: 6px;
|
||||||
|
}
|
||||||
|
::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
::-webkit-scrollbar-thumb {
|
||||||
|
background: oklch(1 0 0 / 15%);
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: oklch(1 0 0 / 25%);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Horizontal scroll row for feeds */
|
||||||
|
.feed-scroll {
|
||||||
|
scrollbar-width: none;
|
||||||
|
-ms-overflow-style: none;
|
||||||
|
}
|
||||||
|
.feed-scroll::-webkit-scrollbar {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|||||||
+12
-6
@@ -1,9 +1,15 @@
|
|||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
import { Geist, Geist_Mono } from "next/font/google";
|
import { DM_Sans, DM_Serif_Display, Geist_Mono } from "next/font/google";
|
||||||
import "./globals.css";
|
import "./globals.css";
|
||||||
|
|
||||||
const geistSans = Geist({
|
const dmSans = DM_Sans({
|
||||||
variable: "--font-geist-sans",
|
variable: "--font-dm-sans",
|
||||||
|
subsets: ["latin"],
|
||||||
|
});
|
||||||
|
|
||||||
|
const dmSerif = DM_Serif_Display({
|
||||||
|
variable: "--font-dm-serif",
|
||||||
|
weight: "400",
|
||||||
subsets: ["latin"],
|
subsets: ["latin"],
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -13,8 +19,8 @@ const geistMono = Geist_Mono({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Create Next App",
|
title: "Couch Potato",
|
||||||
description: "Generated by create next app",
|
description: "Track your movies and TV shows",
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function RootLayout({
|
export default function RootLayout({
|
||||||
@@ -25,7 +31,7 @@ export default function RootLayout({
|
|||||||
return (
|
return (
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<body
|
<body
|
||||||
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
className={`${dmSans.variable} ${dmSerif.variable} ${geistMono.variable} font-sans antialiased`}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
+39
-51
@@ -1,65 +1,53 @@
|
|||||||
import Image from "next/image";
|
import Link from "next/link";
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-screen items-center justify-center bg-zinc-50 font-sans dark:bg-black">
|
<div className="relative flex min-h-screen flex-col items-center justify-center overflow-hidden">
|
||||||
<main className="flex min-h-screen w-full max-w-3xl flex-col items-center justify-between py-32 px-16 bg-white dark:bg-black sm:items-start">
|
{/* Background grain texture */}
|
||||||
<Image
|
<div
|
||||||
className="dark:invert"
|
className="pointer-events-none absolute inset-0 opacity-[0.03]"
|
||||||
src="/next.svg"
|
style={{
|
||||||
alt="Next.js logo"
|
backgroundImage: `url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E")`,
|
||||||
width={100}
|
}}
|
||||||
height={20}
|
|
||||||
priority
|
|
||||||
/>
|
/>
|
||||||
<div className="flex flex-col items-center gap-6 text-center sm:items-start sm:text-left">
|
|
||||||
<h1 className="max-w-xs text-3xl font-semibold leading-10 tracking-tight text-black dark:text-zinc-50">
|
{/* Warm amber glow */}
|
||||||
To get started, edit the page.tsx file.
|
<div className="pointer-events-none absolute left-1/2 top-1/3 h-[600px] w-[600px] -translate-x-1/2 -translate-y-1/2 rounded-full bg-amber/5 blur-[120px]" />
|
||||||
|
|
||||||
|
<main className="relative z-10 flex flex-col items-center gap-10 px-6 text-center">
|
||||||
|
<div className="space-y-4">
|
||||||
|
<p className="text-sm font-medium uppercase tracking-[0.3em] text-amber">
|
||||||
|
Self-hosted movie & TV tracker
|
||||||
|
</p>
|
||||||
|
<h1 className="font-display text-6xl tracking-tight sm:text-7xl md:text-8xl">
|
||||||
|
Couch Potato
|
||||||
</h1>
|
</h1>
|
||||||
<p className="max-w-md text-lg leading-8 text-zinc-600 dark:text-zinc-400">
|
<p className="mx-auto max-w-md text-lg leading-relaxed text-muted-foreground">
|
||||||
Looking for a starting point or more instructions? Head over to{" "}
|
Track what you watch. Know what's next.
|
||||||
<a
|
<br />
|
||||||
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
Your library, your data, your rules.
|
||||||
className="font-medium text-zinc-950 dark:text-zinc-50"
|
|
||||||
>
|
|
||||||
Templates
|
|
||||||
</a>{" "}
|
|
||||||
or the{" "}
|
|
||||||
<a
|
|
||||||
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
|
||||||
className="font-medium text-zinc-950 dark:text-zinc-50"
|
|
||||||
>
|
|
||||||
Learning
|
|
||||||
</a>{" "}
|
|
||||||
center.
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-4 text-base font-medium sm:flex-row">
|
|
||||||
<a
|
<div className="flex gap-4">
|
||||||
className="flex h-12 w-full items-center justify-center gap-2 rounded-full bg-foreground px-5 text-background transition-colors hover:bg-[#383838] dark:hover:bg-[#ccc] md:w-[158px]"
|
<Link
|
||||||
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
href="/login"
|
||||||
target="_blank"
|
className="group relative inline-flex h-12 items-center justify-center overflow-hidden rounded-lg bg-amber px-8 font-medium text-background transition-all hover:shadow-lg hover:shadow-amber/20"
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
>
|
||||||
<Image
|
<span className="relative z-10">Sign In</span>
|
||||||
className="dark:invert"
|
<div className="absolute inset-0 bg-gradient-to-t from-black/10 to-transparent opacity-0 transition-opacity group-hover:opacity-100" />
|
||||||
src="/vercel.svg"
|
</Link>
|
||||||
alt="Vercel logomark"
|
<Link
|
||||||
width={16}
|
href="/register"
|
||||||
height={16}
|
className="inline-flex h-12 items-center justify-center rounded-lg border border-border px-8 font-medium transition-all hover:border-amber/40 hover:bg-amber/5"
|
||||||
/>
|
|
||||||
Deploy Now
|
|
||||||
</a>
|
|
||||||
<a
|
|
||||||
className="flex h-12 w-full items-center justify-center rounded-full border border-solid border-black/[.08] px-5 transition-colors hover:border-transparent hover:bg-black/[.04] dark:border-white/[.145] dark:hover:bg-[#1a1a1a] md:w-[158px]"
|
|
||||||
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
>
|
||||||
Documentation
|
Register
|
||||||
</a>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
|
{/* Bottom fade */}
|
||||||
|
<div className="pointer-events-none absolute bottom-0 left-0 right-0 h-32 bg-gradient-to-t from-background to-transparent" />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,12 @@
|
|||||||
"ignoreUnknown": true,
|
"ignoreUnknown": true,
|
||||||
"includes": ["**", "!node_modules", "!.next", "!dist", "!build"]
|
"includes": ["**", "!node_modules", "!.next", "!dist", "!build"]
|
||||||
},
|
},
|
||||||
|
"css": {
|
||||||
|
"parser": {
|
||||||
|
"cssModules": true,
|
||||||
|
"tailwindDirectives": true
|
||||||
|
}
|
||||||
|
},
|
||||||
"formatter": {
|
"formatter": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"indentStyle": "space",
|
"indentStyle": "space",
|
||||||
|
|||||||
@@ -0,0 +1,166 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import Link from "next/link";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { signIn, signUp } from "@/lib/auth/client";
|
||||||
|
|
||||||
|
export function AuthForm({ mode }: { mode: "login" | "register" }) {
|
||||||
|
const router = useRouter();
|
||||||
|
const [name, setName] = useState("");
|
||||||
|
const [email, setEmail] = useState("");
|
||||||
|
const [password, setPassword] = useState("");
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const isRegister = mode === "register";
|
||||||
|
|
||||||
|
async function handleSubmit(e: React.FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
setError("");
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (isRegister) {
|
||||||
|
const result = await signUp.email({ name, email, password });
|
||||||
|
if (result.error) {
|
||||||
|
setError(result.error.message ?? "Registration failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const result = await signIn.email({ email, password });
|
||||||
|
if (result.error) {
|
||||||
|
setError(result.error.message ?? "Login failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
router.push("/");
|
||||||
|
router.refresh();
|
||||||
|
} catch {
|
||||||
|
setError("Something went wrong");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="relative mx-auto w-full max-w-sm">
|
||||||
|
{/* Subtle glow behind card */}
|
||||||
|
<div className="absolute -inset-4 rounded-2xl bg-amber/3 blur-2xl" />
|
||||||
|
|
||||||
|
<div className="relative space-y-8 rounded-xl border border-border/50 bg-card/80 p-8 backdrop-blur-sm">
|
||||||
|
<div className="space-y-2 text-center">
|
||||||
|
<Link
|
||||||
|
href="/"
|
||||||
|
className="font-display text-2xl tracking-tight text-amber"
|
||||||
|
>
|
||||||
|
Couch Potato
|
||||||
|
</Link>
|
||||||
|
<h1 className="text-lg font-medium">
|
||||||
|
{isRegister ? "Create your account" : "Welcome back"}
|
||||||
|
</h1>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
{isRegister ? "Start tracking your watches" : "Sign in to continue"}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit} className="space-y-4">
|
||||||
|
{isRegister && (
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<label
|
||||||
|
htmlFor="name"
|
||||||
|
className="text-xs font-medium uppercase tracking-wider text-muted-foreground"
|
||||||
|
>
|
||||||
|
Name
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="name"
|
||||||
|
type="text"
|
||||||
|
required
|
||||||
|
value={name}
|
||||||
|
onChange={(e) => setName(e.target.value)}
|
||||||
|
className="flex h-11 w-full rounded-lg border border-border/50 bg-background/50 px-4 text-sm transition-colors placeholder:text-muted-foreground/50 focus:border-amber/40 focus:outline-none focus:ring-1 focus:ring-amber/20"
|
||||||
|
placeholder="Your name"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<label
|
||||||
|
htmlFor="email"
|
||||||
|
className="text-xs font-medium uppercase tracking-wider text-muted-foreground"
|
||||||
|
>
|
||||||
|
Email
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="email"
|
||||||
|
type="email"
|
||||||
|
required
|
||||||
|
value={email}
|
||||||
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
|
className="flex h-11 w-full rounded-lg border border-border/50 bg-background/50 px-4 text-sm transition-colors placeholder:text-muted-foreground/50 focus:border-amber/40 focus:outline-none focus:ring-1 focus:ring-amber/20"
|
||||||
|
placeholder="you@example.com"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<label
|
||||||
|
htmlFor="password"
|
||||||
|
className="text-xs font-medium uppercase tracking-wider text-muted-foreground"
|
||||||
|
>
|
||||||
|
Password
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="password"
|
||||||
|
type="password"
|
||||||
|
required
|
||||||
|
minLength={8}
|
||||||
|
value={password}
|
||||||
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
|
className="flex h-11 w-full rounded-lg border border-border/50 bg-background/50 px-4 text-sm transition-colors placeholder:text-muted-foreground/50 focus:border-amber/40 focus:outline-none focus:ring-1 focus:ring-amber/20"
|
||||||
|
placeholder="Min 8 characters"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<div className="rounded-lg bg-destructive/10 px-3 py-2 text-sm text-destructive">
|
||||||
|
{error}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
disabled={loading}
|
||||||
|
className="inline-flex h-11 w-full items-center justify-center rounded-lg bg-amber font-medium text-background transition-all hover:shadow-lg hover:shadow-amber/20 disabled:pointer-events-none disabled:opacity-50"
|
||||||
|
>
|
||||||
|
{loading ? "Loading..." : isRegister ? "Create account" : "Sign in"}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<p className="text-center text-sm text-muted-foreground">
|
||||||
|
{isRegister ? (
|
||||||
|
<>
|
||||||
|
Already have an account?{" "}
|
||||||
|
<Link
|
||||||
|
href="/login"
|
||||||
|
className="font-medium text-amber transition-colors hover:text-amber/80"
|
||||||
|
>
|
||||||
|
Sign in
|
||||||
|
</Link>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
Don't have an account?{" "}
|
||||||
|
<Link
|
||||||
|
href="/register"
|
||||||
|
className="font-medium text-amber transition-colors hover:text-amber/80"
|
||||||
|
>
|
||||||
|
Register
|
||||||
|
</Link>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { IconLogout, IconSearch } from "@tabler/icons-react";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { usePathname, useRouter } from "next/navigation";
|
||||||
|
import { signOut, useSession } from "@/lib/auth/client";
|
||||||
|
|
||||||
|
export function NavBar() {
|
||||||
|
const { data: session } = useSession();
|
||||||
|
const router = useRouter();
|
||||||
|
const pathname = usePathname();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<header className="sticky top-0 z-50 border-b border-border/50 bg-background/80 backdrop-blur-xl">
|
||||||
|
<nav className="mx-auto flex h-14 max-w-6xl items-center justify-between px-4">
|
||||||
|
<div className="flex items-center gap-8">
|
||||||
|
<Link href="/" className="font-display text-xl tracking-tight">
|
||||||
|
Couch Potato
|
||||||
|
</Link>
|
||||||
|
{session?.user && (
|
||||||
|
<div className="hidden items-center gap-1 sm:flex">
|
||||||
|
<NavLink href="/search" active={pathname === "/search"}>
|
||||||
|
<IconSearch size={16} />
|
||||||
|
<span>Search</span>
|
||||||
|
</NavLink>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
{session?.user ? (
|
||||||
|
<>
|
||||||
|
<span className="text-sm text-muted-foreground">
|
||||||
|
{session.user.name}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={async () => {
|
||||||
|
await signOut();
|
||||||
|
router.push("/");
|
||||||
|
router.refresh();
|
||||||
|
}}
|
||||||
|
className="inline-flex h-8 items-center gap-1.5 rounded-md px-2 text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
|
||||||
|
>
|
||||||
|
<IconLogout size={15} />
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Link
|
||||||
|
href="/login"
|
||||||
|
className="text-sm text-muted-foreground transition-colors hover:text-foreground"
|
||||||
|
>
|
||||||
|
Sign in
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
href="/register"
|
||||||
|
className="inline-flex h-8 items-center rounded-md bg-amber px-4 text-sm font-medium text-background transition-all hover:shadow-md hover:shadow-amber/20"
|
||||||
|
>
|
||||||
|
Register
|
||||||
|
</Link>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function NavLink({
|
||||||
|
href,
|
||||||
|
active,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
href: string;
|
||||||
|
active: boolean;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
href={href}
|
||||||
|
className={`inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-sm transition-colors ${
|
||||||
|
active
|
||||||
|
? "bg-amber/10 text-amber"
|
||||||
|
: "text-muted-foreground hover:bg-accent hover:text-foreground"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { IconSearch } from "@tabler/icons-react";
|
||||||
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
|
interface SearchBarProps {
|
||||||
|
onSearch: (query: string) => void;
|
||||||
|
placeholder?: string;
|
||||||
|
defaultValue?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SearchBar({
|
||||||
|
onSearch,
|
||||||
|
placeholder = "Search movies & TV shows...",
|
||||||
|
defaultValue = "",
|
||||||
|
}: SearchBarProps) {
|
||||||
|
const [value, setValue] = useState(defaultValue);
|
||||||
|
const timerRef = useRef<ReturnType<typeof setTimeout>>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (timerRef.current) clearTimeout(timerRef.current);
|
||||||
|
if (!value.trim()) return;
|
||||||
|
|
||||||
|
timerRef.current = setTimeout(() => {
|
||||||
|
onSearch(value.trim());
|
||||||
|
}, 400);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (timerRef.current) clearTimeout(timerRef.current);
|
||||||
|
};
|
||||||
|
}, [value, onSearch]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="relative">
|
||||||
|
<IconSearch
|
||||||
|
size={18}
|
||||||
|
className="absolute left-4 top-1/2 -translate-y-1/2 text-muted-foreground"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="search"
|
||||||
|
value={value}
|
||||||
|
onChange={(e) => setValue(e.target.value)}
|
||||||
|
placeholder={placeholder}
|
||||||
|
className="flex h-13 w-full rounded-xl border border-border/50 bg-card/50 pl-11 pr-4 text-base backdrop-blur-sm transition-all placeholder:text-muted-foreground/50 focus:border-amber/40 focus:outline-none focus:ring-1 focus:ring-amber/20"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { IconStar, IconStarFilled } from "@tabler/icons-react";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
interface StarRatingProps {
|
||||||
|
value: number;
|
||||||
|
onChange: (value: number) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function StarRating({ value, onChange }: StarRatingProps) {
|
||||||
|
const [hover, setHover] = useState(0);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="flex items-center gap-0.5"
|
||||||
|
role="radiogroup"
|
||||||
|
aria-label="Rating"
|
||||||
|
onMouseLeave={() => setHover(0)}
|
||||||
|
>
|
||||||
|
{[1, 2, 3, 4, 5].map((star) => {
|
||||||
|
const filled = star <= (hover || value);
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={star}
|
||||||
|
type="button"
|
||||||
|
onClick={() => onChange(star === value ? 0 : star)}
|
||||||
|
onMouseEnter={() => setHover(star)}
|
||||||
|
className="p-0.5 transition-transform hover:scale-110"
|
||||||
|
>
|
||||||
|
{filled ? (
|
||||||
|
<IconStarFilled size={18} className="text-amber" />
|
||||||
|
) : (
|
||||||
|
<IconStar size={18} className="text-muted-foreground/30" />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import {
|
||||||
|
IconBookmark,
|
||||||
|
IconCheck,
|
||||||
|
IconPlayerPlay,
|
||||||
|
IconPlus,
|
||||||
|
IconX,
|
||||||
|
} from "@tabler/icons-react";
|
||||||
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
|
const statuses = [
|
||||||
|
{ value: "watchlist", label: "Watchlist", icon: IconBookmark },
|
||||||
|
{ value: "in_progress", label: "Watching", icon: IconPlayerPlay },
|
||||||
|
{ value: "completed", label: "Completed", icon: IconCheck },
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
interface StatusButtonProps {
|
||||||
|
currentStatus: string | null;
|
||||||
|
onChange: (status: string | null) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function StatusButton({ currentStatus, onChange }: StatusButtonProps) {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
function handleClick(e: MouseEvent) {
|
||||||
|
if (ref.current && !ref.current.contains(e.target as Node)) {
|
||||||
|
setOpen(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.addEventListener("mousedown", handleClick);
|
||||||
|
return () => document.removeEventListener("mousedown", handleClick);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const current = statuses.find((s) => s.value === currentStatus);
|
||||||
|
const CurrentIcon = current?.icon ?? IconPlus;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div ref={ref} className="relative">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setOpen(!open)}
|
||||||
|
className={`inline-flex h-9 items-center gap-2 rounded-lg border px-4 text-sm font-medium transition-all ${
|
||||||
|
current
|
||||||
|
? "border-amber/30 bg-amber/10 text-amber hover:bg-amber/15"
|
||||||
|
: "border-border/50 hover:border-amber/30 hover:bg-amber/5"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<CurrentIcon size={15} />
|
||||||
|
{current ? current.label : "Add to List"}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{open && (
|
||||||
|
<div className="absolute left-0 top-full z-20 mt-1.5 w-44 overflow-hidden rounded-lg border border-border/50 bg-popover/95 p-1 shadow-xl shadow-black/30 backdrop-blur-xl">
|
||||||
|
{statuses.map((s) => {
|
||||||
|
const Icon = s.icon;
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={s.value}
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
onChange(s.value === currentStatus ? null : s.value);
|
||||||
|
setOpen(false);
|
||||||
|
}}
|
||||||
|
className={`flex w-full items-center gap-2 rounded-md px-3 py-2 text-sm transition-colors hover:bg-accent ${
|
||||||
|
s.value === currentStatus ? "text-amber" : "text-foreground"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<Icon size={15} />
|
||||||
|
{s.label}
|
||||||
|
{s.value === currentStatus && (
|
||||||
|
<IconCheck size={13} className="ml-auto" />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
{currentStatus && (
|
||||||
|
<>
|
||||||
|
<div className="my-1 border-t border-border/50" />
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
onChange(null);
|
||||||
|
setOpen(false);
|
||||||
|
}}
|
||||||
|
className="flex w-full items-center gap-2 rounded-md px-3 py-2 text-sm text-destructive transition-colors hover:bg-accent"
|
||||||
|
>
|
||||||
|
<IconX size={15} />
|
||||||
|
Remove
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
import Image from "next/image";
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
|
interface TitleCardProps {
|
||||||
|
id?: string;
|
||||||
|
tmdbId: number;
|
||||||
|
type: string;
|
||||||
|
title: string;
|
||||||
|
posterPath: string | null;
|
||||||
|
releaseDate?: string | null;
|
||||||
|
voteAverage?: number | null;
|
||||||
|
href?: string;
|
||||||
|
onImport?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TitleCard({
|
||||||
|
id,
|
||||||
|
type,
|
||||||
|
title,
|
||||||
|
posterPath,
|
||||||
|
releaseDate,
|
||||||
|
voteAverage,
|
||||||
|
href,
|
||||||
|
onImport,
|
||||||
|
}: TitleCardProps) {
|
||||||
|
const year = releaseDate?.slice(0, 4);
|
||||||
|
const posterUrl = posterPath
|
||||||
|
? `https://image.tmdb.org/t/p/w300${posterPath}`
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const content = (
|
||||||
|
<div className="group relative overflow-hidden rounded-lg transition-transform duration-200 hover:scale-[1.02]">
|
||||||
|
<div className="aspect-[2/3] overflow-hidden rounded-lg bg-card">
|
||||||
|
{posterUrl ? (
|
||||||
|
<Image
|
||||||
|
src={posterUrl}
|
||||||
|
alt={title}
|
||||||
|
width={300}
|
||||||
|
height={450}
|
||||||
|
className="h-full w-full object-cover transition-all duration-300 group-hover:brightness-110"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="flex h-full items-center justify-center bg-gradient-to-br from-card to-muted text-sm text-muted-foreground">
|
||||||
|
No poster
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{/* Overlay gradient */}
|
||||||
|
<div className="absolute inset-0 bg-gradient-to-t from-black/70 via-transparent to-transparent opacity-0 transition-opacity duration-200 group-hover:opacity-100" />
|
||||||
|
</div>
|
||||||
|
<div className="mt-2 space-y-0.5">
|
||||||
|
<p className="line-clamp-1 text-sm font-medium leading-snug">{title}</p>
|
||||||
|
<div className="flex items-center gap-1.5 text-xs text-muted-foreground">
|
||||||
|
<span className="rounded bg-amber/10 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider text-amber">
|
||||||
|
{type}
|
||||||
|
</span>
|
||||||
|
{year && <span>{year}</span>}
|
||||||
|
{voteAverage != null && voteAverage > 0 && (
|
||||||
|
<span className="text-amber">★ {voteAverage.toFixed(1)}</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (href || id) {
|
||||||
|
return <Link href={href ?? `/titles/${id}`}>{content}</Link>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onImport) {
|
||||||
|
return (
|
||||||
|
<button type="button" onClick={onImport} className="w-full text-left">
|
||||||
|
{content}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
@@ -1,25 +1,24 @@
|
|||||||
"use client"
|
"use client";
|
||||||
|
|
||||||
import * as React from "react"
|
import { AlertDialog as AlertDialogPrimitive } from "@base-ui/react/alert-dialog";
|
||||||
import { AlertDialog as AlertDialogPrimitive } from "@base-ui/react/alert-dialog"
|
import type * as React from "react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
import { Button } from "@/components/ui/button"
|
|
||||||
|
|
||||||
function AlertDialog({ ...props }: AlertDialogPrimitive.Root.Props) {
|
function AlertDialog({ ...props }: AlertDialogPrimitive.Root.Props) {
|
||||||
return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />
|
return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
function AlertDialogTrigger({ ...props }: AlertDialogPrimitive.Trigger.Props) {
|
function AlertDialogTrigger({ ...props }: AlertDialogPrimitive.Trigger.Props) {
|
||||||
return (
|
return (
|
||||||
<AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />
|
<AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function AlertDialogPortal({ ...props }: AlertDialogPrimitive.Portal.Props) {
|
function AlertDialogPortal({ ...props }: AlertDialogPrimitive.Portal.Props) {
|
||||||
return (
|
return (
|
||||||
<AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} />
|
<AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} />
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function AlertDialogOverlay({
|
function AlertDialogOverlay({
|
||||||
@@ -31,11 +30,11 @@ function AlertDialogOverlay({
|
|||||||
data-slot="alert-dialog-overlay"
|
data-slot="alert-dialog-overlay"
|
||||||
className={cn(
|
className={cn(
|
||||||
"data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs",
|
"data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function AlertDialogContent({
|
function AlertDialogContent({
|
||||||
@@ -43,7 +42,7 @@ function AlertDialogContent({
|
|||||||
size = "default",
|
size = "default",
|
||||||
...props
|
...props
|
||||||
}: AlertDialogPrimitive.Popup.Props & {
|
}: AlertDialogPrimitive.Popup.Props & {
|
||||||
size?: "default" | "sm"
|
size?: "default" | "sm";
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<AlertDialogPortal>
|
<AlertDialogPortal>
|
||||||
@@ -53,12 +52,12 @@ function AlertDialogContent({
|
|||||||
data-size={size}
|
data-size={size}
|
||||||
className={cn(
|
className={cn(
|
||||||
"data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 bg-background ring-foreground/10 group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 gap-4 rounded-none p-4 ring-1 duration-100 outline-none data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-sm",
|
"data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 bg-background ring-foreground/10 group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 gap-4 rounded-none p-4 ring-1 duration-100 outline-none data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-sm",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
</AlertDialogPortal>
|
</AlertDialogPortal>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function AlertDialogHeader({
|
function AlertDialogHeader({
|
||||||
@@ -70,11 +69,11 @@ function AlertDialogHeader({
|
|||||||
data-slot="alert-dialog-header"
|
data-slot="alert-dialog-header"
|
||||||
className={cn(
|
className={cn(
|
||||||
"grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-4 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",
|
"grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-4 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function AlertDialogFooter({
|
function AlertDialogFooter({
|
||||||
@@ -86,11 +85,11 @@ function AlertDialogFooter({
|
|||||||
data-slot="alert-dialog-footer"
|
data-slot="alert-dialog-footer"
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end",
|
"flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function AlertDialogMedia({
|
function AlertDialogMedia({
|
||||||
@@ -102,11 +101,11 @@ function AlertDialogMedia({
|
|||||||
data-slot="alert-dialog-media"
|
data-slot="alert-dialog-media"
|
||||||
className={cn(
|
className={cn(
|
||||||
"bg-muted mb-2 inline-flex size-10 items-center justify-center rounded-none sm:group-data-[size=default]/alert-dialog-content:row-span-2 *:[svg:not([class*='size-'])]:size-6",
|
"bg-muted mb-2 inline-flex size-10 items-center justify-center rounded-none sm:group-data-[size=default]/alert-dialog-content:row-span-2 *:[svg:not([class*='size-'])]:size-6",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function AlertDialogTitle({
|
function AlertDialogTitle({
|
||||||
@@ -118,11 +117,11 @@ function AlertDialogTitle({
|
|||||||
data-slot="alert-dialog-title"
|
data-slot="alert-dialog-title"
|
||||||
className={cn(
|
className={cn(
|
||||||
"text-sm font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",
|
"text-sm font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function AlertDialogDescription({
|
function AlertDialogDescription({
|
||||||
@@ -134,11 +133,11 @@ function AlertDialogDescription({
|
|||||||
data-slot="alert-dialog-description"
|
data-slot="alert-dialog-description"
|
||||||
className={cn(
|
className={cn(
|
||||||
"text-muted-foreground *:[a]:hover:text-foreground text-xs/relaxed text-balance md:text-pretty *:[a]:underline *:[a]:underline-offset-3",
|
"text-muted-foreground *:[a]:hover:text-foreground text-xs/relaxed text-balance md:text-pretty *:[a]:underline *:[a]:underline-offset-3",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function AlertDialogAction({
|
function AlertDialogAction({
|
||||||
@@ -151,7 +150,7 @@ function AlertDialogAction({
|
|||||||
className={cn(className)}
|
className={cn(className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function AlertDialogCancel({
|
function AlertDialogCancel({
|
||||||
@@ -168,7 +167,7 @@ function AlertDialogCancel({
|
|||||||
render={<Button variant={variant} size={size} />}
|
render={<Button variant={variant} size={size} />}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -184,4 +183,4 @@ export {
|
|||||||
AlertDialogPortal,
|
AlertDialogPortal,
|
||||||
AlertDialogTitle,
|
AlertDialogTitle,
|
||||||
AlertDialogTrigger,
|
AlertDialogTrigger,
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { mergeProps } from "@base-ui/react/merge-props"
|
import { mergeProps } from "@base-ui/react/merge-props";
|
||||||
import { useRender } from "@base-ui/react/use-render"
|
import { useRender } from "@base-ui/react/use-render";
|
||||||
import { cva, type VariantProps } from "class-variance-authority"
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const badgeVariants = cva(
|
const badgeVariants = cva(
|
||||||
"h-5 gap-1 rounded-none border border-transparent px-2 py-0.5 text-xs font-medium transition-all has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&>svg]:size-3! inline-flex items-center justify-center w-fit whitespace-nowrap shrink-0 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive overflow-hidden group/badge",
|
"h-5 gap-1 rounded-none border border-transparent px-2 py-0.5 text-xs font-medium transition-all has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&>svg]:size-3! inline-flex items-center justify-center w-fit whitespace-nowrap shrink-0 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive overflow-hidden group/badge",
|
||||||
@@ -24,8 +24,8 @@ const badgeVariants = cva(
|
|||||||
defaultVariants: {
|
defaultVariants: {
|
||||||
variant: "default",
|
variant: "default",
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
)
|
);
|
||||||
|
|
||||||
function Badge({
|
function Badge({
|
||||||
className,
|
className,
|
||||||
@@ -39,14 +39,14 @@ function Badge({
|
|||||||
{
|
{
|
||||||
className: cn(badgeVariants({ variant }), className),
|
className: cn(badgeVariants({ variant }), className),
|
||||||
},
|
},
|
||||||
props
|
props,
|
||||||
),
|
),
|
||||||
render,
|
render,
|
||||||
state: {
|
state: {
|
||||||
slot: "badge",
|
slot: "badge",
|
||||||
variant,
|
variant,
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Badge, badgeVariants }
|
export { Badge, badgeVariants };
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
"use client"
|
"use client";
|
||||||
|
|
||||||
import { Button as ButtonPrimitive } from "@base-ui/react/button"
|
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
||||||
import { cva, type VariantProps } from "class-variance-authority"
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const buttonVariants = cva(
|
const buttonVariants = cva(
|
||||||
"focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 rounded-none border border-transparent bg-clip-padding text-xs font-medium focus-visible:ring-1 aria-invalid:ring-1 [&_svg:not([class*='size-'])]:size-4 inline-flex items-center justify-center whitespace-nowrap transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none shrink-0 [&_svg]:shrink-0 outline-none group/button select-none",
|
"focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 rounded-none border border-transparent bg-clip-padding text-xs font-medium focus-visible:ring-1 aria-invalid:ring-1 [&_svg:not([class*='size-'])]:size-4 inline-flex items-center justify-center whitespace-nowrap transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none shrink-0 [&_svg]:shrink-0 outline-none group/button select-none",
|
||||||
@@ -37,8 +37,8 @@ const buttonVariants = cva(
|
|||||||
variant: "default",
|
variant: "default",
|
||||||
size: "default",
|
size: "default",
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
)
|
);
|
||||||
|
|
||||||
function Button({
|
function Button({
|
||||||
className,
|
className,
|
||||||
@@ -52,7 +52,7 @@ function Button({
|
|||||||
className={cn(buttonVariants({ variant, size, className }))}
|
className={cn(buttonVariants({ variant, size, className }))}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Button, buttonVariants }
|
export { Button, buttonVariants };
|
||||||
|
|||||||
+15
-15
@@ -1,6 +1,6 @@
|
|||||||
import * as React from "react"
|
import type * as React from "react";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
function Card({
|
function Card({
|
||||||
className,
|
className,
|
||||||
@@ -13,11 +13,11 @@ function Card({
|
|||||||
data-size={size}
|
data-size={size}
|
||||||
className={cn(
|
className={cn(
|
||||||
"ring-foreground/10 bg-card text-card-foreground group/card flex flex-col gap-4 overflow-hidden rounded-none py-4 text-xs/relaxed ring-1 has-data-[slot=card-footer]:pb-0 has-[>img:first-child]:pt-0 data-[size=sm]:gap-2 data-[size=sm]:py-3 data-[size=sm]:has-data-[slot=card-footer]:pb-0 *:[img:first-child]:rounded-none *:[img:last-child]:rounded-none",
|
"ring-foreground/10 bg-card text-card-foreground group/card flex flex-col gap-4 overflow-hidden rounded-none py-4 text-xs/relaxed ring-1 has-data-[slot=card-footer]:pb-0 has-[>img:first-child]:pt-0 data-[size=sm]:gap-2 data-[size=sm]:py-3 data-[size=sm]:has-data-[slot=card-footer]:pb-0 *:[img:first-child]:rounded-none *:[img:last-child]:rounded-none",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
@@ -26,11 +26,11 @@ function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|||||||
data-slot="card-header"
|
data-slot="card-header"
|
||||||
className={cn(
|
className={cn(
|
||||||
"group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-none px-4 group-data-[size=sm]/card:px-3 has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-4 group-data-[size=sm]/card:[.border-b]:pb-3",
|
"group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-none px-4 group-data-[size=sm]/card:px-3 has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-4 group-data-[size=sm]/card:[.border-b]:pb-3",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
@@ -39,11 +39,11 @@ function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|||||||
data-slot="card-title"
|
data-slot="card-title"
|
||||||
className={cn(
|
className={cn(
|
||||||
"text-sm font-medium group-data-[size=sm]/card:text-sm",
|
"text-sm font-medium group-data-[size=sm]/card:text-sm",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
@@ -53,7 +53,7 @@ function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
|||||||
className={cn("text-muted-foreground text-xs/relaxed", className)}
|
className={cn("text-muted-foreground text-xs/relaxed", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
@@ -62,11 +62,11 @@ function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
|||||||
data-slot="card-action"
|
data-slot="card-action"
|
||||||
className={cn(
|
className={cn(
|
||||||
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
@@ -76,7 +76,7 @@ function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
|||||||
className={cn("px-4 group-data-[size=sm]/card:px-3", className)}
|
className={cn("px-4 group-data-[size=sm]/card:px-3", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
@@ -85,11 +85,11 @@ function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
|||||||
data-slot="card-footer"
|
data-slot="card-footer"
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex items-center rounded-none border-t p-4 group-data-[size=sm]/card:p-3",
|
"flex items-center rounded-none border-t p-4 group-data-[size=sm]/card:p-3",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -100,4 +100,4 @@ export {
|
|||||||
CardAction,
|
CardAction,
|
||||||
CardDescription,
|
CardDescription,
|
||||||
CardContent,
|
CardContent,
|
||||||
}
|
};
|
||||||
|
|||||||
+37
-35
@@ -1,22 +1,21 @@
|
|||||||
"use client"
|
"use client";
|
||||||
|
|
||||||
import * as React from "react"
|
import { Combobox as ComboboxPrimitive } from "@base-ui/react";
|
||||||
import { Combobox as ComboboxPrimitive } from "@base-ui/react"
|
import { IconCheck, IconChevronDown, IconX } from "@tabler/icons-react";
|
||||||
|
import * as React from "react";
|
||||||
import { cn } from "@/lib/utils"
|
import { Button } from "@/components/ui/button";
|
||||||
import { Button } from "@/components/ui/button"
|
|
||||||
import {
|
import {
|
||||||
InputGroup,
|
InputGroup,
|
||||||
InputGroupAddon,
|
InputGroupAddon,
|
||||||
InputGroupButton,
|
InputGroupButton,
|
||||||
InputGroupInput,
|
InputGroupInput,
|
||||||
} from "@/components/ui/input-group"
|
} from "@/components/ui/input-group";
|
||||||
import { IconChevronDown, IconX, IconCheck } from "@tabler/icons-react"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const Combobox = ComboboxPrimitive.Root
|
const Combobox = ComboboxPrimitive.Root;
|
||||||
|
|
||||||
function ComboboxValue({ ...props }: ComboboxPrimitive.Value.Props) {
|
function ComboboxValue({ ...props }: ComboboxPrimitive.Value.Props) {
|
||||||
return <ComboboxPrimitive.Value data-slot="combobox-value" {...props} />
|
return <ComboboxPrimitive.Value data-slot="combobox-value" {...props} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ComboboxTrigger({
|
function ComboboxTrigger({
|
||||||
@@ -33,7 +32,7 @@ function ComboboxTrigger({
|
|||||||
{children}
|
{children}
|
||||||
<IconChevronDown className="text-muted-foreground pointer-events-none size-4" />
|
<IconChevronDown className="text-muted-foreground pointer-events-none size-4" />
|
||||||
</ComboboxPrimitive.Trigger>
|
</ComboboxPrimitive.Trigger>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ComboboxClear({ className, ...props }: ComboboxPrimitive.Clear.Props) {
|
function ComboboxClear({ className, ...props }: ComboboxPrimitive.Clear.Props) {
|
||||||
@@ -46,7 +45,7 @@ function ComboboxClear({ className, ...props }: ComboboxPrimitive.Clear.Props) {
|
|||||||
>
|
>
|
||||||
<IconX className="pointer-events-none" />
|
<IconX className="pointer-events-none" />
|
||||||
</ComboboxPrimitive.Clear>
|
</ComboboxPrimitive.Clear>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ComboboxInput({
|
function ComboboxInput({
|
||||||
@@ -57,8 +56,8 @@ function ComboboxInput({
|
|||||||
showClear = false,
|
showClear = false,
|
||||||
...props
|
...props
|
||||||
}: ComboboxPrimitive.Input.Props & {
|
}: ComboboxPrimitive.Input.Props & {
|
||||||
showTrigger?: boolean
|
showTrigger?: boolean;
|
||||||
showClear?: boolean
|
showClear?: boolean;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<InputGroup className={cn("w-auto", className)}>
|
<InputGroup className={cn("w-auto", className)}>
|
||||||
@@ -81,7 +80,7 @@ function ComboboxInput({
|
|||||||
</InputGroupAddon>
|
</InputGroupAddon>
|
||||||
{children}
|
{children}
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ComboboxContent({
|
function ComboboxContent({
|
||||||
@@ -110,12 +109,15 @@ function ComboboxContent({
|
|||||||
<ComboboxPrimitive.Popup
|
<ComboboxPrimitive.Popup
|
||||||
data-slot="combobox-content"
|
data-slot="combobox-content"
|
||||||
data-chips={!!anchor}
|
data-chips={!!anchor}
|
||||||
className={cn("bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 *:data-[slot=input-group]:bg-input/30 *:data-[slot=input-group]:border-input/30 data-[side=inline-start]:slide-in-from-right-2 data-[side=inline-end]:slide-in-from-left-2 group/combobox-content relative max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) min-w-[calc(var(--anchor-width)+--spacing(7))] origin-(--transform-origin) overflow-hidden rounded-none shadow-md ring-1 duration-100 data-[chips=true]:min-w-(--anchor-width) *:data-[slot=input-group]:m-1 *:data-[slot=input-group]:mb-0 *:data-[slot=input-group]:h-8 *:data-[slot=input-group]:shadow-none", className )}
|
className={cn(
|
||||||
|
"bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 *:data-[slot=input-group]:bg-input/30 *:data-[slot=input-group]:border-input/30 data-[side=inline-start]:slide-in-from-right-2 data-[side=inline-end]:slide-in-from-left-2 group/combobox-content relative max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) min-w-[calc(var(--anchor-width)+--spacing(7))] origin-(--transform-origin) overflow-hidden rounded-none shadow-md ring-1 duration-100 data-[chips=true]:min-w-(--anchor-width) *:data-[slot=input-group]:m-1 *:data-[slot=input-group]:mb-0 *:data-[slot=input-group]:h-8 *:data-[slot=input-group]:shadow-none",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
</ComboboxPrimitive.Positioner>
|
</ComboboxPrimitive.Positioner>
|
||||||
</ComboboxPrimitive.Portal>
|
</ComboboxPrimitive.Portal>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ComboboxList({ className, ...props }: ComboboxPrimitive.List.Props) {
|
function ComboboxList({ className, ...props }: ComboboxPrimitive.List.Props) {
|
||||||
@@ -124,11 +126,11 @@ function ComboboxList({ className, ...props }: ComboboxPrimitive.List.Props) {
|
|||||||
data-slot="combobox-list"
|
data-slot="combobox-list"
|
||||||
className={cn(
|
className={cn(
|
||||||
"no-scrollbar max-h-[min(calc(--spacing(72)---spacing(9)),calc(var(--available-height)---spacing(9)))] scroll-py-1 overflow-y-auto overscroll-contain data-empty:p-0",
|
"no-scrollbar max-h-[min(calc(--spacing(72)---spacing(9)),calc(var(--available-height)---spacing(9)))] scroll-py-1 overflow-y-auto overscroll-contain data-empty:p-0",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ComboboxItem({
|
function ComboboxItem({
|
||||||
@@ -141,7 +143,7 @@ function ComboboxItem({
|
|||||||
data-slot="combobox-item"
|
data-slot="combobox-item"
|
||||||
className={cn(
|
className={cn(
|
||||||
"data-highlighted:bg-accent data-highlighted:text-accent-foreground not-data-[variant=destructive]:data-highlighted:**:text-accent-foreground relative flex w-full cursor-default items-center gap-2 rounded-none py-2 pr-8 pl-2 text-xs outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
"data-highlighted:bg-accent data-highlighted:text-accent-foreground not-data-[variant=destructive]:data-highlighted:**:text-accent-foreground relative flex w-full cursor-default items-center gap-2 rounded-none py-2 pr-8 pl-2 text-xs outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
@@ -154,7 +156,7 @@ function ComboboxItem({
|
|||||||
<IconCheck className="pointer-events-none" />
|
<IconCheck className="pointer-events-none" />
|
||||||
</ComboboxPrimitive.ItemIndicator>
|
</ComboboxPrimitive.ItemIndicator>
|
||||||
</ComboboxPrimitive.Item>
|
</ComboboxPrimitive.Item>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ComboboxGroup({ className, ...props }: ComboboxPrimitive.Group.Props) {
|
function ComboboxGroup({ className, ...props }: ComboboxPrimitive.Group.Props) {
|
||||||
@@ -164,7 +166,7 @@ function ComboboxGroup({ className, ...props }: ComboboxPrimitive.Group.Props) {
|
|||||||
className={cn(className)}
|
className={cn(className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ComboboxLabel({
|
function ComboboxLabel({
|
||||||
@@ -177,13 +179,13 @@ function ComboboxLabel({
|
|||||||
className={cn("text-muted-foreground px-2 py-2 text-xs", className)}
|
className={cn("text-muted-foreground px-2 py-2 text-xs", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ComboboxCollection({ ...props }: ComboboxPrimitive.Collection.Props) {
|
function ComboboxCollection({ ...props }: ComboboxPrimitive.Collection.Props) {
|
||||||
return (
|
return (
|
||||||
<ComboboxPrimitive.Collection data-slot="combobox-collection" {...props} />
|
<ComboboxPrimitive.Collection data-slot="combobox-collection" {...props} />
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ComboboxEmpty({ className, ...props }: ComboboxPrimitive.Empty.Props) {
|
function ComboboxEmpty({ className, ...props }: ComboboxPrimitive.Empty.Props) {
|
||||||
@@ -192,11 +194,11 @@ function ComboboxEmpty({ className, ...props }: ComboboxPrimitive.Empty.Props) {
|
|||||||
data-slot="combobox-empty"
|
data-slot="combobox-empty"
|
||||||
className={cn(
|
className={cn(
|
||||||
"text-muted-foreground hidden w-full justify-center py-2 text-center text-xs group-data-empty/combobox-content:flex",
|
"text-muted-foreground hidden w-full justify-center py-2 text-center text-xs group-data-empty/combobox-content:flex",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ComboboxSeparator({
|
function ComboboxSeparator({
|
||||||
@@ -209,7 +211,7 @@ function ComboboxSeparator({
|
|||||||
className={cn("bg-border -mx-1 h-px", className)}
|
className={cn("bg-border -mx-1 h-px", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ComboboxChips({
|
function ComboboxChips({
|
||||||
@@ -222,11 +224,11 @@ function ComboboxChips({
|
|||||||
data-slot="combobox-chips"
|
data-slot="combobox-chips"
|
||||||
className={cn(
|
className={cn(
|
||||||
"dark:bg-input/30 border-input focus-within:border-ring focus-within:ring-ring/50 has-aria-invalid:ring-destructive/20 dark:has-aria-invalid:ring-destructive/40 has-aria-invalid:border-destructive dark:has-aria-invalid:border-destructive/50 flex min-h-8 flex-wrap items-center gap-1 rounded-none border bg-transparent bg-clip-padding px-2.5 py-1 text-xs transition-colors focus-within:ring-1 has-aria-invalid:ring-1 has-data-[slot=combobox-chip]:px-1",
|
"dark:bg-input/30 border-input focus-within:border-ring focus-within:ring-ring/50 has-aria-invalid:ring-destructive/20 dark:has-aria-invalid:ring-destructive/40 has-aria-invalid:border-destructive dark:has-aria-invalid:border-destructive/50 flex min-h-8 flex-wrap items-center gap-1 rounded-none border bg-transparent bg-clip-padding px-2.5 py-1 text-xs transition-colors focus-within:ring-1 has-aria-invalid:ring-1 has-data-[slot=combobox-chip]:px-1",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ComboboxChip({
|
function ComboboxChip({
|
||||||
@@ -235,14 +237,14 @@ function ComboboxChip({
|
|||||||
showRemove = true,
|
showRemove = true,
|
||||||
...props
|
...props
|
||||||
}: ComboboxPrimitive.Chip.Props & {
|
}: ComboboxPrimitive.Chip.Props & {
|
||||||
showRemove?: boolean
|
showRemove?: boolean;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<ComboboxPrimitive.Chip
|
<ComboboxPrimitive.Chip
|
||||||
data-slot="combobox-chip"
|
data-slot="combobox-chip"
|
||||||
className={cn(
|
className={cn(
|
||||||
"bg-muted text-foreground flex h-[calc(--spacing(5.25))] w-fit items-center justify-center gap-1 rounded-none px-1.5 text-xs font-medium whitespace-nowrap has-disabled:pointer-events-none has-disabled:cursor-not-allowed has-disabled:opacity-50 has-data-[slot=combobox-chip-remove]:pr-0",
|
"bg-muted text-foreground flex h-[calc(--spacing(5.25))] w-fit items-center justify-center gap-1 rounded-none px-1.5 text-xs font-medium whitespace-nowrap has-disabled:pointer-events-none has-disabled:cursor-not-allowed has-disabled:opacity-50 has-data-[slot=combobox-chip-remove]:pr-0",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
@@ -257,7 +259,7 @@ function ComboboxChip({
|
|||||||
</ComboboxPrimitive.ChipRemove>
|
</ComboboxPrimitive.ChipRemove>
|
||||||
)}
|
)}
|
||||||
</ComboboxPrimitive.Chip>
|
</ComboboxPrimitive.Chip>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ComboboxChipsInput({
|
function ComboboxChipsInput({
|
||||||
@@ -270,11 +272,11 @@ function ComboboxChipsInput({
|
|||||||
className={cn("min-w-16 flex-1 outline-none", className)}
|
className={cn("min-w-16 flex-1 outline-none", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function useComboboxAnchor() {
|
function useComboboxAnchor() {
|
||||||
return React.useRef<HTMLDivElement | null>(null)
|
return React.useRef<HTMLDivElement | null>(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -294,4 +296,4 @@ export {
|
|||||||
ComboboxTrigger,
|
ComboboxTrigger,
|
||||||
ComboboxValue,
|
ComboboxValue,
|
||||||
useComboboxAnchor,
|
useComboboxAnchor,
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
"use client"
|
"use client";
|
||||||
|
|
||||||
import * as React from "react"
|
import { Menu as MenuPrimitive } from "@base-ui/react/menu";
|
||||||
import { Menu as MenuPrimitive } from "@base-ui/react/menu"
|
import { IconCheck, IconChevronRight } from "@tabler/icons-react";
|
||||||
|
import type * as React from "react";
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
import { IconChevronRight, IconCheck } from "@tabler/icons-react"
|
|
||||||
|
|
||||||
function DropdownMenu({ ...props }: MenuPrimitive.Root.Props) {
|
function DropdownMenu({ ...props }: MenuPrimitive.Root.Props) {
|
||||||
return <MenuPrimitive.Root data-slot="dropdown-menu" {...props} />
|
return <MenuPrimitive.Root data-slot="dropdown-menu" {...props} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuPortal({ ...props }: MenuPrimitive.Portal.Props) {
|
function DropdownMenuPortal({ ...props }: MenuPrimitive.Portal.Props) {
|
||||||
return <MenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
|
return <MenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuTrigger({ ...props }: MenuPrimitive.Trigger.Props) {
|
function DropdownMenuTrigger({ ...props }: MenuPrimitive.Trigger.Props) {
|
||||||
return <MenuPrimitive.Trigger data-slot="dropdown-menu-trigger" {...props} />
|
return <MenuPrimitive.Trigger data-slot="dropdown-menu-trigger" {...props} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuContent({
|
function DropdownMenuContent({
|
||||||
@@ -41,16 +40,19 @@ function DropdownMenuContent({
|
|||||||
>
|
>
|
||||||
<MenuPrimitive.Popup
|
<MenuPrimitive.Popup
|
||||||
data-slot="dropdown-menu-content"
|
data-slot="dropdown-menu-content"
|
||||||
className={cn("data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 bg-popover text-popover-foreground data-[side=inline-start]:slide-in-from-right-2 data-[side=inline-end]:slide-in-from-left-2 z-50 max-h-(--available-height) w-(--anchor-width) min-w-32 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-none shadow-md ring-1 duration-100 outline-none data-closed:overflow-hidden", className )}
|
className={cn(
|
||||||
|
"data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 bg-popover text-popover-foreground data-[side=inline-start]:slide-in-from-right-2 data-[side=inline-end]:slide-in-from-left-2 z-50 max-h-(--available-height) w-(--anchor-width) min-w-32 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-none shadow-md ring-1 duration-100 outline-none data-closed:overflow-hidden",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
</MenuPrimitive.Positioner>
|
</MenuPrimitive.Positioner>
|
||||||
</MenuPrimitive.Portal>
|
</MenuPrimitive.Portal>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuGroup({ ...props }: MenuPrimitive.Group.Props) {
|
function DropdownMenuGroup({ ...props }: MenuPrimitive.Group.Props) {
|
||||||
return <MenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
|
return <MenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuLabel({
|
function DropdownMenuLabel({
|
||||||
@@ -58,7 +60,7 @@ function DropdownMenuLabel({
|
|||||||
inset,
|
inset,
|
||||||
...props
|
...props
|
||||||
}: MenuPrimitive.GroupLabel.Props & {
|
}: MenuPrimitive.GroupLabel.Props & {
|
||||||
inset?: boolean
|
inset?: boolean;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<MenuPrimitive.GroupLabel
|
<MenuPrimitive.GroupLabel
|
||||||
@@ -66,11 +68,11 @@ function DropdownMenuLabel({
|
|||||||
data-inset={inset}
|
data-inset={inset}
|
||||||
className={cn(
|
className={cn(
|
||||||
"text-muted-foreground px-2 py-2 text-xs data-inset:pl-7",
|
"text-muted-foreground px-2 py-2 text-xs data-inset:pl-7",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuItem({
|
function DropdownMenuItem({
|
||||||
@@ -79,8 +81,8 @@ function DropdownMenuItem({
|
|||||||
variant = "default",
|
variant = "default",
|
||||||
...props
|
...props
|
||||||
}: MenuPrimitive.Item.Props & {
|
}: MenuPrimitive.Item.Props & {
|
||||||
inset?: boolean
|
inset?: boolean;
|
||||||
variant?: "default" | "destructive"
|
variant?: "default" | "destructive";
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<MenuPrimitive.Item
|
<MenuPrimitive.Item
|
||||||
@@ -89,15 +91,15 @@ function DropdownMenuItem({
|
|||||||
data-variant={variant}
|
data-variant={variant}
|
||||||
className={cn(
|
className={cn(
|
||||||
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:text-destructive not-data-[variant=destructive]:focus:**:text-accent-foreground group/dropdown-menu-item relative flex cursor-default items-center gap-2 rounded-none px-2 py-2 text-xs outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 data-inset:pl-7 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:text-destructive not-data-[variant=destructive]:focus:**:text-accent-foreground group/dropdown-menu-item relative flex cursor-default items-center gap-2 rounded-none px-2 py-2 text-xs outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 data-inset:pl-7 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuSub({ ...props }: MenuPrimitive.SubmenuRoot.Props) {
|
function DropdownMenuSub({ ...props }: MenuPrimitive.SubmenuRoot.Props) {
|
||||||
return <MenuPrimitive.SubmenuRoot data-slot="dropdown-menu-sub" {...props} />
|
return <MenuPrimitive.SubmenuRoot data-slot="dropdown-menu-sub" {...props} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuSubTrigger({
|
function DropdownMenuSubTrigger({
|
||||||
@@ -106,7 +108,7 @@ function DropdownMenuSubTrigger({
|
|||||||
children,
|
children,
|
||||||
...props
|
...props
|
||||||
}: MenuPrimitive.SubmenuTrigger.Props & {
|
}: MenuPrimitive.SubmenuTrigger.Props & {
|
||||||
inset?: boolean
|
inset?: boolean;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<MenuPrimitive.SubmenuTrigger
|
<MenuPrimitive.SubmenuTrigger
|
||||||
@@ -114,14 +116,14 @@ function DropdownMenuSubTrigger({
|
|||||||
data-inset={inset}
|
data-inset={inset}
|
||||||
className={cn(
|
className={cn(
|
||||||
"focus:bg-accent focus:text-accent-foreground data-open:bg-accent data-open:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-popup-open:bg-accent data-popup-open:text-accent-foreground flex cursor-default items-center gap-2 rounded-none px-2 py-2 text-xs outline-hidden select-none data-inset:pl-7 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
"focus:bg-accent focus:text-accent-foreground data-open:bg-accent data-open:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-popup-open:bg-accent data-popup-open:text-accent-foreground flex cursor-default items-center gap-2 rounded-none px-2 py-2 text-xs outline-hidden select-none data-inset:pl-7 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
<IconChevronRight className="ml-auto" />
|
<IconChevronRight className="ml-auto" />
|
||||||
</MenuPrimitive.SubmenuTrigger>
|
</MenuPrimitive.SubmenuTrigger>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuSubContent({
|
function DropdownMenuSubContent({
|
||||||
@@ -137,7 +139,7 @@ function DropdownMenuSubContent({
|
|||||||
data-slot="dropdown-menu-sub-content"
|
data-slot="dropdown-menu-sub-content"
|
||||||
className={cn(
|
className={cn(
|
||||||
"data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 bg-popover text-popover-foreground w-auto min-w-[96px] rounded-none shadow-lg ring-1 duration-100",
|
"data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 bg-popover text-popover-foreground w-auto min-w-[96px] rounded-none shadow-lg ring-1 duration-100",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
align={align}
|
align={align}
|
||||||
alignOffset={alignOffset}
|
alignOffset={alignOffset}
|
||||||
@@ -145,7 +147,7 @@ function DropdownMenuSubContent({
|
|||||||
sideOffset={sideOffset}
|
sideOffset={sideOffset}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuCheckboxItem({
|
function DropdownMenuCheckboxItem({
|
||||||
@@ -155,7 +157,7 @@ function DropdownMenuCheckboxItem({
|
|||||||
inset,
|
inset,
|
||||||
...props
|
...props
|
||||||
}: MenuPrimitive.CheckboxItem.Props & {
|
}: MenuPrimitive.CheckboxItem.Props & {
|
||||||
inset?: boolean
|
inset?: boolean;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<MenuPrimitive.CheckboxItem
|
<MenuPrimitive.CheckboxItem
|
||||||
@@ -163,7 +165,7 @@ function DropdownMenuCheckboxItem({
|
|||||||
data-inset={inset}
|
data-inset={inset}
|
||||||
className={cn(
|
className={cn(
|
||||||
"focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-none py-2 pr-8 pl-2 text-xs outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 data-inset:pl-7 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
"focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-none py-2 pr-8 pl-2 text-xs outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 data-inset:pl-7 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
checked={checked}
|
checked={checked}
|
||||||
{...props}
|
{...props}
|
||||||
@@ -173,13 +175,12 @@ function DropdownMenuCheckboxItem({
|
|||||||
data-slot="dropdown-menu-checkbox-item-indicator"
|
data-slot="dropdown-menu-checkbox-item-indicator"
|
||||||
>
|
>
|
||||||
<MenuPrimitive.CheckboxItemIndicator>
|
<MenuPrimitive.CheckboxItemIndicator>
|
||||||
<IconCheck
|
<IconCheck />
|
||||||
/>
|
|
||||||
</MenuPrimitive.CheckboxItemIndicator>
|
</MenuPrimitive.CheckboxItemIndicator>
|
||||||
</span>
|
</span>
|
||||||
{children}
|
{children}
|
||||||
</MenuPrimitive.CheckboxItem>
|
</MenuPrimitive.CheckboxItem>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuRadioGroup({ ...props }: MenuPrimitive.RadioGroup.Props) {
|
function DropdownMenuRadioGroup({ ...props }: MenuPrimitive.RadioGroup.Props) {
|
||||||
@@ -188,7 +189,7 @@ function DropdownMenuRadioGroup({ ...props }: MenuPrimitive.RadioGroup.Props) {
|
|||||||
data-slot="dropdown-menu-radio-group"
|
data-slot="dropdown-menu-radio-group"
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuRadioItem({
|
function DropdownMenuRadioItem({
|
||||||
@@ -197,7 +198,7 @@ function DropdownMenuRadioItem({
|
|||||||
inset,
|
inset,
|
||||||
...props
|
...props
|
||||||
}: MenuPrimitive.RadioItem.Props & {
|
}: MenuPrimitive.RadioItem.Props & {
|
||||||
inset?: boolean
|
inset?: boolean;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<MenuPrimitive.RadioItem
|
<MenuPrimitive.RadioItem
|
||||||
@@ -205,7 +206,7 @@ function DropdownMenuRadioItem({
|
|||||||
data-inset={inset}
|
data-inset={inset}
|
||||||
className={cn(
|
className={cn(
|
||||||
"focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-none py-2 pr-8 pl-2 text-xs outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 data-inset:pl-7 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
"focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-none py-2 pr-8 pl-2 text-xs outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 data-inset:pl-7 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
@@ -214,13 +215,12 @@ function DropdownMenuRadioItem({
|
|||||||
data-slot="dropdown-menu-radio-item-indicator"
|
data-slot="dropdown-menu-radio-item-indicator"
|
||||||
>
|
>
|
||||||
<MenuPrimitive.RadioItemIndicator>
|
<MenuPrimitive.RadioItemIndicator>
|
||||||
<IconCheck
|
<IconCheck />
|
||||||
/>
|
|
||||||
</MenuPrimitive.RadioItemIndicator>
|
</MenuPrimitive.RadioItemIndicator>
|
||||||
</span>
|
</span>
|
||||||
{children}
|
{children}
|
||||||
</MenuPrimitive.RadioItem>
|
</MenuPrimitive.RadioItem>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuSeparator({
|
function DropdownMenuSeparator({
|
||||||
@@ -233,7 +233,7 @@ function DropdownMenuSeparator({
|
|||||||
className={cn("bg-border -mx-1 h-px", className)}
|
className={cn("bg-border -mx-1 h-px", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuShortcut({
|
function DropdownMenuShortcut({
|
||||||
@@ -245,11 +245,11 @@ function DropdownMenuShortcut({
|
|||||||
data-slot="dropdown-menu-shortcut"
|
data-slot="dropdown-menu-shortcut"
|
||||||
className={cn(
|
className={cn(
|
||||||
"text-muted-foreground group-focus/dropdown-menu-item:text-accent-foreground ml-auto text-xs tracking-widest",
|
"text-muted-foreground group-focus/dropdown-menu-item:text-accent-foreground ml-auto text-xs tracking-widest",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -268,4 +268,4 @@ export {
|
|||||||
DropdownMenuSub,
|
DropdownMenuSub,
|
||||||
DropdownMenuSubTrigger,
|
DropdownMenuSubTrigger,
|
||||||
DropdownMenuSubContent,
|
DropdownMenuSubContent,
|
||||||
}
|
};
|
||||||
|
|||||||
+40
-40
@@ -1,11 +1,10 @@
|
|||||||
"use client"
|
"use client";
|
||||||
|
|
||||||
import { useMemo } from "react"
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
import { cva, type VariantProps } from "class-variance-authority"
|
import { useMemo } from "react";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
import { cn } from "@/lib/utils"
|
import { Separator } from "@/components/ui/separator";
|
||||||
import { Label } from "@/components/ui/label"
|
import { cn } from "@/lib/utils";
|
||||||
import { Separator } from "@/components/ui/separator"
|
|
||||||
|
|
||||||
function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {
|
function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {
|
||||||
return (
|
return (
|
||||||
@@ -13,11 +12,11 @@ function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {
|
|||||||
data-slot="field-set"
|
data-slot="field-set"
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex flex-col gap-4 has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3",
|
"flex flex-col gap-4 has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function FieldLegend({
|
function FieldLegend({
|
||||||
@@ -31,11 +30,11 @@ function FieldLegend({
|
|||||||
data-variant={variant}
|
data-variant={variant}
|
||||||
className={cn(
|
className={cn(
|
||||||
"mb-2.5 font-medium data-[variant=label]:text-xs data-[variant=legend]:text-sm",
|
"mb-2.5 font-medium data-[variant=label]:text-xs data-[variant=legend]:text-sm",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function FieldGroup({ className, ...props }: React.ComponentProps<"div">) {
|
function FieldGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
@@ -44,11 +43,11 @@ function FieldGroup({ className, ...props }: React.ComponentProps<"div">) {
|
|||||||
data-slot="field-group"
|
data-slot="field-group"
|
||||||
className={cn(
|
className={cn(
|
||||||
"group/field-group @container/field-group flex w-full flex-col gap-5 data-[slot=checkbox-group]:gap-3 *:data-[slot=field-group]:gap-4",
|
"group/field-group @container/field-group flex w-full flex-col gap-5 data-[slot=checkbox-group]:gap-3 *:data-[slot=field-group]:gap-4",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fieldVariants = cva(
|
const fieldVariants = cva(
|
||||||
@@ -66,8 +65,8 @@ const fieldVariants = cva(
|
|||||||
defaultVariants: {
|
defaultVariants: {
|
||||||
orientation: "vertical",
|
orientation: "vertical",
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
)
|
);
|
||||||
|
|
||||||
function Field({
|
function Field({
|
||||||
className,
|
className,
|
||||||
@@ -75,6 +74,7 @@ function Field({
|
|||||||
...props
|
...props
|
||||||
}: React.ComponentProps<"div"> & VariantProps<typeof fieldVariants>) {
|
}: React.ComponentProps<"div"> & VariantProps<typeof fieldVariants>) {
|
||||||
return (
|
return (
|
||||||
|
// biome-ignore lint/a11y/useSemanticElements: shadcn component uses role="group" intentionally
|
||||||
<div
|
<div
|
||||||
role="group"
|
role="group"
|
||||||
data-slot="field"
|
data-slot="field"
|
||||||
@@ -82,7 +82,7 @@ function Field({
|
|||||||
className={cn(fieldVariants({ orientation }), className)}
|
className={cn(fieldVariants({ orientation }), className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function FieldContent({ className, ...props }: React.ComponentProps<"div">) {
|
function FieldContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
@@ -91,11 +91,11 @@ function FieldContent({ className, ...props }: React.ComponentProps<"div">) {
|
|||||||
data-slot="field-content"
|
data-slot="field-content"
|
||||||
className={cn(
|
className={cn(
|
||||||
"group/field-content flex flex-1 flex-col gap-0.5 leading-snug",
|
"group/field-content flex flex-1 flex-col gap-0.5 leading-snug",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function FieldLabel({
|
function FieldLabel({
|
||||||
@@ -108,11 +108,11 @@ function FieldLabel({
|
|||||||
className={cn(
|
className={cn(
|
||||||
"has-data-checked:bg-primary/5 has-data-checked:border-primary/30 dark:has-data-checked:border-primary/20 dark:has-data-checked:bg-primary/10 group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50 has-[>[data-slot=field]]:rounded-none has-[>[data-slot=field]]:border *:data-[slot=field]:p-2",
|
"has-data-checked:bg-primary/5 has-data-checked:border-primary/30 dark:has-data-checked:border-primary/20 dark:has-data-checked:bg-primary/10 group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50 has-[>[data-slot=field]]:rounded-none has-[>[data-slot=field]]:border *:data-[slot=field]:p-2",
|
||||||
"has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col",
|
"has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function FieldTitle({ className, ...props }: React.ComponentProps<"div">) {
|
function FieldTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
@@ -121,11 +121,11 @@ function FieldTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|||||||
data-slot="field-label"
|
data-slot="field-label"
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex w-fit items-center gap-2 text-xs/relaxed leading-snug group-data-[disabled=true]/field:opacity-50",
|
"flex w-fit items-center gap-2 text-xs/relaxed leading-snug group-data-[disabled=true]/field:opacity-50",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function FieldDescription({ className, ...props }: React.ComponentProps<"p">) {
|
function FieldDescription({ className, ...props }: React.ComponentProps<"p">) {
|
||||||
@@ -136,11 +136,11 @@ function FieldDescription({ className, ...props }: React.ComponentProps<"p">) {
|
|||||||
"text-muted-foreground text-left text-xs/relaxed leading-normal font-normal group-has-data-horizontal/field:text-balance [[data-variant=legend]+&]:-mt-1.5",
|
"text-muted-foreground text-left text-xs/relaxed leading-normal font-normal group-has-data-horizontal/field:text-balance [[data-variant=legend]+&]:-mt-1.5",
|
||||||
"last:mt-0 nth-last-2:-mt-1",
|
"last:mt-0 nth-last-2:-mt-1",
|
||||||
"[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4",
|
"[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function FieldSeparator({
|
function FieldSeparator({
|
||||||
@@ -148,7 +148,7 @@ function FieldSeparator({
|
|||||||
className,
|
className,
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<"div"> & {
|
}: React.ComponentProps<"div"> & {
|
||||||
children?: React.ReactNode
|
children?: React.ReactNode;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -156,7 +156,7 @@ function FieldSeparator({
|
|||||||
data-content={!!children}
|
data-content={!!children}
|
||||||
className={cn(
|
className={cn(
|
||||||
"relative -my-2 h-5 text-xs group-data-[variant=outline]/field-group:-mb-2",
|
"relative -my-2 h-5 text-xs group-data-[variant=outline]/field-group:-mb-2",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
@@ -170,7 +170,7 @@ function FieldSeparator({
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function FieldError({
|
function FieldError({
|
||||||
@@ -179,37 +179,37 @@ function FieldError({
|
|||||||
errors,
|
errors,
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<"div"> & {
|
}: React.ComponentProps<"div"> & {
|
||||||
errors?: Array<{ message?: string } | undefined>
|
errors?: Array<{ message?: string } | undefined>;
|
||||||
}) {
|
}) {
|
||||||
const content = useMemo(() => {
|
const content = useMemo(() => {
|
||||||
if (children) {
|
if (children) {
|
||||||
return children
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!errors?.length) {
|
if (!errors?.length) {
|
||||||
return null
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uniqueErrors = [
|
const uniqueErrors = [
|
||||||
...new Map(errors.map((error) => [error?.message, error])).values(),
|
...new Map(errors.map((error) => [error?.message, error])).values(),
|
||||||
]
|
];
|
||||||
|
|
||||||
if (uniqueErrors?.length == 1) {
|
if (uniqueErrors?.length === 1) {
|
||||||
return uniqueErrors[0]?.message
|
return uniqueErrors[0]?.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ul className="ml-4 flex list-disc flex-col gap-1">
|
<ul className="ml-4 flex list-disc flex-col gap-1">
|
||||||
{uniqueErrors.map(
|
{uniqueErrors.map(
|
||||||
(error, index) =>
|
(error) =>
|
||||||
error?.message && <li key={index}>{error.message}</li>
|
error?.message && <li key={error.message}>{error.message}</li>,
|
||||||
)}
|
)}
|
||||||
</ul>
|
</ul>
|
||||||
)
|
);
|
||||||
}, [children, errors])
|
}, [children, errors]);
|
||||||
|
|
||||||
if (!content) {
|
if (!content) {
|
||||||
return null
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -221,7 +221,7 @@ function FieldError({
|
|||||||
>
|
>
|
||||||
{content}
|
{content}
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -235,4 +235,4 @@ export {
|
|||||||
FieldSet,
|
FieldSet,
|
||||||
FieldContent,
|
FieldContent,
|
||||||
FieldTitle,
|
FieldTitle,
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
"use client"
|
"use client";
|
||||||
|
|
||||||
import * as React from "react"
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
import { cva, type VariantProps } from "class-variance-authority"
|
import type * as React from "react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
import { cn } from "@/lib/utils"
|
import { Input } from "@/components/ui/input";
|
||||||
import { Button } from "@/components/ui/button"
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
import { Input } from "@/components/ui/input"
|
import { cn } from "@/lib/utils";
|
||||||
import { Textarea } from "@/components/ui/textarea"
|
|
||||||
|
|
||||||
function InputGroup({ className, ...props }: React.ComponentProps<"div">) {
|
function InputGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
return (
|
return (
|
||||||
|
// biome-ignore lint/a11y/useSemanticElements: shadcn component uses role="group" intentionally
|
||||||
<div
|
<div
|
||||||
data-slot="input-group"
|
data-slot="input-group"
|
||||||
role="group"
|
role="group"
|
||||||
className={cn(
|
className={cn(
|
||||||
"border-input dark:bg-input/30 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[[data-slot][aria-invalid=true]]:border-destructive dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-disabled:bg-input/50 dark:has-disabled:bg-input/80 group/input-group relative flex h-8 w-full min-w-0 items-center rounded-none border transition-colors outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-disabled:opacity-50 has-[[data-slot=input-group-control]:focus-visible]:ring-1 has-[[data-slot][aria-invalid=true]]:ring-1 has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5",
|
"border-input dark:bg-input/30 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[[data-slot][aria-invalid=true]]:border-destructive dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-disabled:bg-input/50 dark:has-disabled:bg-input/80 group/input-group relative flex h-8 w-full min-w-0 items-center rounded-none border transition-colors outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-disabled:opacity-50 has-[[data-slot=input-group-control]:focus-visible]:ring-1 has-[[data-slot][aria-invalid=true]]:ring-1 has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const inputGroupAddonVariants = cva(
|
const inputGroupAddonVariants = cva(
|
||||||
@@ -40,8 +40,8 @@ const inputGroupAddonVariants = cva(
|
|||||||
defaultVariants: {
|
defaultVariants: {
|
||||||
align: "inline-start",
|
align: "inline-start",
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
)
|
);
|
||||||
|
|
||||||
function InputGroupAddon({
|
function InputGroupAddon({
|
||||||
className,
|
className,
|
||||||
@@ -49,6 +49,8 @@ function InputGroupAddon({
|
|||||||
...props
|
...props
|
||||||
}: React.ComponentProps<"div"> & VariantProps<typeof inputGroupAddonVariants>) {
|
}: React.ComponentProps<"div"> & VariantProps<typeof inputGroupAddonVariants>) {
|
||||||
return (
|
return (
|
||||||
|
// biome-ignore lint/a11y/useSemanticElements: shadcn component uses role="group" intentionally
|
||||||
|
// biome-ignore lint/a11y/useKeyWithClickEvents: click focuses input, keyboard users use tab
|
||||||
<div
|
<div
|
||||||
role="group"
|
role="group"
|
||||||
data-slot="input-group-addon"
|
data-slot="input-group-addon"
|
||||||
@@ -56,13 +58,13 @@ function InputGroupAddon({
|
|||||||
className={cn(inputGroupAddonVariants({ align }), className)}
|
className={cn(inputGroupAddonVariants({ align }), className)}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
if ((e.target as HTMLElement).closest("button")) {
|
if ((e.target as HTMLElement).closest("button")) {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
e.currentTarget.parentElement?.querySelector("input")?.focus()
|
e.currentTarget.parentElement?.querySelector("input")?.focus();
|
||||||
}}
|
}}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const inputGroupButtonVariants = cva(
|
const inputGroupButtonVariants = cva(
|
||||||
@@ -79,8 +81,8 @@ const inputGroupButtonVariants = cva(
|
|||||||
defaultVariants: {
|
defaultVariants: {
|
||||||
size: "xs",
|
size: "xs",
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
)
|
);
|
||||||
|
|
||||||
function InputGroupButton({
|
function InputGroupButton({
|
||||||
className,
|
className,
|
||||||
@@ -90,7 +92,7 @@ function InputGroupButton({
|
|||||||
...props
|
...props
|
||||||
}: Omit<React.ComponentProps<typeof Button>, "size" | "type"> &
|
}: Omit<React.ComponentProps<typeof Button>, "size" | "type"> &
|
||||||
VariantProps<typeof inputGroupButtonVariants> & {
|
VariantProps<typeof inputGroupButtonVariants> & {
|
||||||
type?: "button" | "submit" | "reset"
|
type?: "button" | "submit" | "reset";
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
@@ -100,7 +102,7 @@ function InputGroupButton({
|
|||||||
className={cn(inputGroupButtonVariants({ size }), className)}
|
className={cn(inputGroupButtonVariants({ size }), className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function InputGroupText({ className, ...props }: React.ComponentProps<"span">) {
|
function InputGroupText({ className, ...props }: React.ComponentProps<"span">) {
|
||||||
@@ -108,11 +110,11 @@ function InputGroupText({ className, ...props }: React.ComponentProps<"span">) {
|
|||||||
<span
|
<span
|
||||||
className={cn(
|
className={cn(
|
||||||
"text-muted-foreground flex items-center gap-2 text-xs [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
|
"text-muted-foreground flex items-center gap-2 text-xs [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function InputGroupInput({
|
function InputGroupInput({
|
||||||
@@ -124,11 +126,11 @@ function InputGroupInput({
|
|||||||
data-slot="input-group-control"
|
data-slot="input-group-control"
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex-1 rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:ring-0 disabled:bg-transparent aria-invalid:ring-0 dark:bg-transparent dark:disabled:bg-transparent",
|
"flex-1 rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:ring-0 disabled:bg-transparent aria-invalid:ring-0 dark:bg-transparent dark:disabled:bg-transparent",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function InputGroupTextarea({
|
function InputGroupTextarea({
|
||||||
@@ -140,11 +142,11 @@ function InputGroupTextarea({
|
|||||||
data-slot="input-group-control"
|
data-slot="input-group-control"
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex-1 resize-none rounded-none border-0 bg-transparent py-2 shadow-none ring-0 focus-visible:ring-0 disabled:bg-transparent aria-invalid:ring-0 dark:bg-transparent dark:disabled:bg-transparent",
|
"flex-1 resize-none rounded-none border-0 bg-transparent py-2 shadow-none ring-0 focus-visible:ring-0 disabled:bg-transparent aria-invalid:ring-0 dark:bg-transparent dark:disabled:bg-transparent",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -154,4 +156,4 @@ export {
|
|||||||
InputGroupText,
|
InputGroupText,
|
||||||
InputGroupInput,
|
InputGroupInput,
|
||||||
InputGroupTextarea,
|
InputGroupTextarea,
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as React from "react"
|
import { Input as InputPrimitive } from "@base-ui/react/input";
|
||||||
import { Input as InputPrimitive } from "@base-ui/react/input"
|
import type * as React from "react";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||||
return (
|
return (
|
||||||
@@ -10,11 +10,11 @@ function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
|||||||
data-slot="input"
|
data-slot="input"
|
||||||
className={cn(
|
className={cn(
|
||||||
"dark:bg-input/30 border-input focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 disabled:bg-input/50 dark:disabled:bg-input/80 file:text-foreground placeholder:text-muted-foreground h-8 w-full min-w-0 rounded-none border bg-transparent px-2.5 py-1 text-xs transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-xs file:font-medium focus-visible:ring-1 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-1 md:text-xs",
|
"dark:bg-input/30 border-input focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 disabled:bg-input/50 dark:disabled:bg-input/80 file:text-foreground placeholder:text-muted-foreground h-8 w-full min-w-0 rounded-none border bg-transparent px-2.5 py-1 text-xs transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-xs file:font-medium focus-visible:ring-1 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-1 md:text-xs",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Input }
|
export { Input };
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
"use client"
|
"use client";
|
||||||
|
|
||||||
import * as React from "react"
|
import type * as React from "react";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
function Label({ className, ...props }: React.ComponentProps<"label">) {
|
function Label({ className, ...props }: React.ComponentProps<"label">) {
|
||||||
return (
|
return (
|
||||||
|
// biome-ignore lint/a11y/noLabelWithoutControl: generic label component, control association handled by consumer
|
||||||
<label
|
<label
|
||||||
data-slot="label"
|
data-slot="label"
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex items-center gap-2 text-xs leading-none select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
"flex items-center gap-2 text-xs leading-none select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Label }
|
export { Label };
|
||||||
|
|||||||
+32
-27
@@ -1,12 +1,16 @@
|
|||||||
"use client"
|
"use client";
|
||||||
|
|
||||||
import * as React from "react"
|
import { Select as SelectPrimitive } from "@base-ui/react/select";
|
||||||
import { Select as SelectPrimitive } from "@base-ui/react/select"
|
import {
|
||||||
|
IconCheck,
|
||||||
|
IconChevronDown,
|
||||||
|
IconChevronUp,
|
||||||
|
IconSelector,
|
||||||
|
} from "@tabler/icons-react";
|
||||||
|
import type * as React from "react";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
const Select = SelectPrimitive.Root;
|
||||||
import { IconSelector, IconCheck, IconChevronUp, IconChevronDown } from "@tabler/icons-react"
|
|
||||||
|
|
||||||
const Select = SelectPrimitive.Root
|
|
||||||
|
|
||||||
function SelectGroup({ className, ...props }: SelectPrimitive.Group.Props) {
|
function SelectGroup({ className, ...props }: SelectPrimitive.Group.Props) {
|
||||||
return (
|
return (
|
||||||
@@ -15,7 +19,7 @@ function SelectGroup({ className, ...props }: SelectPrimitive.Group.Props) {
|
|||||||
className={cn("scroll-my-1", className)}
|
className={cn("scroll-my-1", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function SelectValue({ className, ...props }: SelectPrimitive.Value.Props) {
|
function SelectValue({ className, ...props }: SelectPrimitive.Value.Props) {
|
||||||
@@ -25,7 +29,7 @@ function SelectValue({ className, ...props }: SelectPrimitive.Value.Props) {
|
|||||||
className={cn("flex flex-1 text-left", className)}
|
className={cn("flex flex-1 text-left", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function SelectTrigger({
|
function SelectTrigger({
|
||||||
@@ -34,7 +38,7 @@ function SelectTrigger({
|
|||||||
children,
|
children,
|
||||||
...props
|
...props
|
||||||
}: SelectPrimitive.Trigger.Props & {
|
}: SelectPrimitive.Trigger.Props & {
|
||||||
size?: "sm" | "default"
|
size?: "sm" | "default";
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<SelectPrimitive.Trigger
|
<SelectPrimitive.Trigger
|
||||||
@@ -42,7 +46,7 @@ function SelectTrigger({
|
|||||||
data-size={size}
|
data-size={size}
|
||||||
className={cn(
|
className={cn(
|
||||||
"border-input data-placeholder:text-muted-foreground dark:bg-input/30 dark:hover:bg-input/50 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 flex w-fit items-center justify-between gap-1.5 rounded-none border bg-transparent py-2 pr-2 pl-2.5 text-xs whitespace-nowrap transition-colors outline-none select-none focus-visible:ring-1 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-1 data-[size=default]:h-8 data-[size=sm]:h-7 data-[size=sm]:rounded-none *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
"border-input data-placeholder:text-muted-foreground dark:bg-input/30 dark:hover:bg-input/50 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 flex w-fit items-center justify-between gap-1.5 rounded-none border bg-transparent py-2 pr-2 pl-2.5 text-xs whitespace-nowrap transition-colors outline-none select-none focus-visible:ring-1 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-1 data-[size=default]:h-8 data-[size=sm]:h-7 data-[size=sm]:rounded-none *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
@@ -53,7 +57,7 @@ function SelectTrigger({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</SelectPrimitive.Trigger>
|
</SelectPrimitive.Trigger>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function SelectContent({
|
function SelectContent({
|
||||||
@@ -83,7 +87,10 @@ function SelectContent({
|
|||||||
<SelectPrimitive.Popup
|
<SelectPrimitive.Popup
|
||||||
data-slot="select-content"
|
data-slot="select-content"
|
||||||
data-align-trigger={alignItemWithTrigger}
|
data-align-trigger={alignItemWithTrigger}
|
||||||
className={cn("bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 data-[side=inline-start]:slide-in-from-right-2 data-[side=inline-end]:slide-in-from-left-2 relative isolate z-50 max-h-(--available-height) w-(--anchor-width) min-w-36 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-none shadow-md ring-1 duration-100 data-[align-trigger=true]:animate-none", className )}
|
className={cn(
|
||||||
|
"bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 data-[side=inline-start]:slide-in-from-right-2 data-[side=inline-end]:slide-in-from-left-2 relative isolate z-50 max-h-(--available-height) w-(--anchor-width) min-w-36 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-none shadow-md ring-1 duration-100 data-[align-trigger=true]:animate-none",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<SelectScrollUpButton />
|
<SelectScrollUpButton />
|
||||||
@@ -92,7 +99,7 @@ function SelectContent({
|
|||||||
</SelectPrimitive.Popup>
|
</SelectPrimitive.Popup>
|
||||||
</SelectPrimitive.Positioner>
|
</SelectPrimitive.Positioner>
|
||||||
</SelectPrimitive.Portal>
|
</SelectPrimitive.Portal>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function SelectLabel({
|
function SelectLabel({
|
||||||
@@ -105,7 +112,7 @@ function SelectLabel({
|
|||||||
className={cn("text-muted-foreground px-2 py-2 text-xs", className)}
|
className={cn("text-muted-foreground px-2 py-2 text-xs", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function SelectItem({
|
function SelectItem({
|
||||||
@@ -118,7 +125,7 @@ function SelectItem({
|
|||||||
data-slot="select-item"
|
data-slot="select-item"
|
||||||
className={cn(
|
className={cn(
|
||||||
"focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground relative flex w-full cursor-default items-center gap-2 rounded-none py-2 pr-8 pl-2 text-xs outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
"focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground relative flex w-full cursor-default items-center gap-2 rounded-none py-2 pr-8 pl-2 text-xs outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
@@ -133,7 +140,7 @@ function SelectItem({
|
|||||||
<IconCheck className="pointer-events-none" />
|
<IconCheck className="pointer-events-none" />
|
||||||
</SelectPrimitive.ItemIndicator>
|
</SelectPrimitive.ItemIndicator>
|
||||||
</SelectPrimitive.Item>
|
</SelectPrimitive.Item>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function SelectSeparator({
|
function SelectSeparator({
|
||||||
@@ -146,7 +153,7 @@ function SelectSeparator({
|
|||||||
className={cn("bg-border pointer-events-none -mx-1 h-px", className)}
|
className={cn("bg-border pointer-events-none -mx-1 h-px", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function SelectScrollUpButton({
|
function SelectScrollUpButton({
|
||||||
@@ -158,14 +165,13 @@ function SelectScrollUpButton({
|
|||||||
data-slot="select-scroll-up-button"
|
data-slot="select-scroll-up-button"
|
||||||
className={cn(
|
className={cn(
|
||||||
"bg-popover top-0 z-10 flex w-full cursor-default items-center justify-center py-1 [&_svg:not([class*='size-'])]:size-4",
|
"bg-popover top-0 z-10 flex w-full cursor-default items-center justify-center py-1 [&_svg:not([class*='size-'])]:size-4",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<IconChevronUp
|
<IconChevronUp />
|
||||||
/>
|
|
||||||
</SelectPrimitive.ScrollUpArrow>
|
</SelectPrimitive.ScrollUpArrow>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function SelectScrollDownButton({
|
function SelectScrollDownButton({
|
||||||
@@ -177,14 +183,13 @@ function SelectScrollDownButton({
|
|||||||
data-slot="select-scroll-down-button"
|
data-slot="select-scroll-down-button"
|
||||||
className={cn(
|
className={cn(
|
||||||
"bg-popover bottom-0 z-10 flex w-full cursor-default items-center justify-center py-1 [&_svg:not([class*='size-'])]:size-4",
|
"bg-popover bottom-0 z-10 flex w-full cursor-default items-center justify-center py-1 [&_svg:not([class*='size-'])]:size-4",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<IconChevronDown
|
<IconChevronDown />
|
||||||
/>
|
|
||||||
</SelectPrimitive.ScrollDownArrow>
|
</SelectPrimitive.ScrollDownArrow>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -198,4 +203,4 @@ export {
|
|||||||
SelectSeparator,
|
SelectSeparator,
|
||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
"use client"
|
"use client";
|
||||||
|
|
||||||
import { Separator as SeparatorPrimitive } from "@base-ui/react/separator"
|
import { Separator as SeparatorPrimitive } from "@base-ui/react/separator";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
function Separator({
|
function Separator({
|
||||||
className,
|
className,
|
||||||
@@ -15,11 +15,11 @@ function Separator({
|
|||||||
orientation={orientation}
|
orientation={orientation}
|
||||||
className={cn(
|
className={cn(
|
||||||
"bg-border shrink-0 data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch",
|
"bg-border shrink-0 data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Separator }
|
export { Separator };
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import * as React from "react"
|
import type * as React from "react";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
||||||
return (
|
return (
|
||||||
@@ -8,11 +8,11 @@ function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
|||||||
data-slot="textarea"
|
data-slot="textarea"
|
||||||
className={cn(
|
className={cn(
|
||||||
"border-input dark:bg-input/30 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 disabled:bg-input/50 dark:disabled:bg-input/80 placeholder:text-muted-foreground flex field-sizing-content min-h-16 w-full rounded-none border bg-transparent px-2.5 py-2 text-xs transition-colors outline-none focus-visible:ring-1 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-1 md:text-xs",
|
"border-input dark:bg-input/30 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 disabled:bg-input/50 dark:disabled:bg-input/80 placeholder:text-muted-foreground flex field-sizing-content min-h-16 w-full rounded-none border bg-transparent px-2.5 py-2 text-xs transition-colors outline-none focus-visible:ring-1 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-1 md:text-xs",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Textarea }
|
export { Textarea };
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { defineConfig } from "drizzle-kit";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
dialect: "sqlite",
|
||||||
|
schema: "./lib/db/schema.ts",
|
||||||
|
out: "./drizzle",
|
||||||
|
dbCredentials: {
|
||||||
|
url: process.env.DATABASE_URL ?? "sqlite.db",
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
export async function onRequestError() {
|
||||||
|
// Required by Next.js instrumentation
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function register() {
|
||||||
|
if (
|
||||||
|
process.env.NEXT_RUNTIME === "nodejs" &&
|
||||||
|
process.env.NODE_ENV === "production"
|
||||||
|
) {
|
||||||
|
const { initJobs } = await import("@/lib/jobs/init");
|
||||||
|
initJobs();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { headers } from "next/headers";
|
||||||
|
import { auth } from "@/lib/auth/server";
|
||||||
|
|
||||||
|
export async function getSession() {
|
||||||
|
return auth.api.getSession({
|
||||||
|
headers: await headers(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function requireAuth(): Promise<string> {
|
||||||
|
const session = await getSession();
|
||||||
|
if (!session?.user?.id) {
|
||||||
|
throw new AuthError();
|
||||||
|
}
|
||||||
|
return session.user.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class AuthError extends Error {
|
||||||
|
constructor() {
|
||||||
|
super("Unauthorized");
|
||||||
|
this.name = "AuthError";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
export function apiError(message: string, status: number) {
|
||||||
|
return NextResponse.json({ error: message }, { status });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function unauthorized(message = "Unauthorized") {
|
||||||
|
return apiError(message, 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function badRequest(message = "Bad request") {
|
||||||
|
return apiError(message, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function notFound(message = "Not found") {
|
||||||
|
return apiError(message, 404);
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { createAuthClient } from "better-auth/react";
|
||||||
|
|
||||||
|
export const authClient = createAuthClient();
|
||||||
|
|
||||||
|
export const { signIn, signUp, signOut, useSession } = authClient;
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { betterAuth } from "better-auth";
|
||||||
|
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
||||||
|
import { v4 as uuid } from "uuid";
|
||||||
|
import { db } from "@/lib/db/client";
|
||||||
|
|
||||||
|
export const auth = betterAuth({
|
||||||
|
database: drizzleAdapter(db, {
|
||||||
|
provider: "sqlite",
|
||||||
|
}),
|
||||||
|
emailAndPassword: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
advanced: {
|
||||||
|
database: {
|
||||||
|
generateId: () => uuid(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import Database from "better-sqlite3";
|
||||||
|
import { drizzle } from "drizzle-orm/better-sqlite3";
|
||||||
|
import * as schema from "./schema";
|
||||||
|
|
||||||
|
const globalForDb = globalThis as unknown as {
|
||||||
|
_db: ReturnType<typeof drizzle> | undefined;
|
||||||
|
_sqlite: Database.Database | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!globalForDb._sqlite) {
|
||||||
|
globalForDb._sqlite = new Database(process.env.DATABASE_URL ?? "sqlite.db");
|
||||||
|
globalForDb._sqlite.pragma("journal_mode = WAL");
|
||||||
|
globalForDb._sqlite.pragma("foreign_keys = ON");
|
||||||
|
globalForDb._sqlite.pragma("busy_timeout = 5000");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!globalForDb._db) {
|
||||||
|
globalForDb._db = drizzle(globalForDb._sqlite, { schema });
|
||||||
|
}
|
||||||
|
|
||||||
|
export const db = globalForDb._db;
|
||||||
|
export const sqlite = globalForDb._sqlite;
|
||||||
@@ -0,0 +1,279 @@
|
|||||||
|
import {
|
||||||
|
index,
|
||||||
|
int,
|
||||||
|
real,
|
||||||
|
sqliteTable,
|
||||||
|
text,
|
||||||
|
uniqueIndex,
|
||||||
|
} from "drizzle-orm/sqlite-core";
|
||||||
|
import { v4 as uuid } from "uuid";
|
||||||
|
|
||||||
|
// Helper for UUID primary keys
|
||||||
|
const uuidPk = () =>
|
||||||
|
text("id")
|
||||||
|
.primaryKey()
|
||||||
|
.$defaultFn(() => uuid());
|
||||||
|
|
||||||
|
// ─── Better Auth tables ──────────────────────────────────────────────
|
||||||
|
|
||||||
|
export const user = sqliteTable("user", {
|
||||||
|
id: text("id").primaryKey(),
|
||||||
|
name: text("name").notNull(),
|
||||||
|
email: text("email").notNull().unique(),
|
||||||
|
emailVerified: int("emailVerified", { mode: "boolean" })
|
||||||
|
.notNull()
|
||||||
|
.default(false),
|
||||||
|
image: text("image"),
|
||||||
|
createdAt: int("createdAt", { mode: "timestamp" }).notNull(),
|
||||||
|
updatedAt: int("updatedAt", { mode: "timestamp" }).notNull(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const session = sqliteTable("session", {
|
||||||
|
id: text("id").primaryKey(),
|
||||||
|
userId: text("userId")
|
||||||
|
.notNull()
|
||||||
|
.references(() => user.id, { onDelete: "cascade" }),
|
||||||
|
token: text("token").notNull().unique(),
|
||||||
|
expiresAt: int("expiresAt", { mode: "timestamp" }).notNull(),
|
||||||
|
ipAddress: text("ipAddress"),
|
||||||
|
userAgent: text("userAgent"),
|
||||||
|
createdAt: int("createdAt", { mode: "timestamp" }).notNull(),
|
||||||
|
updatedAt: int("updatedAt", { mode: "timestamp" }).notNull(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const account = sqliteTable("account", {
|
||||||
|
id: text("id").primaryKey(),
|
||||||
|
userId: text("userId")
|
||||||
|
.notNull()
|
||||||
|
.references(() => user.id, { onDelete: "cascade" }),
|
||||||
|
accountId: text("accountId").notNull(),
|
||||||
|
providerId: text("providerId").notNull(),
|
||||||
|
accessToken: text("accessToken"),
|
||||||
|
refreshToken: text("refreshToken"),
|
||||||
|
accessTokenExpiresAt: int("accessTokenExpiresAt", { mode: "timestamp" }),
|
||||||
|
refreshTokenExpiresAt: int("refreshTokenExpiresAt", { mode: "timestamp" }),
|
||||||
|
scope: text("scope"),
|
||||||
|
password: text("password"),
|
||||||
|
createdAt: int("createdAt", { mode: "timestamp" }).notNull(),
|
||||||
|
updatedAt: int("updatedAt", { mode: "timestamp" }).notNull(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const verification = sqliteTable("verification", {
|
||||||
|
id: text("id").primaryKey(),
|
||||||
|
identifier: text("identifier").notNull(),
|
||||||
|
value: text("value").notNull(),
|
||||||
|
expiresAt: int("expiresAt", { mode: "timestamp" }).notNull(),
|
||||||
|
createdAt: int("createdAt", { mode: "timestamp" }),
|
||||||
|
updatedAt: int("updatedAt", { mode: "timestamp" }),
|
||||||
|
});
|
||||||
|
|
||||||
|
// ─── App tables ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export const titles = sqliteTable(
|
||||||
|
"titles",
|
||||||
|
{
|
||||||
|
id: uuidPk(),
|
||||||
|
tmdbId: int("tmdbId").notNull(),
|
||||||
|
type: text("type", { enum: ["movie", "tv"] }).notNull(),
|
||||||
|
title: text("title").notNull(),
|
||||||
|
originalTitle: text("originalTitle"),
|
||||||
|
overview: text("overview"),
|
||||||
|
releaseDate: text("releaseDate"),
|
||||||
|
firstAirDate: text("firstAirDate"),
|
||||||
|
posterPath: text("posterPath"),
|
||||||
|
backdropPath: text("backdropPath"),
|
||||||
|
popularity: real("popularity"),
|
||||||
|
voteAverage: real("voteAverage"),
|
||||||
|
voteCount: int("voteCount"),
|
||||||
|
status: text("status"),
|
||||||
|
lastFetchedAt: int("lastFetchedAt", { mode: "timestamp" }),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
uniqueIndex("titles_tmdbId_unique").on(table.tmdbId),
|
||||||
|
index("titles_type_releaseDate").on(table.type, table.releaseDate),
|
||||||
|
index("titles_type_firstAirDate").on(table.type, table.firstAirDate),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
export const seasons = sqliteTable(
|
||||||
|
"seasons",
|
||||||
|
{
|
||||||
|
id: uuidPk(),
|
||||||
|
titleId: text("titleId")
|
||||||
|
.notNull()
|
||||||
|
.references(() => titles.id, { onDelete: "cascade" }),
|
||||||
|
seasonNumber: int("seasonNumber").notNull(),
|
||||||
|
name: text("name"),
|
||||||
|
overview: text("overview"),
|
||||||
|
posterPath: text("posterPath"),
|
||||||
|
airDate: text("airDate"),
|
||||||
|
lastFetchedAt: int("lastFetchedAt", { mode: "timestamp" }),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
uniqueIndex("seasons_titleId_seasonNumber").on(
|
||||||
|
table.titleId,
|
||||||
|
table.seasonNumber,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
export const episodes = sqliteTable(
|
||||||
|
"episodes",
|
||||||
|
{
|
||||||
|
id: uuidPk(),
|
||||||
|
seasonId: text("seasonId")
|
||||||
|
.notNull()
|
||||||
|
.references(() => seasons.id, { onDelete: "cascade" }),
|
||||||
|
episodeNumber: int("episodeNumber").notNull(),
|
||||||
|
name: text("name"),
|
||||||
|
overview: text("overview"),
|
||||||
|
stillPath: text("stillPath"),
|
||||||
|
airDate: text("airDate"),
|
||||||
|
runtimeMinutes: int("runtimeMinutes"),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
uniqueIndex("episodes_seasonId_episodeNumber").on(
|
||||||
|
table.seasonId,
|
||||||
|
table.episodeNumber,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
export const userTitleStatus = sqliteTable(
|
||||||
|
"userTitleStatus",
|
||||||
|
{
|
||||||
|
userId: text("userId")
|
||||||
|
.notNull()
|
||||||
|
.references(() => user.id, { onDelete: "cascade" }),
|
||||||
|
titleId: text("titleId")
|
||||||
|
.notNull()
|
||||||
|
.references(() => titles.id, { onDelete: "cascade" }),
|
||||||
|
status: text("status", {
|
||||||
|
enum: ["watchlist", "in_progress", "completed"],
|
||||||
|
}).notNull(),
|
||||||
|
addedAt: int("addedAt", { mode: "timestamp" }).notNull(),
|
||||||
|
updatedAt: int("updatedAt", { mode: "timestamp" }).notNull(),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
uniqueIndex("userTitleStatus_userId_titleId").on(
|
||||||
|
table.userId,
|
||||||
|
table.titleId,
|
||||||
|
),
|
||||||
|
index("userTitleStatus_userId_status").on(table.userId, table.status),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
export const userMovieWatches = sqliteTable(
|
||||||
|
"userMovieWatches",
|
||||||
|
{
|
||||||
|
id: uuidPk(),
|
||||||
|
userId: text("userId")
|
||||||
|
.notNull()
|
||||||
|
.references(() => user.id, { onDelete: "cascade" }),
|
||||||
|
titleId: text("titleId")
|
||||||
|
.notNull()
|
||||||
|
.references(() => titles.id, { onDelete: "cascade" }),
|
||||||
|
watchedAt: int("watchedAt", { mode: "timestamp" }).notNull(),
|
||||||
|
source: text("source", { enum: ["manual", "import"] })
|
||||||
|
.notNull()
|
||||||
|
.default("manual"),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
index("userMovieWatches_userId_watchedAt").on(
|
||||||
|
table.userId,
|
||||||
|
table.watchedAt,
|
||||||
|
),
|
||||||
|
index("userMovieWatches_titleId").on(table.titleId),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
export const userEpisodeWatches = sqliteTable(
|
||||||
|
"userEpisodeWatches",
|
||||||
|
{
|
||||||
|
id: uuidPk(),
|
||||||
|
userId: text("userId")
|
||||||
|
.notNull()
|
||||||
|
.references(() => user.id, { onDelete: "cascade" }),
|
||||||
|
episodeId: text("episodeId")
|
||||||
|
.notNull()
|
||||||
|
.references(() => episodes.id, { onDelete: "cascade" }),
|
||||||
|
watchedAt: int("watchedAt", { mode: "timestamp" }).notNull(),
|
||||||
|
source: text("source", { enum: ["manual", "import"] })
|
||||||
|
.notNull()
|
||||||
|
.default("manual"),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
index("userEpisodeWatches_userId_watchedAt").on(
|
||||||
|
table.userId,
|
||||||
|
table.watchedAt,
|
||||||
|
),
|
||||||
|
index("userEpisodeWatches_episodeId").on(table.episodeId),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
export const userRatings = sqliteTable(
|
||||||
|
"userRatings",
|
||||||
|
{
|
||||||
|
userId: text("userId")
|
||||||
|
.notNull()
|
||||||
|
.references(() => user.id, { onDelete: "cascade" }),
|
||||||
|
titleId: text("titleId")
|
||||||
|
.notNull()
|
||||||
|
.references(() => titles.id, { onDelete: "cascade" }),
|
||||||
|
ratingStars: int("ratingStars").notNull(),
|
||||||
|
ratedAt: int("ratedAt", { mode: "timestamp" }).notNull(),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
uniqueIndex("userRatings_userId_titleId").on(table.userId, table.titleId),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
export const availabilityOffers = sqliteTable(
|
||||||
|
"availabilityOffers",
|
||||||
|
{
|
||||||
|
titleId: text("titleId")
|
||||||
|
.notNull()
|
||||||
|
.references(() => titles.id, { onDelete: "cascade" }),
|
||||||
|
region: text("region").notNull().default("US"),
|
||||||
|
providerId: int("providerId").notNull(),
|
||||||
|
providerName: text("providerName").notNull(),
|
||||||
|
logoPath: text("logoPath"),
|
||||||
|
offerType: text("offerType", {
|
||||||
|
enum: ["flatrate", "rent", "buy", "free", "ads"],
|
||||||
|
}).notNull(),
|
||||||
|
link: text("link"),
|
||||||
|
lastFetchedAt: int("lastFetchedAt", { mode: "timestamp" }),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
uniqueIndex("availabilityOffers_unique").on(
|
||||||
|
table.titleId,
|
||||||
|
table.region,
|
||||||
|
table.providerId,
|
||||||
|
table.offerType,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
export const titleRecommendations = sqliteTable(
|
||||||
|
"titleRecommendations",
|
||||||
|
{
|
||||||
|
titleId: text("titleId")
|
||||||
|
.notNull()
|
||||||
|
.references(() => titles.id, { onDelete: "cascade" }),
|
||||||
|
recommendedTitleId: text("recommendedTitleId")
|
||||||
|
.notNull()
|
||||||
|
.references(() => titles.id, { onDelete: "cascade" }),
|
||||||
|
source: text("source", {
|
||||||
|
enum: ["tmdb_similar", "tmdb_recommendations"],
|
||||||
|
}).notNull(),
|
||||||
|
rank: int("rank").notNull(),
|
||||||
|
lastFetchedAt: int("lastFetchedAt", { mode: "timestamp" }),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
uniqueIndex("titleRecommendations_unique").on(
|
||||||
|
table.titleId,
|
||||||
|
table.recommendedTitleId,
|
||||||
|
table.source,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { registerJobs } from "./registry";
|
||||||
|
import { scheduler } from "./scheduler";
|
||||||
|
|
||||||
|
export function initJobs() {
|
||||||
|
registerJobs();
|
||||||
|
scheduler.start();
|
||||||
|
}
|
||||||
@@ -0,0 +1,163 @@
|
|||||||
|
import { and, eq, isNotNull, lt, or } from "drizzle-orm";
|
||||||
|
import { db } from "@/lib/db/client";
|
||||||
|
import {
|
||||||
|
availabilityOffers,
|
||||||
|
seasons,
|
||||||
|
titles,
|
||||||
|
userTitleStatus,
|
||||||
|
} from "@/lib/db/schema";
|
||||||
|
import { refreshAvailability } from "@/lib/services/availability";
|
||||||
|
import {
|
||||||
|
refreshRecommendations,
|
||||||
|
refreshTitle,
|
||||||
|
refreshTvChildren,
|
||||||
|
} from "@/lib/services/metadata";
|
||||||
|
import { getTvDetails } from "@/lib/tmdb/client";
|
||||||
|
import { scheduler } from "./scheduler";
|
||||||
|
|
||||||
|
const HOUR = 60 * 60 * 1000;
|
||||||
|
const DAY = 24 * HOUR;
|
||||||
|
const RATE_LIMIT_MS = 300;
|
||||||
|
|
||||||
|
function delay(ms: number) {
|
||||||
|
return new Promise((r) => setTimeout(r, ms));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getLibraryTitleIds(): string[] {
|
||||||
|
return db
|
||||||
|
.select({ titleId: userTitleStatus.titleId })
|
||||||
|
.from(userTitleStatus)
|
||||||
|
.groupBy(userTitleStatus.titleId)
|
||||||
|
.all()
|
||||||
|
.map((r) => r.titleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refresh titles where lastFetchedAt is stale
|
||||||
|
async function nightlyRefreshLibrary() {
|
||||||
|
const libraryIds = getLibraryTitleIds();
|
||||||
|
const libraryStale = new Date(Date.now() - 7 * DAY);
|
||||||
|
const nonLibraryStale = new Date(Date.now() - 30 * DAY);
|
||||||
|
|
||||||
|
// Library titles: 7 days
|
||||||
|
for (const titleId of libraryIds) {
|
||||||
|
const t = db
|
||||||
|
.select()
|
||||||
|
.from(titles)
|
||||||
|
.where(
|
||||||
|
and(eq(titles.id, titleId), lt(titles.lastFetchedAt, libraryStale)),
|
||||||
|
)
|
||||||
|
.get();
|
||||||
|
if (t) {
|
||||||
|
await refreshTitle(titleId);
|
||||||
|
await delay(RATE_LIMIT_MS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Non-library titles: 30 days
|
||||||
|
const nonLibrary = db
|
||||||
|
.select()
|
||||||
|
.from(titles)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
isNotNull(titles.lastFetchedAt),
|
||||||
|
lt(titles.lastFetchedAt, nonLibraryStale),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.limit(50)
|
||||||
|
.all();
|
||||||
|
|
||||||
|
for (const t of nonLibrary) {
|
||||||
|
if (!libraryIds.includes(t.id)) {
|
||||||
|
await refreshTitle(t.id);
|
||||||
|
await delay(RATE_LIMIT_MS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refresh availability for library titles where stale
|
||||||
|
async function refreshAvailabilityJob() {
|
||||||
|
const libraryIds = getLibraryTitleIds();
|
||||||
|
const stale = new Date(Date.now() - DAY);
|
||||||
|
|
||||||
|
for (const titleId of libraryIds) {
|
||||||
|
// Check if any offer is stale
|
||||||
|
const offer = db
|
||||||
|
.select()
|
||||||
|
.from(availabilityOffers)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(availabilityOffers.titleId, titleId),
|
||||||
|
lt(availabilityOffers.lastFetchedAt, stale),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
// Also handle titles with no offers yet
|
||||||
|
const anyOffer = db
|
||||||
|
.select()
|
||||||
|
.from(availabilityOffers)
|
||||||
|
.where(eq(availabilityOffers.titleId, titleId))
|
||||||
|
.get();
|
||||||
|
|
||||||
|
if (offer || !anyOffer) {
|
||||||
|
await refreshAvailability(titleId);
|
||||||
|
await delay(RATE_LIMIT_MS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refresh recommendations for recently active titles
|
||||||
|
async function refreshRecommendationsJob() {
|
||||||
|
const libraryIds = getLibraryTitleIds();
|
||||||
|
|
||||||
|
for (const titleId of libraryIds) {
|
||||||
|
await refreshRecommendations(titleId);
|
||||||
|
await delay(RATE_LIMIT_MS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refresh TV episodes for returning shows
|
||||||
|
async function refreshTvChildrenJob() {
|
||||||
|
const returningStatuses = ["Returning Series", "In Production"];
|
||||||
|
const stale = new Date(Date.now() - 7 * DAY);
|
||||||
|
|
||||||
|
const tvShows = db
|
||||||
|
.select()
|
||||||
|
.from(titles)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(titles.type, "tv"),
|
||||||
|
isNotNull(titles.lastFetchedAt),
|
||||||
|
or(...returningStatuses.map((s) => eq(titles.status, s))),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.all();
|
||||||
|
|
||||||
|
for (const show of tvShows) {
|
||||||
|
// Check if seasons are stale
|
||||||
|
const staleSeason = db
|
||||||
|
.select()
|
||||||
|
.from(seasons)
|
||||||
|
.where(
|
||||||
|
and(eq(seasons.titleId, show.id), lt(seasons.lastFetchedAt, stale)),
|
||||||
|
)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
if (staleSeason) {
|
||||||
|
const details = await getTvDetails(show.tmdbId);
|
||||||
|
await refreshTvChildren(show.id, show.tmdbId, details.number_of_seasons);
|
||||||
|
await delay(RATE_LIMIT_MS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function registerJobs() {
|
||||||
|
scheduler.register("nightlyRefreshLibrary", nightlyRefreshLibrary, 24 * HOUR);
|
||||||
|
scheduler.register("refreshAvailability", refreshAvailabilityJob, 6 * HOUR);
|
||||||
|
scheduler.register(
|
||||||
|
"refreshRecommendations",
|
||||||
|
refreshRecommendationsJob,
|
||||||
|
12 * HOUR,
|
||||||
|
);
|
||||||
|
scheduler.register("refreshTvChildren", refreshTvChildrenJob, 12 * HOUR);
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
interface Job {
|
||||||
|
name: string;
|
||||||
|
handler: () => Promise<void>;
|
||||||
|
intervalMs: number;
|
||||||
|
timer?: ReturnType<typeof setInterval>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const globalForScheduler = globalThis as unknown as {
|
||||||
|
_scheduler: Scheduler | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Scheduler {
|
||||||
|
private jobs = new Map<string, Job>();
|
||||||
|
private running = false;
|
||||||
|
|
||||||
|
register(name: string, handler: () => Promise<void>, intervalMs: number) {
|
||||||
|
this.jobs.set(name, { name, handler, intervalMs });
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
if (this.running) return;
|
||||||
|
this.running = true;
|
||||||
|
|
||||||
|
for (const job of this.jobs.values()) {
|
||||||
|
job.timer = setInterval(async () => {
|
||||||
|
try {
|
||||||
|
console.log(`[scheduler] Running job: ${job.name}`);
|
||||||
|
await job.handler();
|
||||||
|
console.log(`[scheduler] Completed job: ${job.name}`);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`[scheduler] Job ${job.name} failed:`, err);
|
||||||
|
}
|
||||||
|
}, job.intervalMs);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`[scheduler] Started ${this.jobs.size} jobs`);
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
for (const job of this.jobs.values()) {
|
||||||
|
if (job.timer) clearInterval(job.timer);
|
||||||
|
}
|
||||||
|
this.running = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async runNow(name: string) {
|
||||||
|
const job = this.jobs.get(name);
|
||||||
|
if (!job) throw new Error(`Job not found: ${name}`);
|
||||||
|
await job.handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
getJobNames() {
|
||||||
|
return [...this.jobs.keys()];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!globalForScheduler._scheduler) {
|
||||||
|
globalForScheduler._scheduler = new Scheduler();
|
||||||
|
}
|
||||||
|
|
||||||
|
export const scheduler = globalForScheduler._scheduler;
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import { and, eq } from "drizzle-orm";
|
||||||
|
import { db } from "@/lib/db/client";
|
||||||
|
import { availabilityOffers, titles } from "@/lib/db/schema";
|
||||||
|
import { getWatchProviders } from "@/lib/tmdb/client";
|
||||||
|
|
||||||
|
export async function refreshAvailability(titleId: string) {
|
||||||
|
const title = db.select().from(titles).where(eq(titles.id, titleId)).get();
|
||||||
|
if (!title) return;
|
||||||
|
|
||||||
|
const data = await getWatchProviders(title.tmdbId, title.type);
|
||||||
|
const us = data.results?.US;
|
||||||
|
if (!us) return;
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
|
const offerTypes = ["flatrate", "rent", "buy", "free", "ads"] as const;
|
||||||
|
|
||||||
|
// Delete existing offers for this title+region
|
||||||
|
db.delete(availabilityOffers)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(availabilityOffers.titleId, titleId),
|
||||||
|
eq(availabilityOffers.region, "US"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
|
||||||
|
for (const offerType of offerTypes) {
|
||||||
|
const providers = us[offerType];
|
||||||
|
if (!providers) continue;
|
||||||
|
|
||||||
|
for (const p of providers) {
|
||||||
|
db.insert(availabilityOffers)
|
||||||
|
.values({
|
||||||
|
titleId,
|
||||||
|
region: "US",
|
||||||
|
providerId: p.provider_id,
|
||||||
|
providerName: p.provider_name,
|
||||||
|
logoPath: p.logo_path,
|
||||||
|
offerType,
|
||||||
|
link: us.link ?? null,
|
||||||
|
lastFetchedAt: now,
|
||||||
|
})
|
||||||
|
.onConflictDoNothing()
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAvailability(titleId: string) {
|
||||||
|
return db
|
||||||
|
.select()
|
||||||
|
.from(availabilityOffers)
|
||||||
|
.where(eq(availabilityOffers.titleId, titleId))
|
||||||
|
.all();
|
||||||
|
}
|
||||||
@@ -0,0 +1,242 @@
|
|||||||
|
import { and, desc, eq, sql } from "drizzle-orm";
|
||||||
|
import { db } from "@/lib/db/client";
|
||||||
|
import {
|
||||||
|
availabilityOffers,
|
||||||
|
episodes,
|
||||||
|
seasons,
|
||||||
|
titleRecommendations,
|
||||||
|
titles,
|
||||||
|
userEpisodeWatches,
|
||||||
|
userRatings,
|
||||||
|
userTitleStatus,
|
||||||
|
} from "@/lib/db/schema";
|
||||||
|
|
||||||
|
export interface ContinueWatchingItem {
|
||||||
|
title: {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
posterPath: string | null;
|
||||||
|
type: string;
|
||||||
|
};
|
||||||
|
nextEpisode: {
|
||||||
|
id: string;
|
||||||
|
seasonNumber: number;
|
||||||
|
episodeNumber: number;
|
||||||
|
name: string | null;
|
||||||
|
} | null;
|
||||||
|
lastWatchedAt: Date | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getContinueWatchingFeed(
|
||||||
|
userId: string,
|
||||||
|
): ContinueWatchingItem[] {
|
||||||
|
// Get in-progress TV shows
|
||||||
|
const inProgress = db
|
||||||
|
.select({
|
||||||
|
titleId: userTitleStatus.titleId,
|
||||||
|
updatedAt: userTitleStatus.updatedAt,
|
||||||
|
})
|
||||||
|
.from(userTitleStatus)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(userTitleStatus.userId, userId),
|
||||||
|
eq(userTitleStatus.status, "in_progress"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.all();
|
||||||
|
|
||||||
|
const items: ContinueWatchingItem[] = [];
|
||||||
|
const today = new Date().toISOString().slice(0, 10);
|
||||||
|
|
||||||
|
for (const row of inProgress) {
|
||||||
|
const title = db
|
||||||
|
.select()
|
||||||
|
.from(titles)
|
||||||
|
.where(and(eq(titles.id, row.titleId), eq(titles.type, "tv")))
|
||||||
|
.get();
|
||||||
|
if (!title) continue;
|
||||||
|
|
||||||
|
// Get all seasons for this title, ordered
|
||||||
|
const titleSeasons = db
|
||||||
|
.select()
|
||||||
|
.from(seasons)
|
||||||
|
.where(eq(seasons.titleId, title.id))
|
||||||
|
.orderBy(seasons.seasonNumber)
|
||||||
|
.all();
|
||||||
|
|
||||||
|
// Find first unwatched episode
|
||||||
|
let nextEpisode: ContinueWatchingItem["nextEpisode"] = null;
|
||||||
|
let lastWatchedAt: Date | null = null;
|
||||||
|
|
||||||
|
// Get most recent watch for this show
|
||||||
|
for (const s of titleSeasons) {
|
||||||
|
const eps = db
|
||||||
|
.select()
|
||||||
|
.from(episodes)
|
||||||
|
.where(eq(episodes.seasonId, s.id))
|
||||||
|
.orderBy(episodes.episodeNumber)
|
||||||
|
.all();
|
||||||
|
|
||||||
|
for (const ep of eps) {
|
||||||
|
const watch = db
|
||||||
|
.select()
|
||||||
|
.from(userEpisodeWatches)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(userEpisodeWatches.userId, userId),
|
||||||
|
eq(userEpisodeWatches.episodeId, ep.id),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
if (watch) {
|
||||||
|
if (!lastWatchedAt || watch.watchedAt > lastWatchedAt) {
|
||||||
|
lastWatchedAt = watch.watchedAt;
|
||||||
|
}
|
||||||
|
} else if (!nextEpisode) {
|
||||||
|
// Skip episodes not yet aired
|
||||||
|
if (ep.airDate && ep.airDate > today) continue;
|
||||||
|
nextEpisode = {
|
||||||
|
id: ep.id,
|
||||||
|
seasonNumber: s.seasonNumber,
|
||||||
|
episodeNumber: ep.episodeNumber,
|
||||||
|
name: ep.name,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextEpisode) {
|
||||||
|
items.push({
|
||||||
|
title: {
|
||||||
|
id: title.id,
|
||||||
|
title: title.title,
|
||||||
|
posterPath: title.posterPath,
|
||||||
|
type: title.type,
|
||||||
|
},
|
||||||
|
nextEpisode,
|
||||||
|
lastWatchedAt,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort by most recent watch
|
||||||
|
items.sort((a, b) => {
|
||||||
|
const aTime = a.lastWatchedAt?.getTime() ?? 0;
|
||||||
|
const bTime = b.lastWatchedAt?.getTime() ?? 0;
|
||||||
|
return bTime - aTime;
|
||||||
|
});
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
// biome-ignore lint/correctness/noUnusedFunctionParameters: days reserved for future date filtering
|
||||||
|
export function getNewAvailableFeed(userId: string, days = 14) {
|
||||||
|
// Get titles the user has in any status that have availability offers
|
||||||
|
// and recent release/air dates
|
||||||
|
const results = db
|
||||||
|
.select({
|
||||||
|
titleId: titles.id,
|
||||||
|
title: titles.title,
|
||||||
|
type: titles.type,
|
||||||
|
posterPath: titles.posterPath,
|
||||||
|
releaseDate: titles.releaseDate,
|
||||||
|
firstAirDate: titles.firstAirDate,
|
||||||
|
popularity: titles.popularity,
|
||||||
|
})
|
||||||
|
.from(titles)
|
||||||
|
.innerJoin(
|
||||||
|
userTitleStatus,
|
||||||
|
and(
|
||||||
|
eq(userTitleStatus.titleId, titles.id),
|
||||||
|
eq(userTitleStatus.userId, userId),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
sql`EXISTS (SELECT 1 FROM ${availabilityOffers} WHERE ${availabilityOffers.titleId} = ${titles.id})`,
|
||||||
|
)
|
||||||
|
.orderBy(desc(titles.popularity))
|
||||||
|
.limit(20)
|
||||||
|
.all();
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getRecommendationsFeed(userId: string) {
|
||||||
|
// Get recommendations from user's highly-rated or completed titles
|
||||||
|
const userCompletedOrRated = db
|
||||||
|
.select({ titleId: userTitleStatus.titleId })
|
||||||
|
.from(userTitleStatus)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(userTitleStatus.userId, userId),
|
||||||
|
eq(userTitleStatus.status, "completed"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.all()
|
||||||
|
.map((r) => r.titleId);
|
||||||
|
|
||||||
|
const ratedIds = db
|
||||||
|
.select({ titleId: userRatings.titleId })
|
||||||
|
.from(userRatings)
|
||||||
|
.where(
|
||||||
|
and(eq(userRatings.userId, userId), sql`${userRatings.ratingStars} >= 4`),
|
||||||
|
)
|
||||||
|
.all()
|
||||||
|
.map((r) => r.titleId);
|
||||||
|
|
||||||
|
const sourceIds = [...new Set([...userCompletedOrRated, ...ratedIds])];
|
||||||
|
if (sourceIds.length === 0) return [];
|
||||||
|
|
||||||
|
// Get all tracked title IDs to exclude
|
||||||
|
const trackedIds = new Set(
|
||||||
|
db
|
||||||
|
.select({ titleId: userTitleStatus.titleId })
|
||||||
|
.from(userTitleStatus)
|
||||||
|
.where(eq(userTitleStatus.userId, userId))
|
||||||
|
.all()
|
||||||
|
.map((r) => r.titleId),
|
||||||
|
);
|
||||||
|
|
||||||
|
const recs: Map<string, { titleId: string; score: number }> = new Map();
|
||||||
|
|
||||||
|
for (const sourceId of sourceIds) {
|
||||||
|
const recRows = db
|
||||||
|
.select({
|
||||||
|
recommendedTitleId: titleRecommendations.recommendedTitleId,
|
||||||
|
rank: titleRecommendations.rank,
|
||||||
|
})
|
||||||
|
.from(titleRecommendations)
|
||||||
|
.where(eq(titleRecommendations.titleId, sourceId))
|
||||||
|
.all();
|
||||||
|
|
||||||
|
for (const rec of recRows) {
|
||||||
|
if (trackedIds.has(rec.recommendedTitleId)) continue;
|
||||||
|
const existing = recs.get(rec.recommendedTitleId);
|
||||||
|
const score = 100 - rec.rank;
|
||||||
|
if (existing) {
|
||||||
|
existing.score += score;
|
||||||
|
} else {
|
||||||
|
recs.set(rec.recommendedTitleId, {
|
||||||
|
titleId: rec.recommendedTitleId,
|
||||||
|
score,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const sorted = [...recs.values()]
|
||||||
|
.sort((a, b) => b.score - a.score)
|
||||||
|
.slice(0, 20);
|
||||||
|
|
||||||
|
return sorted
|
||||||
|
.map((r) => {
|
||||||
|
const title = db
|
||||||
|
.select()
|
||||||
|
.from(titles)
|
||||||
|
.where(eq(titles.id, r.titleId))
|
||||||
|
.get();
|
||||||
|
return title;
|
||||||
|
})
|
||||||
|
.filter(Boolean);
|
||||||
|
}
|
||||||
@@ -0,0 +1,344 @@
|
|||||||
|
import { eq } from "drizzle-orm";
|
||||||
|
import { db } from "@/lib/db/client";
|
||||||
|
import {
|
||||||
|
episodes,
|
||||||
|
seasons,
|
||||||
|
titleRecommendations,
|
||||||
|
titles,
|
||||||
|
} from "@/lib/db/schema";
|
||||||
|
import {
|
||||||
|
getMovieDetails,
|
||||||
|
getRecommendations,
|
||||||
|
getSimilar,
|
||||||
|
getTvDetails,
|
||||||
|
getTvSeasonDetails,
|
||||||
|
} from "@/lib/tmdb/client";
|
||||||
|
import { refreshAvailability } from "./availability";
|
||||||
|
|
||||||
|
export async function importTitle(tmdbId: number, type: "movie" | "tv") {
|
||||||
|
const existing = db
|
||||||
|
.select()
|
||||||
|
.from(titles)
|
||||||
|
.where(eq(titles.tmdbId, tmdbId))
|
||||||
|
.get();
|
||||||
|
if (existing) return existing;
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
if (type === "movie") {
|
||||||
|
const movie = await getMovieDetails(tmdbId);
|
||||||
|
const row = db
|
||||||
|
.insert(titles)
|
||||||
|
.values({
|
||||||
|
tmdbId: movie.id,
|
||||||
|
type: "movie",
|
||||||
|
title: movie.title,
|
||||||
|
originalTitle: movie.original_title,
|
||||||
|
overview: movie.overview,
|
||||||
|
releaseDate: movie.release_date || null,
|
||||||
|
posterPath: movie.poster_path,
|
||||||
|
backdropPath: movie.backdrop_path,
|
||||||
|
popularity: movie.popularity,
|
||||||
|
voteAverage: movie.vote_average,
|
||||||
|
voteCount: movie.vote_count,
|
||||||
|
status: movie.status,
|
||||||
|
lastFetchedAt: now,
|
||||||
|
})
|
||||||
|
.returning()
|
||||||
|
.get();
|
||||||
|
// Fire-and-forget: fetch availability & recommendations
|
||||||
|
refreshAvailability(row.id).catch(() => {});
|
||||||
|
refreshRecommendations(row.id).catch(() => {});
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
const show = await getTvDetails(tmdbId);
|
||||||
|
const row = db
|
||||||
|
.insert(titles)
|
||||||
|
.values({
|
||||||
|
tmdbId: show.id,
|
||||||
|
type: "tv",
|
||||||
|
title: show.name,
|
||||||
|
originalTitle: show.original_name,
|
||||||
|
overview: show.overview,
|
||||||
|
firstAirDate: show.first_air_date || null,
|
||||||
|
posterPath: show.poster_path,
|
||||||
|
backdropPath: show.backdrop_path,
|
||||||
|
popularity: show.popularity,
|
||||||
|
voteAverage: show.vote_average,
|
||||||
|
voteCount: show.vote_count,
|
||||||
|
status: show.status,
|
||||||
|
lastFetchedAt: now,
|
||||||
|
})
|
||||||
|
.returning()
|
||||||
|
.get();
|
||||||
|
|
||||||
|
await refreshTvChildren(row.id, tmdbId, show.number_of_seasons);
|
||||||
|
// Fire-and-forget: fetch availability & recommendations
|
||||||
|
refreshAvailability(row.id).catch(() => {});
|
||||||
|
refreshRecommendations(row.id).catch(() => {});
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function refreshTitle(titleId: string) {
|
||||||
|
const title = db.select().from(titles).where(eq(titles.id, titleId)).get();
|
||||||
|
if (!title) return null;
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
if (title.type === "movie") {
|
||||||
|
const movie = await getMovieDetails(title.tmdbId);
|
||||||
|
db.update(titles)
|
||||||
|
.set({
|
||||||
|
title: movie.title,
|
||||||
|
originalTitle: movie.original_title,
|
||||||
|
overview: movie.overview,
|
||||||
|
releaseDate: movie.release_date || null,
|
||||||
|
posterPath: movie.poster_path,
|
||||||
|
backdropPath: movie.backdrop_path,
|
||||||
|
popularity: movie.popularity,
|
||||||
|
voteAverage: movie.vote_average,
|
||||||
|
voteCount: movie.vote_count,
|
||||||
|
status: movie.status,
|
||||||
|
lastFetchedAt: now,
|
||||||
|
})
|
||||||
|
.where(eq(titles.id, titleId))
|
||||||
|
.run();
|
||||||
|
} else {
|
||||||
|
const show = await getTvDetails(title.tmdbId);
|
||||||
|
db.update(titles)
|
||||||
|
.set({
|
||||||
|
title: show.name,
|
||||||
|
originalTitle: show.original_name,
|
||||||
|
overview: show.overview,
|
||||||
|
firstAirDate: show.first_air_date || null,
|
||||||
|
posterPath: show.poster_path,
|
||||||
|
backdropPath: show.backdrop_path,
|
||||||
|
popularity: show.popularity,
|
||||||
|
voteAverage: show.vote_average,
|
||||||
|
voteCount: show.vote_count,
|
||||||
|
status: show.status,
|
||||||
|
lastFetchedAt: now,
|
||||||
|
})
|
||||||
|
.where(eq(titles.id, titleId))
|
||||||
|
.run();
|
||||||
|
await refreshTvChildren(titleId, title.tmdbId, show.number_of_seasons);
|
||||||
|
}
|
||||||
|
|
||||||
|
return db.select().from(titles).where(eq(titles.id, titleId)).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function refreshTvChildren(
|
||||||
|
titleId: string,
|
||||||
|
tmdbId: number,
|
||||||
|
numberOfSeasons: number,
|
||||||
|
) {
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
for (let sn = 1; sn <= numberOfSeasons; sn++) {
|
||||||
|
// Rate-limit: 250ms between TMDB calls
|
||||||
|
if (sn > 1) await delay(250);
|
||||||
|
|
||||||
|
const seasonData = await getTvSeasonDetails(tmdbId, sn);
|
||||||
|
|
||||||
|
const seasonRow = db
|
||||||
|
.insert(seasons)
|
||||||
|
.values({
|
||||||
|
titleId,
|
||||||
|
seasonNumber: seasonData.season_number,
|
||||||
|
name: seasonData.name,
|
||||||
|
overview: seasonData.overview,
|
||||||
|
posterPath: seasonData.poster_path,
|
||||||
|
airDate: seasonData.air_date,
|
||||||
|
lastFetchedAt: now,
|
||||||
|
})
|
||||||
|
.onConflictDoUpdate({
|
||||||
|
target: [seasons.titleId, seasons.seasonNumber],
|
||||||
|
set: {
|
||||||
|
name: seasonData.name,
|
||||||
|
overview: seasonData.overview,
|
||||||
|
posterPath: seasonData.poster_path,
|
||||||
|
airDate: seasonData.air_date,
|
||||||
|
lastFetchedAt: now,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.returning()
|
||||||
|
.get();
|
||||||
|
|
||||||
|
for (const ep of seasonData.episodes) {
|
||||||
|
db.insert(episodes)
|
||||||
|
.values({
|
||||||
|
seasonId: seasonRow.id,
|
||||||
|
episodeNumber: ep.episode_number,
|
||||||
|
name: ep.name,
|
||||||
|
overview: ep.overview,
|
||||||
|
stillPath: ep.still_path,
|
||||||
|
airDate: ep.air_date,
|
||||||
|
runtimeMinutes: ep.runtime,
|
||||||
|
})
|
||||||
|
.onConflictDoUpdate({
|
||||||
|
target: [episodes.seasonId, episodes.episodeNumber],
|
||||||
|
set: {
|
||||||
|
name: ep.name,
|
||||||
|
overview: ep.overview,
|
||||||
|
stillPath: ep.still_path,
|
||||||
|
airDate: ep.air_date,
|
||||||
|
runtimeMinutes: ep.runtime,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function refreshRecommendations(titleId: string) {
|
||||||
|
const title = db.select().from(titles).where(eq(titles.id, titleId)).get();
|
||||||
|
if (!title) return;
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
// Fetch both recommendations and similar
|
||||||
|
const [recs, similar] = await Promise.all([
|
||||||
|
getRecommendations(title.tmdbId, title.type),
|
||||||
|
getSimilar(title.tmdbId, title.type),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Process recommendations
|
||||||
|
for (let i = 0; i < recs.results.length && i < 20; i++) {
|
||||||
|
const r = recs.results[i];
|
||||||
|
const type = r.media_type ?? title.type;
|
||||||
|
if (type !== "movie" && type !== "tv") continue;
|
||||||
|
|
||||||
|
// Minimal upsert of the recommended title
|
||||||
|
const existing = db
|
||||||
|
.select()
|
||||||
|
.from(titles)
|
||||||
|
.where(eq(titles.tmdbId, r.id))
|
||||||
|
.get();
|
||||||
|
let recTitleId: string;
|
||||||
|
if (existing) {
|
||||||
|
recTitleId = existing.id;
|
||||||
|
} else {
|
||||||
|
const row = db
|
||||||
|
.insert(titles)
|
||||||
|
.values({
|
||||||
|
tmdbId: r.id,
|
||||||
|
type,
|
||||||
|
title: r.title ?? r.name ?? "Unknown",
|
||||||
|
originalTitle: r.original_title ?? r.original_name,
|
||||||
|
overview: r.overview,
|
||||||
|
releaseDate: r.release_date,
|
||||||
|
firstAirDate: r.first_air_date,
|
||||||
|
posterPath: r.poster_path,
|
||||||
|
backdropPath: r.backdrop_path,
|
||||||
|
popularity: r.popularity,
|
||||||
|
voteAverage: r.vote_average,
|
||||||
|
voteCount: r.vote_count,
|
||||||
|
lastFetchedAt: null,
|
||||||
|
})
|
||||||
|
.onConflictDoNothing()
|
||||||
|
.returning()
|
||||||
|
.get();
|
||||||
|
if (!row) {
|
||||||
|
const found = db
|
||||||
|
.select()
|
||||||
|
.from(titles)
|
||||||
|
.where(eq(titles.tmdbId, r.id))
|
||||||
|
.get();
|
||||||
|
if (!found) continue;
|
||||||
|
recTitleId = found.id;
|
||||||
|
} else {
|
||||||
|
recTitleId = row.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
db.insert(titleRecommendations)
|
||||||
|
.values({
|
||||||
|
titleId,
|
||||||
|
recommendedTitleId: recTitleId,
|
||||||
|
source: "tmdb_recommendations",
|
||||||
|
rank: i + 1,
|
||||||
|
lastFetchedAt: now,
|
||||||
|
})
|
||||||
|
.onConflictDoUpdate({
|
||||||
|
target: [
|
||||||
|
titleRecommendations.titleId,
|
||||||
|
titleRecommendations.recommendedTitleId,
|
||||||
|
titleRecommendations.source,
|
||||||
|
],
|
||||||
|
set: { rank: i + 1, lastFetchedAt: now },
|
||||||
|
})
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process similar
|
||||||
|
for (let i = 0; i < similar.results.length && i < 20; i++) {
|
||||||
|
const r = similar.results[i];
|
||||||
|
const type = r.media_type ?? title.type;
|
||||||
|
if (type !== "movie" && type !== "tv") continue;
|
||||||
|
|
||||||
|
const existing = db
|
||||||
|
.select()
|
||||||
|
.from(titles)
|
||||||
|
.where(eq(titles.tmdbId, r.id))
|
||||||
|
.get();
|
||||||
|
let recTitleId: string;
|
||||||
|
if (existing) {
|
||||||
|
recTitleId = existing.id;
|
||||||
|
} else {
|
||||||
|
const row = db
|
||||||
|
.insert(titles)
|
||||||
|
.values({
|
||||||
|
tmdbId: r.id,
|
||||||
|
type,
|
||||||
|
title: r.title ?? r.name ?? "Unknown",
|
||||||
|
originalTitle: r.original_title ?? r.original_name,
|
||||||
|
overview: r.overview,
|
||||||
|
releaseDate: r.release_date,
|
||||||
|
firstAirDate: r.first_air_date,
|
||||||
|
posterPath: r.poster_path,
|
||||||
|
backdropPath: r.backdrop_path,
|
||||||
|
popularity: r.popularity,
|
||||||
|
voteAverage: r.vote_average,
|
||||||
|
voteCount: r.vote_count,
|
||||||
|
lastFetchedAt: null,
|
||||||
|
})
|
||||||
|
.onConflictDoNothing()
|
||||||
|
.returning()
|
||||||
|
.get();
|
||||||
|
if (!row) {
|
||||||
|
const found = db
|
||||||
|
.select()
|
||||||
|
.from(titles)
|
||||||
|
.where(eq(titles.tmdbId, r.id))
|
||||||
|
.get();
|
||||||
|
if (!found) continue;
|
||||||
|
recTitleId = found.id;
|
||||||
|
} else {
|
||||||
|
recTitleId = row.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
db.insert(titleRecommendations)
|
||||||
|
.values({
|
||||||
|
titleId,
|
||||||
|
recommendedTitleId: recTitleId,
|
||||||
|
source: "tmdb_similar",
|
||||||
|
rank: i + 1,
|
||||||
|
lastFetchedAt: now,
|
||||||
|
})
|
||||||
|
.onConflictDoUpdate({
|
||||||
|
target: [
|
||||||
|
titleRecommendations.titleId,
|
||||||
|
titleRecommendations.recommendedTitleId,
|
||||||
|
titleRecommendations.source,
|
||||||
|
],
|
||||||
|
set: { rank: i + 1, lastFetchedAt: now },
|
||||||
|
})
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function delay(ms: number) {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
@@ -0,0 +1,215 @@
|
|||||||
|
import { and, eq } from "drizzle-orm";
|
||||||
|
import { db } from "@/lib/db/client";
|
||||||
|
import {
|
||||||
|
episodes,
|
||||||
|
seasons,
|
||||||
|
userEpisodeWatches,
|
||||||
|
userMovieWatches,
|
||||||
|
userRatings,
|
||||||
|
userTitleStatus,
|
||||||
|
} from "@/lib/db/schema";
|
||||||
|
|
||||||
|
export function setTitleStatus(
|
||||||
|
userId: string,
|
||||||
|
titleId: string,
|
||||||
|
status: "watchlist" | "in_progress" | "completed",
|
||||||
|
) {
|
||||||
|
const now = new Date();
|
||||||
|
db.insert(userTitleStatus)
|
||||||
|
.values({ userId, titleId, status, addedAt: now, updatedAt: now })
|
||||||
|
.onConflictDoUpdate({
|
||||||
|
target: [userTitleStatus.userId, userTitleStatus.titleId],
|
||||||
|
set: { status, updatedAt: now },
|
||||||
|
})
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeTitleStatus(userId: string, titleId: string) {
|
||||||
|
db.delete(userTitleStatus)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(userTitleStatus.userId, userId),
|
||||||
|
eq(userTitleStatus.titleId, titleId),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function logMovieWatch(userId: string, titleId: string) {
|
||||||
|
const now = new Date();
|
||||||
|
db.insert(userMovieWatches)
|
||||||
|
.values({ userId, titleId, watchedAt: now, source: "manual" })
|
||||||
|
.run();
|
||||||
|
|
||||||
|
// Auto-set status to completed
|
||||||
|
const existing = db
|
||||||
|
.select()
|
||||||
|
.from(userTitleStatus)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(userTitleStatus.userId, userId),
|
||||||
|
eq(userTitleStatus.titleId, titleId),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
setTitleStatus(userId, titleId, "completed");
|
||||||
|
} else if (existing.status !== "completed") {
|
||||||
|
setTitleStatus(userId, titleId, "completed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function logEpisodeWatch(userId: string, episodeId: string) {
|
||||||
|
const now = new Date();
|
||||||
|
db.insert(userEpisodeWatches)
|
||||||
|
.values({ userId, episodeId, watchedAt: now, source: "manual" })
|
||||||
|
.run();
|
||||||
|
|
||||||
|
// Find the title for this episode
|
||||||
|
const ep = db.select().from(episodes).where(eq(episodes.id, episodeId)).get();
|
||||||
|
if (!ep) return;
|
||||||
|
const season = db
|
||||||
|
.select()
|
||||||
|
.from(seasons)
|
||||||
|
.where(eq(seasons.id, ep.seasonId))
|
||||||
|
.get();
|
||||||
|
if (!season) return;
|
||||||
|
const titleId = season.titleId;
|
||||||
|
|
||||||
|
// Auto-set status to in_progress if not set
|
||||||
|
const existing = db
|
||||||
|
.select()
|
||||||
|
.from(userTitleStatus)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(userTitleStatus.userId, userId),
|
||||||
|
eq(userTitleStatus.titleId, titleId),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
setTitleStatus(userId, titleId, "in_progress");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if all episodes are watched -> auto-complete
|
||||||
|
checkAllEpisodesWatched(userId, titleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkAllEpisodesWatched(userId: string, titleId: string) {
|
||||||
|
const allSeasons = db
|
||||||
|
.select()
|
||||||
|
.from(seasons)
|
||||||
|
.where(eq(seasons.titleId, titleId))
|
||||||
|
.all();
|
||||||
|
|
||||||
|
let totalEpisodes = 0;
|
||||||
|
let watchedEpisodes = 0;
|
||||||
|
|
||||||
|
for (const s of allSeasons) {
|
||||||
|
const eps = db
|
||||||
|
.select()
|
||||||
|
.from(episodes)
|
||||||
|
.where(eq(episodes.seasonId, s.id))
|
||||||
|
.all();
|
||||||
|
totalEpisodes += eps.length;
|
||||||
|
|
||||||
|
for (const ep of eps) {
|
||||||
|
const watch = db
|
||||||
|
.select()
|
||||||
|
.from(userEpisodeWatches)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(userEpisodeWatches.userId, userId),
|
||||||
|
eq(userEpisodeWatches.episodeId, ep.id),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.get();
|
||||||
|
if (watch) watchedEpisodes++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (totalEpisodes > 0 && watchedEpisodes >= totalEpisodes) {
|
||||||
|
setTitleStatus(userId, titleId, "completed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function rateTitleStars(
|
||||||
|
userId: string,
|
||||||
|
titleId: string,
|
||||||
|
ratingStars: number,
|
||||||
|
) {
|
||||||
|
const now = new Date();
|
||||||
|
if (ratingStars === 0) {
|
||||||
|
db.delete(userRatings)
|
||||||
|
.where(
|
||||||
|
and(eq(userRatings.userId, userId), eq(userRatings.titleId, titleId)),
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
db.insert(userRatings)
|
||||||
|
.values({ userId, titleId, ratingStars, ratedAt: now })
|
||||||
|
.onConflictDoUpdate({
|
||||||
|
target: [userRatings.userId, userRatings.titleId],
|
||||||
|
set: { ratingStars, ratedAt: now },
|
||||||
|
})
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUserTitleInfo(userId: string, titleId: string) {
|
||||||
|
const status = db
|
||||||
|
.select()
|
||||||
|
.from(userTitleStatus)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(userTitleStatus.userId, userId),
|
||||||
|
eq(userTitleStatus.titleId, titleId),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
const rating = db
|
||||||
|
.select()
|
||||||
|
.from(userRatings)
|
||||||
|
.where(
|
||||||
|
and(eq(userRatings.userId, userId), eq(userRatings.titleId, titleId)),
|
||||||
|
)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
// Get watched episode IDs for this title
|
||||||
|
const titleSeasons = db
|
||||||
|
.select()
|
||||||
|
.from(seasons)
|
||||||
|
.where(eq(seasons.titleId, titleId))
|
||||||
|
.all();
|
||||||
|
|
||||||
|
const watchedEpisodeIds: string[] = [];
|
||||||
|
for (const s of titleSeasons) {
|
||||||
|
const eps = db
|
||||||
|
.select()
|
||||||
|
.from(episodes)
|
||||||
|
.where(eq(episodes.seasonId, s.id))
|
||||||
|
.all();
|
||||||
|
for (const ep of eps) {
|
||||||
|
const watch = db
|
||||||
|
.select()
|
||||||
|
.from(userEpisodeWatches)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(userEpisodeWatches.userId, userId),
|
||||||
|
eq(userEpisodeWatches.episodeId, ep.id),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.get();
|
||||||
|
if (watch) watchedEpisodeIds.push(ep.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: status?.status ?? null,
|
||||||
|
rating: rating?.ratingStars ?? null,
|
||||||
|
episodeWatches: watchedEpisodeIds,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
import type {
|
||||||
|
TmdbMovieDetails,
|
||||||
|
TmdbRecommendationResponse,
|
||||||
|
TmdbSearchResponse,
|
||||||
|
TmdbSeasonDetails,
|
||||||
|
TmdbTvDetails,
|
||||||
|
TmdbWatchProviderResponse,
|
||||||
|
} from "./types";
|
||||||
|
|
||||||
|
const BASE_URL = "https://api.themoviedb.org/3";
|
||||||
|
|
||||||
|
function getApiKey() {
|
||||||
|
const key = process.env.TMDB_API_KEY;
|
||||||
|
if (!key) throw new Error("TMDB_API_KEY is not set");
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function tmdbFetch<T>(
|
||||||
|
path: string,
|
||||||
|
params?: Record<string, string>,
|
||||||
|
): Promise<T> {
|
||||||
|
const url = new URL(`${BASE_URL}${path}`);
|
||||||
|
if (params) {
|
||||||
|
for (const [k, v] of Object.entries(params)) {
|
||||||
|
url.searchParams.set(k, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await fetch(url.toString(), {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${getApiKey()}`,
|
||||||
|
Accept: "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(`TMDB API error: ${res.status} ${res.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.json() as Promise<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function searchMulti(query: string, page = 1) {
|
||||||
|
return tmdbFetch<TmdbSearchResponse>("/search/multi", {
|
||||||
|
query,
|
||||||
|
page: String(page),
|
||||||
|
include_adult: "false",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function searchMovies(query: string, page = 1) {
|
||||||
|
return tmdbFetch<TmdbSearchResponse>("/search/movie", {
|
||||||
|
query,
|
||||||
|
page: String(page),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function searchTv(query: string, page = 1) {
|
||||||
|
return tmdbFetch<TmdbSearchResponse>("/search/tv", {
|
||||||
|
query,
|
||||||
|
page: String(page),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getMovieDetails(tmdbId: number) {
|
||||||
|
return tmdbFetch<TmdbMovieDetails>(`/movie/${tmdbId}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getTvDetails(tmdbId: number) {
|
||||||
|
return tmdbFetch<TmdbTvDetails>(`/tv/${tmdbId}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getTvSeasonDetails(tmdbId: number, seasonNumber: number) {
|
||||||
|
return tmdbFetch<TmdbSeasonDetails>(`/tv/${tmdbId}/season/${seasonNumber}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getWatchProviders(tmdbId: number, type: "movie" | "tv") {
|
||||||
|
return tmdbFetch<TmdbWatchProviderResponse>(
|
||||||
|
`/${type}/${tmdbId}/watch/providers`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getRecommendations(tmdbId: number, type: "movie" | "tv") {
|
||||||
|
return tmdbFetch<TmdbRecommendationResponse>(
|
||||||
|
`/${type}/${tmdbId}/recommendations`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getSimilar(tmdbId: number, type: "movie" | "tv") {
|
||||||
|
return tmdbFetch<TmdbRecommendationResponse>(`/${type}/${tmdbId}/similar`);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function tmdbImageUrl(path: string | null, size = "w500") {
|
||||||
|
if (!path) return null;
|
||||||
|
return `https://image.tmdb.org/t/p/${size}${path}`;
|
||||||
|
}
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
export interface TmdbSearchResult {
|
||||||
|
id: number;
|
||||||
|
media_type: "movie" | "tv" | "person";
|
||||||
|
title?: string;
|
||||||
|
name?: string;
|
||||||
|
original_title?: string;
|
||||||
|
original_name?: string;
|
||||||
|
overview: string;
|
||||||
|
release_date?: string;
|
||||||
|
first_air_date?: string;
|
||||||
|
poster_path: string | null;
|
||||||
|
backdrop_path: string | null;
|
||||||
|
popularity: number;
|
||||||
|
vote_average: number;
|
||||||
|
vote_count: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TmdbSearchResponse {
|
||||||
|
page: number;
|
||||||
|
results: TmdbSearchResult[];
|
||||||
|
total_pages: number;
|
||||||
|
total_results: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TmdbMovieDetails {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
original_title: string;
|
||||||
|
overview: string;
|
||||||
|
release_date: string;
|
||||||
|
poster_path: string | null;
|
||||||
|
backdrop_path: string | null;
|
||||||
|
popularity: number;
|
||||||
|
vote_average: number;
|
||||||
|
vote_count: number;
|
||||||
|
status: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TmdbTvDetails {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
original_name: string;
|
||||||
|
overview: string;
|
||||||
|
first_air_date: string;
|
||||||
|
poster_path: string | null;
|
||||||
|
backdrop_path: string | null;
|
||||||
|
popularity: number;
|
||||||
|
vote_average: number;
|
||||||
|
vote_count: number;
|
||||||
|
status: string;
|
||||||
|
number_of_seasons: number;
|
||||||
|
seasons: TmdbSeasonSummary[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TmdbSeasonSummary {
|
||||||
|
id: number;
|
||||||
|
season_number: number;
|
||||||
|
name: string;
|
||||||
|
overview: string;
|
||||||
|
poster_path: string | null;
|
||||||
|
air_date: string | null;
|
||||||
|
episode_count: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TmdbSeasonDetails {
|
||||||
|
id: number;
|
||||||
|
season_number: number;
|
||||||
|
name: string;
|
||||||
|
overview: string;
|
||||||
|
poster_path: string | null;
|
||||||
|
air_date: string | null;
|
||||||
|
episodes: TmdbEpisode[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TmdbEpisode {
|
||||||
|
id: number;
|
||||||
|
episode_number: number;
|
||||||
|
name: string;
|
||||||
|
overview: string;
|
||||||
|
still_path: string | null;
|
||||||
|
air_date: string | null;
|
||||||
|
runtime: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TmdbWatchProviderResponse {
|
||||||
|
id: number;
|
||||||
|
results: Record<
|
||||||
|
string,
|
||||||
|
{
|
||||||
|
link?: string;
|
||||||
|
flatrate?: TmdbProvider[];
|
||||||
|
rent?: TmdbProvider[];
|
||||||
|
buy?: TmdbProvider[];
|
||||||
|
free?: TmdbProvider[];
|
||||||
|
ads?: TmdbProvider[];
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TmdbProvider {
|
||||||
|
provider_id: number;
|
||||||
|
provider_name: string;
|
||||||
|
logo_path: string;
|
||||||
|
display_priority: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TmdbRecommendationResponse {
|
||||||
|
page: number;
|
||||||
|
results: TmdbSearchResult[];
|
||||||
|
total_pages: number;
|
||||||
|
total_results: number;
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { type ClassValue, clsx } from "clsx";
|
||||||
|
import { twMerge } from "tailwind-merge";
|
||||||
|
|
||||||
|
export function cn(...inputs: ClassValue[]) {
|
||||||
|
return twMerge(clsx(inputs));
|
||||||
|
}
|
||||||
+9
-1
@@ -1,8 +1,16 @@
|
|||||||
import type { NextConfig } from "next";
|
import type { NextConfig } from "next";
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
/* config options here */
|
|
||||||
reactCompiler: true,
|
reactCompiler: true,
|
||||||
|
images: {
|
||||||
|
remotePatterns: [
|
||||||
|
{
|
||||||
|
protocol: "https",
|
||||||
|
hostname: "image.tmdb.org",
|
||||||
|
pathname: "/t/p/**",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default nextConfig;
|
export default nextConfig;
|
||||||
|
|||||||
+19
-2
@@ -7,28 +7,45 @@
|
|||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "biome check",
|
"lint": "biome check",
|
||||||
"format": "biome format --write"
|
"format": "biome format --write",
|
||||||
|
"db:generate": "drizzle-kit generate",
|
||||||
|
"db:migrate": "drizzle-kit migrate",
|
||||||
|
"db:push": "drizzle-kit push",
|
||||||
|
"db:studio": "drizzle-kit studio"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@base-ui/react": "^1.2.0",
|
"@base-ui/react": "^1.2.0",
|
||||||
"@tabler/icons-react": "^3.37.1",
|
"@tabler/icons-react": "^3.37.1",
|
||||||
|
"better-auth": "^1.4.19",
|
||||||
|
"better-sqlite3": "^12.6.2",
|
||||||
"class-variance-authority": "^0.7.1",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
|
"drizzle-orm": "^0.45.1",
|
||||||
"next": "16.1.6",
|
"next": "16.1.6",
|
||||||
"react": "19.2.4",
|
"react": "19.2.4",
|
||||||
"react-dom": "19.2.4",
|
"react-dom": "19.2.4",
|
||||||
"shadcn": "^3.8.5",
|
"shadcn": "^3.8.5",
|
||||||
"tailwind-merge": "^3.5.0",
|
"tailwind-merge": "^3.5.0",
|
||||||
"tw-animate-css": "^1.4.0"
|
"tw-animate-css": "^1.4.0",
|
||||||
|
"uuid": "^13.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "2.4.4",
|
"@biomejs/biome": "2.4.4",
|
||||||
"@tailwindcss/postcss": "^4.2.1",
|
"@tailwindcss/postcss": "^4.2.1",
|
||||||
|
"@types/better-sqlite3": "^7.6.13",
|
||||||
"@types/node": "^25.3.2",
|
"@types/node": "^25.3.2",
|
||||||
"@types/react": "^19.2.14",
|
"@types/react": "^19.2.14",
|
||||||
"@types/react-dom": "^19.2.3",
|
"@types/react-dom": "^19.2.3",
|
||||||
|
"@types/uuid": "^11.0.0",
|
||||||
"babel-plugin-react-compiler": "1.0.0",
|
"babel-plugin-react-compiler": "1.0.0",
|
||||||
|
"drizzle-kit": "^0.31.9",
|
||||||
"tailwindcss": "^4.2.1",
|
"tailwindcss": "^4.2.1",
|
||||||
"typescript": "^5.9.3"
|
"typescript": "^5.9.3"
|
||||||
|
},
|
||||||
|
"pnpm": {
|
||||||
|
"onlyBuiltDependencies": [
|
||||||
|
"better-sqlite3",
|
||||||
|
"esbuild"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+1132
-2
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user