Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | 2x 81x 81x 33x 81x 81x 33x 33x 81x 81x 81x 81x 6x 6x 81x 81x 81x 81x 89x 89x 89x 81x 4x 4x 4x 81x 81x 81x 81x 81x 81x 81x 81x 81x 81x 81x 2x 1x 1x | // SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 Max Boksem. See NOTICE for additional terms under GPLv3 section 7.
import { useState, useEffect } from "react";
import { X, Play, Clapperboard, LoaderCircle } from "lucide-react";
import { Select } from "@/components/ui/select";
import type { Channel, OmdbData, WhatsonData } from "@/lib/types";
import { enqueueMovieDownload, stopDownload, removeDownload } from "@/lib/tauri";
import { channelSources, withSource, describeSource } from "@/lib/sources";
import { downloadIconState } from "@/lib/download-status";
import { RatingsRow } from "@/components/ui/ratings-row";
import { useDownloads } from "@/hooks/useDownloads";
import { useSheetDetails } from "@/hooks/useMediaDetails";
import { useSheetDrag } from "@/hooks/useSheetDrag";
import { DownloadButton } from "@/components/downloads/DownloadButton";
import { RetentionNote } from "@/components/downloads/RetentionNote";
import { OmdbKeyHint } from "./OmdbKeyHint";
interface MovieInfoDrawerProps {
movie: Channel;
onClose: () => void;
onPlay: (ch: Channel) => void;
// Optional pre-fetched data from PlayerView to avoid double-fetch
prefetchedOmdbData?: OmdbData | null;
prefetchedWhatsonData?: WhatsonData | null;
}
export const MovieInfoDrawer = ({
movie,
onClose,
onPlay,
prefetchedOmdbData,
prefetchedWhatsonData,
}: MovieInfoDrawerProps) => {
const [visible, setVisible] = useState(false);
// Pre-select the source currently in use (the player opens this drawer for the playing movie).
const [selectedSourceIdx, setSelectedSourceIdx] = useState(() =>
Math.max(0, channelSources(movie).indexOf(movie.url))
);
const { omdbData, whatsonData, omdbLoading, hasOmdbKey, infoLoading } = useSheetDetails(
{
id: movie.id,
title: movie.name,
kind: movie.contentType === "series" ? "series" : "movie",
},
prefetchedOmdbData,
prefetchedWhatsonData
);
useEffect(() => {
const id = requestAnimationFrame(() => setVisible(true));
return () => cancelAnimationFrame(id);
}, []);
const { byChannel } = useDownloads();
const dl = byChannel.get(movie.id);
const downloadState = downloadIconState(dl);
const handleClose = () => {
setVisible(false);
setTimeout(onClose, 300);
};
const { sheetRef, handleProps } = useSheetDrag({ onClose: handleClose, enabled: visible });
const allSources = channelSources(movie);
const hasSources = allSources.length > 1;
const sourceOptions = allSources.map((url, idx) => {
const detail = describeSource(url);
const label = idx === 0 ? "Source 1 (default)" : `Source ${idx + 1}`;
return { value: idx, label: detail ? `${label} · ${detail}` : label };
});
const handlePlay = () => {
const url = allSources[selectedSourceIdx] ?? movie.url;
onPlay(url === movie.url ? movie : withSource(movie, url));
handleClose();
};
// Derived display values
const posterSrc =
whatsonData?.image ??
(omdbData?.posterUrl && omdbData.posterUrl !== "N/A"
? omdbData.posterUrl
: (movie.logoUrl ?? null));
const year = omdbData?.year && omdbData.year !== "N/A" ? omdbData.year : null;
const rated =
whatsonData?.certification ??
(omdbData?.rated && omdbData.rated !== "N/A" ? omdbData.rated : null);
const genre = omdbData?.genre && omdbData.genre !== "N/A" ? omdbData.genre : null;
const runtime = omdbData?.runtime && omdbData.runtime !== "N/A" ? omdbData.runtime : null;
const director = omdbData?.director && omdbData.director !== "N/A" ? omdbData.director : null;
const actors = omdbData?.actors && omdbData.actors !== "N/A" ? omdbData.actors : null;
const plot =
(omdbData?.plot && omdbData.plot !== "N/A" ? omdbData.plot : null) ??
whatsonData?.tagline ??
null;
const truncatedActors = actors && actors.length > 60 ? actors.slice(0, 57) + "..." : actors;
const genreRuntime = [genre, runtime].filter(Boolean).join(" · ");
return (
<div className="fixed inset-0 z-50">
<div
className={`absolute inset-0 bg-black/60 backdrop-blur-xs transition-opacity duration-300 ${
visible ? "opacity-100" : "opacity-0"
}`}
onClick={handleClose}
/>
<div
ref={sheetRef}
className={`absolute bottom-0 left-0 right-0 bg-card rounded-t-2xl shadow-2xl flex flex-col transition-[translate,max-height] duration-300 ease-out motion-reduce:transition-none overflow-hidden ${
visible ? "translate-y-0" : "translate-y-full"
}`}
>
{/* Handle */}
<div
{...handleProps}
className="flex justify-center pt-3 pb-1 shrink-0 select-none"
>
<div className="w-9 h-1 rounded-full bg-border" />
</div>
{/* Close button */}
<div {...handleProps} className="flex justify-end px-5 pt-1 shrink-0 select-none">
<button
onClick={handleClose}
aria-label="Close"
className="text-muted-foreground hover:text-foreground transition-colors"
>
<X className="h-4 w-4" />
</button>
</div>
{/* Side-by-side: movie info (left ~65%) + controls (right ~35%) */}
<div className="flex gap-4 px-5 pb-4 shrink-0">
{/* Poster */}
<div className="w-20 h-28 rounded-xl bg-secondary overflow-hidden shrink-0 flex items-center justify-center">
{posterSrc ? (
<img
src={posterSrc}
alt=""
className="h-full w-full object-cover"
loading="lazy"
/>
) : (
<Clapperboard className="h-8 w-8 text-muted-foreground/30" />
)}
</div>
{/* Movie info */}
<div className="flex flex-col justify-center gap-1.5 flex-2 min-w-0">
{infoLoading ? (
<div className="flex items-center gap-2 text-muted-foreground">
<LoaderCircle className="h-3.5 w-3.5 animate-spin" />
<span className="text-xs">Loading info…</span>
</div>
) : (
<>
{/* Title + year + rated */}
<div className="flex items-baseline gap-1.5 flex-wrap">
<p className="text-base font-semibold leading-tight line-clamp-2">
{movie.name}
</p>
{year && (
<span className="text-xs text-muted-foreground shrink-0">
({year})
</span>
)}
{rated && (
<span className="text-[11px] font-semibold bg-secondary text-muted-foreground px-1.5 py-0.5 rounded shrink-0">
{rated}
</span>
)}
</div>
{/* Ratings row */}
<RatingsRow omdbData={omdbData} whatsonData={whatsonData} />
{/* Genre + runtime */}
{genreRuntime && (
<p className="text-xs text-muted-foreground">{genreRuntime}</p>
)}
{/* Director */}
{director && (
<p className="text-xs text-muted-foreground truncate">
Dir: {director}
</p>
)}
{/* Cast */}
{truncatedActors && (
<p className="text-xs text-muted-foreground">
Cast: {truncatedActors}
</p>
)}
{/* Fallback: no OMDB data */}
{!omdbData &&
(hasOmdbKey ? (
<p className="text-xs text-muted-foreground">— · —</p>
) : (
<OmdbKeyHint onNavigate={onClose} />
))}
</>
)}
</div>
{/* Controls */}
<div className="flex flex-col justify-center gap-2.5 flex-1 min-w-0 shrink-0">
{hasSources && (
<Select
value={selectedSourceIdx}
onChange={setSelectedSourceIdx}
options={sourceOptions}
aria-label="Select source"
/>
)}
<button
onClick={handlePlay}
className="w-full flex items-center justify-center gap-2 bg-primary text-primary-foreground rounded-xl py-2.5 text-sm font-semibold hover:bg-primary/90 active:bg-primary/80 transition-colors"
>
<Play className="h-4 w-4 ml-0.5" />
Play
</button>
{movie.contentType !== "series" && (
<DownloadButton
showLabel
state={downloadState}
onStart={() => void enqueueMovieDownload(movie.id)}
onStop={() => dl && void stopDownload(dl.id)}
onRemove={() => dl && removeDownload(dl.id)}
className="w-full justify-center rounded-xl border border-border py-2.5 text-sm font-semibold hover:bg-accent"
/>
)}
{dl && <RetentionNote records={[dl]} className="px-1" />}
</div>
</div>
{/* Plot — shown below the main row when available */}
{plot && !omdbLoading && (
<div className="px-5 pb-4 shrink-0">
<div className="border-t border-border mb-3" />
<p className="text-xs text-muted-foreground leading-relaxed">{plot}</p>
</div>
)}
<div className="shrink-0 pb-2" />
</div>
</div>
);
};
|