Add Discovery Videos feature
Let users upload videos, tag them with one or more entries, and watch them from a new Discovery Videos page. Backend: - Add Video and VideoEntry models and relations - Add video controller and /video routes - Add video thumbnail generation service (ffmpeg-static) - Add video upload storage location and config Frontend: - Add DiscoveryVideosPage with sidebar link and route - Add AddVideoDialog, VideoDropzone, EntryMultiSelect, VideoCard and VideoPlayerDialog components - Add discoveryVideos API client and useDiscoveryVideos hook - Add format helpers, video types and normalizers - Add skeleton for the page Docs: - Document the feature in docs-vault
This commit is contained in:
1 parent
4d88747649
commit
eb3a12f6cb
41 files changed
+2163
-15
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import { api } from "@/lib/api";
|
||||
import { normalizeDiscoveryVideo } from "@/lib/normalizers";
|
||||
import type {
|
||||
DiscoveryVideo,
|
||||
DiscoveryVideoPaginatedResponse,
|
||||
} from "@/types";
|
||||
|
||||
export interface UpdateVideoData {
|
||||
title?: string;
|
||||
description?: string;
|
||||
entryIds: number[];
|
||||
}
|
||||
|
||||
export const discoveryVideosApi = {
|
||||
getAll: (page = 1, limit = 24) =>
|
||||
api
|
||||
.get<DiscoveryVideoPaginatedResponse>("/discovery-videos", {
|
||||
params: { page, limit },
|
||||
})
|
||||
.then((r) => ({
|
||||
...r.data,
|
||||
videos: r.data.videos.map(normalizeDiscoveryVideo),
|
||||
})),
|
||||
|
||||
create: (formData: FormData, onProgress?: (percent: number) => void) =>
|
||||
api
|
||||
.post<DiscoveryVideo[]>("/discovery-videos", formData, {
|
||||
headers: { "Content-Type": "multipart/form-data" },
|
||||
onUploadProgress: (e) => {
|
||||
if (onProgress && e.total) {
|
||||
onProgress(Math.round((e.loaded / e.total) * 100));
|
||||
}
|
||||
},
|
||||
})
|
||||
.then((r) => r.data.map(normalizeDiscoveryVideo)),
|
||||
|
||||
update: (id: number, data: UpdateVideoData) =>
|
||||
api
|
||||
.put<DiscoveryVideo>(`/discovery-videos/${id}`, data)
|
||||
.then((r) => normalizeDiscoveryVideo(r.data)),
|
||||
|
||||
remove: (id: number) => api.delete(`/discovery-videos/${id}`).then((r) => r.data),
|
||||
};
|
||||
@@ -34,10 +34,12 @@ export function ConfirmDialog({
|
||||
}: ConfirmDialogProps) {
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent>
|
||||
<DialogContent className="overflow-hidden">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{title}</DialogTitle>
|
||||
<DialogDescription>{description}</DialogDescription>
|
||||
<DialogTitle className="break-all">{title}</DialogTitle>
|
||||
<DialogDescription className="break-all">
|
||||
{description}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
import { useState } from "react";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Progress } from "@/components/ui/progress";
|
||||
import { VideoDropzone } from "./VideoDropzone";
|
||||
import { EntryMultiSelect } from "./EntryMultiSelect";
|
||||
import { useLibrary } from "@/hooks/useEntries";
|
||||
import { useUploadVideos, useUpdateVideo } from "@/hooks/useDiscoveryVideos";
|
||||
import type { DiscoveryVideo } from "@/types";
|
||||
|
||||
interface AddVideoDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
/** When set, the dialog runs in edit mode (no file dropzone). */
|
||||
video?: DiscoveryVideo | null;
|
||||
}
|
||||
|
||||
export function AddVideoDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
video,
|
||||
}: AddVideoDialogProps) {
|
||||
const isEdit = !!video;
|
||||
|
||||
const [files, setFiles] = useState<File[]>([]);
|
||||
const [title, setTitle] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [entryIds, setEntryIds] = useState<number[]>([]);
|
||||
const [progress, setProgress] = useState<number | null>(null);
|
||||
|
||||
const uploadVideos = useUploadVideos();
|
||||
const updateVideo = useUpdateVideo();
|
||||
|
||||
// Warm the library store so the entry picker has data.
|
||||
useLibrary();
|
||||
|
||||
// Reset form state whenever the dialog opens (or switches between
|
||||
// create/edit mode) — the render-phase pattern from the React docs,
|
||||
// which avoids cascading renders from setState-in-effect.
|
||||
const [prevOpen, setPrevOpen] = useState(open);
|
||||
const [prevVideo, setPrevVideo] = useState(video);
|
||||
if (open !== prevOpen || video !== prevVideo) {
|
||||
setPrevOpen(open);
|
||||
setPrevVideo(video);
|
||||
if (open) {
|
||||
setFiles([]);
|
||||
setTitle(video?.title ?? "");
|
||||
setDescription(video?.description ?? "");
|
||||
setEntryIds(video?.entries?.map((e) => e.id) ?? []);
|
||||
setProgress(null);
|
||||
}
|
||||
}
|
||||
|
||||
const isBusy = uploadVideos.isPending || updateVideo.isPending;
|
||||
|
||||
const handleSubmit = () => {
|
||||
if (isEdit && video) {
|
||||
updateVideo.mutate(
|
||||
{ id: video.id, data: { title, description, entryIds } },
|
||||
{ onSuccess: () => onOpenChange(false) },
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (files.length === 0) return;
|
||||
|
||||
const formData = new FormData();
|
||||
files.forEach((file) => formData.append("videos", file));
|
||||
formData.append("description", description);
|
||||
formData.append("entryIds", JSON.stringify(entryIds));
|
||||
|
||||
uploadVideos.mutate(
|
||||
{ formData, onProgress: setProgress },
|
||||
{ onSuccess: () => onOpenChange(false) },
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="overflow-hidden sm:max-w-xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{isEdit ? "Edit video" : "Add media"}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{isEdit
|
||||
? "Update the video details and linked library entries."
|
||||
: "Drop your videos, add a description, and link them to library entries."}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="min-w-0 space-y-4">
|
||||
{!isEdit && (
|
||||
<VideoDropzone
|
||||
files={files}
|
||||
onChange={setFiles}
|
||||
disabled={isBusy}
|
||||
/>
|
||||
)}
|
||||
|
||||
{isEdit && (
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="video-title">Title</Label>
|
||||
<Input
|
||||
id="video-title"
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
disabled={isBusy}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="video-description">Description</Label>
|
||||
<Textarea
|
||||
id="video-description"
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
placeholder="What is this video about? Why did you save it?"
|
||||
rows={3}
|
||||
disabled={isBusy}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<EntryMultiSelect
|
||||
value={entryIds}
|
||||
onChange={setEntryIds}
|
||||
disabled={isBusy}
|
||||
/>
|
||||
|
||||
{progress !== null && !isEdit && (
|
||||
<Progress value={progress} />
|
||||
)}
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => onOpenChange(false)}
|
||||
disabled={isBusy}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
disabled={isBusy || (!isEdit && files.length === 0)}
|
||||
>
|
||||
{isBusy && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
||||
{isEdit
|
||||
? "Save changes"
|
||||
: files.length > 0
|
||||
? `Upload (${files.length})`
|
||||
: "Upload"}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
import { useMemo, useState } from "react";
|
||||
import { Link2, Search, X } from "lucide-react";
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { useLibraryEntries } from "@/stores/useLibraryStore";
|
||||
import { useDebounce } from "@/hooks/useDebounce";
|
||||
import { getPosterUrl } from "@/lib/media-utils";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface EntryMultiSelectProps {
|
||||
value: number[];
|
||||
onChange: (ids: number[]) => void;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export function EntryMultiSelect({
|
||||
value,
|
||||
onChange,
|
||||
disabled,
|
||||
}: EntryMultiSelectProps) {
|
||||
const entries = useLibraryEntries();
|
||||
const [search, setSearch] = useState("");
|
||||
const debouncedSearch = useDebounce(search, 250);
|
||||
|
||||
const hasQuery = debouncedSearch.trim().length > 0;
|
||||
|
||||
// Only list entries once the user starts searching (debounced)
|
||||
const visibleEntries = useMemo(() => {
|
||||
if (!hasQuery) return [];
|
||||
const q = debouncedSearch.trim().toLowerCase();
|
||||
return entries
|
||||
.filter((e) => !e.hidden)
|
||||
.filter((e) => e.title.toLowerCase().includes(q));
|
||||
}, [entries, debouncedSearch, hasQuery]);
|
||||
|
||||
const selectedEntries = useMemo(
|
||||
() => entries.filter((e) => value.includes(e.id)),
|
||||
[entries, value],
|
||||
);
|
||||
|
||||
const toggle = (id: number) => {
|
||||
onChange(
|
||||
value.includes(id) ? value.filter((v) => v !== id) : [...value, id],
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<Popover>
|
||||
<PopoverTrigger
|
||||
disabled={disabled}
|
||||
className={cn(
|
||||
"inline-flex h-8 items-center gap-2 rounded-lg border border-input bg-transparent px-3 text-sm transition-colors hover:bg-muted disabled:pointer-events-none disabled:opacity-50",
|
||||
)}
|
||||
>
|
||||
<Link2 className="size-4" />
|
||||
Link library entries
|
||||
{value.length > 0 && (
|
||||
<span className="rounded-full bg-primary px-1.5 py-0.5 text-[10px] font-medium text-primary-foreground">
|
||||
{value.length}
|
||||
</span>
|
||||
)}
|
||||
</PopoverTrigger>
|
||||
|
||||
<PopoverContent className="w-80 p-0">
|
||||
<div className="border-b p-2">
|
||||
<div className="relative">
|
||||
<Search className="absolute left-2 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
placeholder="Search library…"
|
||||
className="pl-7"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ScrollArea className="h-64">
|
||||
{!hasQuery ? (
|
||||
<p className="p-4 text-center text-sm text-muted-foreground">
|
||||
Type to search your library…
|
||||
</p>
|
||||
) : visibleEntries.length === 0 ? (
|
||||
<p className="p-4 text-center text-sm text-muted-foreground">
|
||||
No entries found.
|
||||
</p>
|
||||
) : (
|
||||
<div className="p-1">
|
||||
{visibleEntries.map((entry) => (
|
||||
<div
|
||||
key={entry.id}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={() => toggle(entry.id)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
toggle(entry.id);
|
||||
}
|
||||
}}
|
||||
className="flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 outline-none hover:bg-accent focus-visible:bg-accent"
|
||||
>
|
||||
<Checkbox
|
||||
checked={value.includes(entry.id)}
|
||||
onCheckedChange={() => toggle(entry.id)}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
tabIndex={-1}
|
||||
/>
|
||||
<img
|
||||
src={getPosterUrl(entry)}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
className="h-9 w-6 shrink-0 rounded object-cover"
|
||||
/>
|
||||
<span className="flex-1 truncate text-sm">
|
||||
{entry.title}
|
||||
</span>
|
||||
{entry.is_tvseries && (
|
||||
<span className="shrink-0 text-[10px] uppercase text-muted-foreground">
|
||||
TV
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</ScrollArea>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
|
||||
{selectedEntries.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{selectedEntries.map((entry) => (
|
||||
<span
|
||||
key={entry.id}
|
||||
className="inline-flex items-center gap-1 rounded-full bg-accent px-2 py-0.5 text-xs text-accent-foreground"
|
||||
>
|
||||
{entry.title}
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-xs"
|
||||
disabled={disabled}
|
||||
onClick={() => toggle(entry.id)}
|
||||
className="text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<X />
|
||||
</Button>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
import { useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { Film, Pencil, Play, Trash2 } from "lucide-react";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { getVideoThumbnailUrl } from "@/lib/api";
|
||||
import { formatBytes } from "@/lib/format";
|
||||
import type { DiscoveryVideo } from "@/types";
|
||||
|
||||
interface VideoCardProps {
|
||||
video: DiscoveryVideo;
|
||||
onPlay: (video: DiscoveryVideo) => void;
|
||||
onEdit: (video: DiscoveryVideo) => void;
|
||||
onDelete: (video: DiscoveryVideo) => void;
|
||||
}
|
||||
|
||||
export function VideoCard({ video, onPlay, onEdit, onDelete }: VideoCardProps) {
|
||||
// If the thumbnail request fails (e.g. unplayable file), fall back to
|
||||
// the placeholder instead of showing a broken image.
|
||||
const [thumbFailed, setThumbFailed] = useState(false);
|
||||
|
||||
return (
|
||||
<Card className="group flex h-full flex-col overflow-hidden">
|
||||
{/* Thumbnail + play overlay → opens the player dialog */}
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={() => onPlay(video)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
onPlay(video);
|
||||
}
|
||||
}}
|
||||
className="relative h-44 w-full cursor-pointer overflow-hidden bg-muted outline-none"
|
||||
>
|
||||
{/* Placeholder (visible while the thumbnail loads or if it fails) */}
|
||||
<div className="absolute inset-0 flex items-center justify-center">
|
||||
<Film className="h-8 w-8 text-muted-foreground/40" />
|
||||
</div>
|
||||
|
||||
{/* Requesting the thumbnail also triggers on-demand generation
|
||||
server-side when the video doesn't have one yet. */}
|
||||
{!thumbFailed && (
|
||||
<img
|
||||
src={getVideoThumbnailUrl(video.id)}
|
||||
alt={video.title}
|
||||
loading="lazy"
|
||||
onError={() => setThumbFailed(true)}
|
||||
className="relative h-full w-full object-cover transition-transform duration-300 group-hover:scale-105"
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="absolute inset-0 flex items-center justify-center bg-black/30 transition-colors hover:bg-black/20">
|
||||
<span className="flex h-12 w-12 items-center justify-center rounded-full bg-primary text-primary-foreground shadow-lg transition-transform group-hover:scale-110">
|
||||
<Play className="ml-1 h-5 w-5" />
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className="absolute right-2 top-2 z-10 flex gap-1 opacity-0 transition-opacity group-hover:opacity-100"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="icon-sm"
|
||||
onClick={() => onEdit(video)}
|
||||
aria-label="Edit video"
|
||||
>
|
||||
<Pencil />
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="icon-sm"
|
||||
onClick={() => onDelete(video)}
|
||||
aria-label="Delete video"
|
||||
>
|
||||
<Trash2 />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-2 p-3">
|
||||
<div className="flex h-5 items-start justify-between gap-2">
|
||||
<h3
|
||||
className="line-clamp-1 min-w-0 break-all text-sm font-medium"
|
||||
title={video.title}
|
||||
>
|
||||
{video.title}
|
||||
</h3>
|
||||
<span className="shrink-0 text-[10px] text-muted-foreground">
|
||||
{formatBytes(video.size)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Fixed-height description area keeps all cards the same size */}
|
||||
<p className="h-8 line-clamp-2 text-xs text-muted-foreground">
|
||||
{video.description || ""}
|
||||
</p>
|
||||
|
||||
{/* Single-row chips — extra entries get clipped, never grow the card */}
|
||||
<div className="h-5 overflow-hidden">
|
||||
{video.entries && video.entries.length > 0 && (
|
||||
<div className="flex gap-1.5 overflow-hidden">
|
||||
{video.entries.map((entry) => (
|
||||
<Link
|
||||
key={entry.id}
|
||||
to={`/entry/${entry.id}`}
|
||||
className="shrink-0 rounded-full bg-accent px-2 py-0.5 text-[10px] text-accent-foreground transition-colors hover:bg-accent/70"
|
||||
>
|
||||
{entry.title}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
import { useRef, useState, type DragEvent } from "react";
|
||||
import { FileVideo, UploadCloud, X } from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { formatBytes } from "@/lib/format";
|
||||
|
||||
const ALLOWED_MIME = [
|
||||
"video/mp4",
|
||||
"video/webm",
|
||||
"video/quicktime",
|
||||
"video/x-matroska",
|
||||
"video/x-msvideo",
|
||||
];
|
||||
const ALLOWED_EXT = ["mp4", "webm", "mov", "m4v", "mkv", "avi"];
|
||||
const MAX_FILES = 10;
|
||||
|
||||
function isAccepted(file: File) {
|
||||
if (ALLOWED_MIME.includes(file.type)) return true;
|
||||
const ext = file.name.split(".").pop()?.toLowerCase() ?? "";
|
||||
return ALLOWED_EXT.includes(ext);
|
||||
}
|
||||
|
||||
interface VideoDropzoneProps {
|
||||
files: File[];
|
||||
onChange: (files: File[]) => void;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export function VideoDropzone({ files, onChange, disabled }: VideoDropzoneProps) {
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const [dragActive, setDragActive] = useState(false);
|
||||
|
||||
const addFiles = (incoming: FileList | null) => {
|
||||
if (!incoming || disabled) return;
|
||||
|
||||
const existing = new Set(files.map((f) => `${f.name}:${f.size}`));
|
||||
const fresh = Array.from(incoming)
|
||||
.filter(isAccepted)
|
||||
.filter((f) => !existing.has(`${f.name}:${f.size}`))
|
||||
.slice(0, MAX_FILES - files.length);
|
||||
|
||||
if (fresh.length > 0) {
|
||||
onChange([...files, ...fresh]);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDrop = (e: DragEvent<HTMLDivElement>) => {
|
||||
e.preventDefault();
|
||||
setDragActive(false);
|
||||
addFiles(e.dataTransfer.files);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={() => inputRef.current?.click()}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
inputRef.current?.click();
|
||||
}
|
||||
}}
|
||||
onDragOver={(e) => {
|
||||
e.preventDefault();
|
||||
setDragActive(true);
|
||||
}}
|
||||
onDragLeave={() => setDragActive(false)}
|
||||
onDrop={handleDrop}
|
||||
className={cn(
|
||||
"flex cursor-pointer flex-col items-center justify-center gap-2 rounded-lg border-2 border-dashed p-8 text-center outline-none transition-colors",
|
||||
dragActive ? "border-primary bg-primary/5" : "border-border",
|
||||
disabled && "pointer-events-none opacity-50",
|
||||
)}
|
||||
>
|
||||
<UploadCloud className="h-8 w-8 text-muted-foreground" />
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Drag & drop videos here, or{" "}
|
||||
<span className="font-medium text-primary underline">
|
||||
browse files
|
||||
</span>
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground/70">
|
||||
mp4, webm, mov, m4v, mkv, avi — up to 10 files per upload
|
||||
</p>
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="file"
|
||||
accept="video/*"
|
||||
multiple
|
||||
className="hidden"
|
||||
onChange={(e) => {
|
||||
addFiles(e.target.files);
|
||||
e.target.value = "";
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{files.length > 0 && (
|
||||
<ul className="max-h-44 space-y-1.5 overflow-y-auto pr-1">
|
||||
{files.map((file, index) => (
|
||||
<li
|
||||
key={`${file.name}-${file.size}-${index}`}
|
||||
className="flex items-center gap-2 rounded-md border px-3 py-2 text-sm"
|
||||
>
|
||||
<FileVideo className="size-4 shrink-0 text-muted-foreground" />
|
||||
{/* break-all: a long filename wraps instead of forcing the
|
||||
dialog wider; line-clamp caps it at two lines */}
|
||||
<span
|
||||
className="min-w-0 flex-1 break-all line-clamp-2"
|
||||
title={file.name}
|
||||
>
|
||||
{file.name}
|
||||
</span>
|
||||
<span className="shrink-0 text-xs text-muted-foreground">
|
||||
{formatBytes(file.size)}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
onClick={() =>
|
||||
onChange(files.filter((_, idx) => idx !== index))
|
||||
}
|
||||
className="shrink-0 text-muted-foreground transition-colors hover:text-foreground"
|
||||
>
|
||||
<X className="size-4" />
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { ChevronDown, ChevronUp, Pencil } from "lucide-react";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { getVideoStreamUrl } from "@/lib/api";
|
||||
import { formatBytes } from "@/lib/format";
|
||||
import type { DiscoveryVideo } from "@/types";
|
||||
|
||||
interface VideoPlayerDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
video: DiscoveryVideo | null;
|
||||
onPrevious?: () => void;
|
||||
onNext?: () => void;
|
||||
hasPrevious?: boolean;
|
||||
hasNext?: boolean;
|
||||
onEdit?: (video: DiscoveryVideo) => void;
|
||||
}
|
||||
|
||||
export function VideoPlayerDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
video,
|
||||
onPrevious,
|
||||
onNext,
|
||||
hasPrevious,
|
||||
hasNext,
|
||||
onEdit,
|
||||
}: VideoPlayerDialogProps) {
|
||||
const videoRef = useRef<HTMLVideoElement>(null);
|
||||
|
||||
// Autoplay when the dialog opens or the video changes. The play() call may
|
||||
// be blocked if the browser considers the gesture consumed — the user can
|
||||
// always press play manually.
|
||||
useEffect(() => {
|
||||
if (open && video) {
|
||||
videoRef.current?.play().catch(() => {});
|
||||
}
|
||||
}, [open, video]);
|
||||
|
||||
// Arrow-key navigation. ↑/↓ always switch videos (when available) and are
|
||||
// captured in the CAPTURE phase with preventDefault, so they never reach
|
||||
// the <video> element's native controls or move focus onto the player.
|
||||
// ←/→ switch videos too, except when the player itself is focused — there
|
||||
// they keep their native seek behaviour.
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
const isVideoFocused = e.target instanceof HTMLVideoElement;
|
||||
|
||||
if (e.key === "ArrowUp" || e.key === "ArrowDown") {
|
||||
e.preventDefault();
|
||||
if (e.key === "ArrowUp" && hasPrevious) onPrevious?.();
|
||||
if (e.key === "ArrowDown" && hasNext) onNext?.();
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!isVideoFocused &&
|
||||
(e.key === "ArrowLeft" || e.key === "ArrowRight")
|
||||
) {
|
||||
e.preventDefault();
|
||||
if (e.key === "ArrowLeft" && hasPrevious) onPrevious?.();
|
||||
if (e.key === "ArrowRight" && hasNext) onNext?.();
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener("keydown", onKey, true);
|
||||
return () => window.removeEventListener("keydown", onKey, true);
|
||||
}, [open, hasPrevious, hasNext, onPrevious, onNext]);
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="overflow-hidden sm:max-w-4xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="truncate pr-8">{video?.title}</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
{open && video && (
|
||||
<div className="space-y-4">
|
||||
<div className="relative bg-black">
|
||||
{/* tabIndex=-1 keeps the player out of the focus order so the
|
||||
dialog doesn't focus it and arrow keys stay ours */}
|
||||
<video
|
||||
key={video.id}
|
||||
ref={videoRef}
|
||||
src={getVideoStreamUrl(video.id)}
|
||||
controls
|
||||
autoPlay
|
||||
tabIndex={-1}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "ArrowUp" || e.key === "ArrowDown") {
|
||||
e.preventDefault();
|
||||
}
|
||||
}}
|
||||
className="max-h-[65vh] w-full"
|
||||
/>
|
||||
|
||||
{hasPrevious && (
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="icon"
|
||||
onClick={onPrevious}
|
||||
aria-label="Previous video"
|
||||
className="absolute left-2 top-1/2 -translate-y-1/2 opacity-70"
|
||||
>
|
||||
<ChevronUp />
|
||||
</Button>
|
||||
)}
|
||||
{hasNext && (
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="icon"
|
||||
onClick={onNext}
|
||||
aria-label="Next video"
|
||||
className="absolute right-2 top-1/2 -translate-y-1/2 opacity-70"
|
||||
>
|
||||
<ChevronDown />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{formatBytes(video.size)}
|
||||
</span>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
{video.entries?.map((entry) => (
|
||||
<Link
|
||||
key={entry.id}
|
||||
to={`/entry/${entry.id}`}
|
||||
onClick={() => onOpenChange(false)}
|
||||
className="rounded-full bg-accent px-2 py-0.5 text-[10px] text-accent-foreground transition-colors hover:bg-accent/70"
|
||||
>
|
||||
{entry.title}
|
||||
</Link>
|
||||
))}
|
||||
{onEdit && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="xs"
|
||||
onClick={() => onEdit(video)}
|
||||
>
|
||||
<Pencil />
|
||||
Edit
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{video.description && (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{video.description}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{(hasPrevious || hasNext) && (
|
||||
<p className="text-center text-[10px] text-muted-foreground/60">
|
||||
Use ↑ / ↓ to switch videos
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
Moon,
|
||||
Sun,
|
||||
Film,
|
||||
Video,
|
||||
} from "lucide-react";
|
||||
import { useThemeStore } from "@/stores/useThemeStore";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
@@ -27,6 +28,7 @@ const libraryNav = [
|
||||
{ to: "/watchlist", icon: ListVideo, label: "Watchlist" },
|
||||
{ to: "/collections", icon: FolderOpen, label: "Collections" },
|
||||
{ to: "/media", icon: Image, label: "Media" },
|
||||
{ to: "/discovery-videos", icon: Video, label: "Discover" },
|
||||
];
|
||||
|
||||
const otherNav = [
|
||||
|
||||
@@ -314,3 +314,26 @@ export function SettingsSkeleton() {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function DiscoveryVideosSkeleton() {
|
||||
return (
|
||||
<div className="space-y-6 animate-in fade-in duration-300">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-40" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
</div>
|
||||
<Skeleton className="h-8 w-28 rounded-lg" />
|
||||
</div>
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<div key={i} className="space-y-2">
|
||||
<Skeleton className="aspect-video w-full rounded-lg" />
|
||||
<Skeleton className="h-4 w-3/4" />
|
||||
<Skeleton className="h-3 w-full" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -83,7 +83,7 @@ function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="dialog-header"
|
||||
className={cn("flex flex-col gap-2", className)}
|
||||
className={cn("flex min-w-0 flex-col gap-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import { useInfiniteQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
discoveryVideosApi,
|
||||
type UpdateVideoData,
|
||||
} from "@/api/discoveryVideos";
|
||||
|
||||
export const discoveryVideoKeys = {
|
||||
all: ["discovery-videos"] as const,
|
||||
};
|
||||
|
||||
export function useDiscoveryVideos() {
|
||||
return useInfiniteQuery({
|
||||
queryKey: discoveryVideoKeys.all,
|
||||
queryFn: ({ pageParam }) =>
|
||||
discoveryVideosApi.getAll((pageParam as number) ?? 1, 24),
|
||||
initialPageParam: 1,
|
||||
getNextPageParam: (lastPage) =>
|
||||
lastPage.page < lastPage.totalPages ? lastPage.page + 1 : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
export function useUploadVideos() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
formData,
|
||||
onProgress,
|
||||
}: {
|
||||
formData: FormData;
|
||||
onProgress?: (percent: number) => void;
|
||||
}) => discoveryVideosApi.create(formData, onProgress),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: discoveryVideoKeys.all });
|
||||
toast.success("Video uploaded successfully");
|
||||
},
|
||||
onError: () => {
|
||||
toast.error("Failed to upload video");
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateVideo() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ id, data }: { id: number; data: UpdateVideoData }) =>
|
||||
discoveryVideosApi.update(id, data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: discoveryVideoKeys.all });
|
||||
toast.success("Video updated");
|
||||
},
|
||||
onError: () => {
|
||||
toast.error("Failed to update video");
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteVideo() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (id: number) => discoveryVideosApi.remove(id),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: discoveryVideoKeys.all });
|
||||
toast.success("Video deleted");
|
||||
},
|
||||
onError: () => {
|
||||
toast.error("Failed to delete video");
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -28,5 +28,19 @@ export const getMediaUrl = (
|
||||
file: string,
|
||||
) => `${API_BASE_URL}/media/${category}/${type}/${size}/${file}`;
|
||||
|
||||
export const getVideoStreamUrl = (id: number) => {
|
||||
const token = useAuthStore.getState().token;
|
||||
return `${API_BASE_URL}/discovery-videos/${id}/stream${
|
||||
token ? `?token=${encodeURIComponent(token)}` : ''
|
||||
}`;
|
||||
};
|
||||
|
||||
export const getVideoThumbnailUrl = (id: number) => {
|
||||
const token = useAuthStore.getState().token;
|
||||
return `${API_BASE_URL}/discovery-videos/${id}/thumbnail${
|
||||
token ? `?token=${encodeURIComponent(token)}` : ''
|
||||
}`;
|
||||
};
|
||||
|
||||
export const getTmdbImageUrl = (path: string, size = 'w342') =>
|
||||
`https://image.tmdb.org/t/p/${size}${path}`;
|
||||
@@ -0,0 +1,11 @@
|
||||
export function formatBytes(bytes: number): string {
|
||||
if (!bytes || bytes <= 0) return "0 B";
|
||||
const units = ["B", "KB", "MB", "GB", "TB"];
|
||||
let value = bytes;
|
||||
let unit = 0;
|
||||
while (value >= 1024 && unit < units.length - 1) {
|
||||
value /= 1024;
|
||||
unit += 1;
|
||||
}
|
||||
return `${value.toFixed(unit === 0 ? 0 : 1)} ${units[unit]}`;
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
* - Genres come as string arrays from the backend mapper
|
||||
*/
|
||||
|
||||
import type { Entry, Collection, Media, Credit, Genre } from "@/types";
|
||||
import type { Entry, Collection, Media, Credit, Genre, DiscoveryVideo } from "@/types";
|
||||
|
||||
/* ---------- Media ---------- */
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
@@ -87,6 +87,25 @@ export function normalizeEntry(raw: any): Entry {
|
||||
};
|
||||
}
|
||||
|
||||
/* ---------- Discovery Video ---------- */
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function normalizeDiscoveryVideo(raw: any): DiscoveryVideo {
|
||||
return {
|
||||
id: raw.id,
|
||||
title: raw.title,
|
||||
description: raw.description ?? null,
|
||||
filename: raw.filename,
|
||||
original_name: raw.original_name ?? raw.originalName ?? "",
|
||||
mime_type: raw.mime_type ?? raw.mimeType ?? "",
|
||||
size: raw.size ?? 0,
|
||||
duration: raw.duration ?? null,
|
||||
thumbnail_path: raw.thumbnail_path ?? raw.thumbnailPath ?? null,
|
||||
createdAt: raw.createdAt,
|
||||
updatedAt: raw.updatedAt,
|
||||
entries: raw.entries ? raw.entries.map(normalizeEntry) : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
/* ---------- Collection ---------- */
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function normalizeCollection(raw: any): Collection {
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { Clapperboard, Loader2, Plus } from "lucide-react";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { VideoCard } from "@/components/discovery-videos/VideoCard";
|
||||
import { VideoPlayerDialog } from "@/components/discovery-videos/VideoPlayerDialog";
|
||||
import { AddVideoDialog } from "@/components/discovery-videos/AddVideoDialog";
|
||||
import { ConfirmDialog } from "@/components/dialogs/ConfirmDialog";
|
||||
import { useLibrary } from "@/hooks/useEntries";
|
||||
import { useDiscoveryVideos, useDeleteVideo } from "@/hooks/useDiscoveryVideos";
|
||||
import type { DiscoveryVideo } from "@/types";
|
||||
|
||||
function VideoCardSkeleton() {
|
||||
return (
|
||||
<Card className="flex h-full flex-col overflow-hidden">
|
||||
<div className="h-44 w-full bg-muted" />
|
||||
{/* Mirror the fixed body heights of VideoCard */}
|
||||
<div className="flex flex-col gap-2 p-3">
|
||||
<Skeleton className="h-5 w-3/4" />
|
||||
<Skeleton className="h-8 w-full" />
|
||||
<Skeleton className="h-5 w-1/2" />
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
export function DiscoveryVideosPage() {
|
||||
useLibrary(); // warm the library store for the entry picker
|
||||
|
||||
const [addOpen, setAddOpen] = useState(false);
|
||||
const [editingVideo, setEditingVideo] = useState<DiscoveryVideo | null>(null);
|
||||
const [deletingVideo, setDeletingVideo] = useState<DiscoveryVideo | null>(
|
||||
null,
|
||||
);
|
||||
const [playerIndex, setPlayerIndex] = useState<number | null>(null);
|
||||
|
||||
const query = useDiscoveryVideos();
|
||||
const deleteVideo = useDeleteVideo();
|
||||
|
||||
// Flatten + dedupe pages
|
||||
const videos = (() => {
|
||||
const seen = new Set<number>();
|
||||
return (query.data?.pages.flatMap((p) => p.videos) ?? []).filter((v) => {
|
||||
if (seen.has(v.id)) return false;
|
||||
seen.add(v.id);
|
||||
return true;
|
||||
});
|
||||
})();
|
||||
|
||||
// Infinite scroll via IntersectionObserver
|
||||
const sentinelRef = useRef<HTMLDivElement>(null);
|
||||
const { hasNextPage, isFetchingNextPage, fetchNextPage } = query;
|
||||
const handleIntersect = useCallback(
|
||||
(entries: IntersectionObserverEntry[]) => {
|
||||
if (
|
||||
entries[0]?.isIntersecting &&
|
||||
hasNextPage &&
|
||||
!isFetchingNextPage
|
||||
) {
|
||||
void fetchNextPage();
|
||||
}
|
||||
},
|
||||
[hasNextPage, isFetchingNextPage, fetchNextPage],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const el = sentinelRef.current;
|
||||
if (!el) return;
|
||||
const observer = new IntersectionObserver(handleIntersect, {
|
||||
rootMargin: "400px",
|
||||
});
|
||||
observer.observe(el);
|
||||
return () => observer.disconnect();
|
||||
}, [handleIntersect]);
|
||||
|
||||
const handleConfirmDelete = () => {
|
||||
if (!deletingVideo) return;
|
||||
deleteVideo.mutate(deletingVideo.id, {
|
||||
onSuccess: () => setDeletingVideo(null),
|
||||
});
|
||||
};
|
||||
|
||||
const openEdit = (video: DiscoveryVideo) => {
|
||||
setEditingVideo(video);
|
||||
setAddOpen(true);
|
||||
};
|
||||
|
||||
const openPlayer = (video: DiscoveryVideo) => {
|
||||
const index = videos.findIndex((v) => v.id === video.id);
|
||||
if (index !== -1) setPlayerIndex(index);
|
||||
};
|
||||
|
||||
const playerVideo = playerIndex !== null ? videos[playerIndex] : null;
|
||||
|
||||
const editFromPlayer = (video: DiscoveryVideo) => {
|
||||
setPlayerIndex(null);
|
||||
openEdit(video);
|
||||
};
|
||||
|
||||
const closeAdd = (open: boolean) => {
|
||||
setAddOpen(open);
|
||||
if (!open) setEditingVideo(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="animate-page-enter space-y-6">
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold">Discover</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Your saved videos — recommendations, and more.
|
||||
</p>
|
||||
</div>
|
||||
<Button onClick={() => setAddOpen(true)}>
|
||||
<Plus />
|
||||
Add media
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{query.isLoading ? (
|
||||
<div className="grid grid-cols-[repeat(auto-fill,minmax(240px,1fr))] items-start gap-4">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<VideoCardSkeleton key={i} />
|
||||
))}
|
||||
</div>
|
||||
) : videos.length === 0 ? (
|
||||
<div className="flex flex-col items-center gap-3 rounded-xl border border-dashed p-12 text-center">
|
||||
<Clapperboard className="h-10 w-10 text-muted-foreground" />
|
||||
<p className="max-w-sm text-sm text-muted-foreground">
|
||||
No videos yet. Drop your first video and start building your watch
|
||||
pile.
|
||||
</p>
|
||||
<Button onClick={() => setAddOpen(true)}>
|
||||
<Plus />
|
||||
Add media
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
/* items-start: cards keep their own fixed size — a row never
|
||||
stretches smaller cards to follow the biggest one */
|
||||
<div className="grid grid-cols-[repeat(auto-fill,minmax(240px,1fr))] items-start gap-4">
|
||||
{videos.map((video, index) => (
|
||||
<div
|
||||
key={video.id}
|
||||
className="animate-card-enter"
|
||||
style={{ animationDelay: `${Math.min(index * 20, 300)}ms` }}
|
||||
>
|
||||
<VideoCard
|
||||
video={video}
|
||||
onPlay={openPlayer}
|
||||
onEdit={openEdit}
|
||||
onDelete={setDeletingVideo}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Infinite scroll sentinel */}
|
||||
<div ref={sentinelRef} className="flex justify-center py-4">
|
||||
{query.isFetchingNextPage && (
|
||||
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
|
||||
)}
|
||||
</div>
|
||||
|
||||
<AddVideoDialog open={addOpen} onOpenChange={closeAdd} video={editingVideo} />
|
||||
|
||||
<VideoPlayerDialog
|
||||
open={playerIndex !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setPlayerIndex(null);
|
||||
}}
|
||||
video={playerVideo}
|
||||
hasPrevious={playerIndex !== null && playerIndex > 0}
|
||||
hasNext={playerIndex !== null && playerIndex < videos.length - 1}
|
||||
onPrevious={() =>
|
||||
setPlayerIndex((i) => (i !== null ? Math.max(0, i - 1) : i))
|
||||
}
|
||||
onNext={() =>
|
||||
setPlayerIndex((i) =>
|
||||
i !== null ? Math.min(videos.length - 1, i + 1) : i,
|
||||
)
|
||||
}
|
||||
onEdit={editFromPlayer}
|
||||
/>
|
||||
|
||||
<ConfirmDialog
|
||||
open={!!deletingVideo}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setDeletingVideo(null);
|
||||
}}
|
||||
title="Delete video?"
|
||||
description={
|
||||
deletingVideo
|
||||
? `"${deletingVideo.title}" will be permanently removed from disk.`
|
||||
: ""
|
||||
}
|
||||
confirmLabel="Delete"
|
||||
variant="destructive"
|
||||
isLoading={deleteVideo.isPending}
|
||||
onConfirm={handleConfirmDelete}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import { useCommandPaletteStore } from "@/stores/useCommandPaletteStore";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { Star, Plus, Loader2, ExternalLink } from "lucide-react";
|
||||
import { Plus, Loader2, ExternalLink } from "lucide-react";
|
||||
import { EntryDetailsSkeleton } from "@/components/skeletons/PageSkeletons";
|
||||
import { CastList } from "@/components/entries/CastList";
|
||||
import { getYear, formatRuntime } from "@/lib/media-utils";
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
MediaSkeleton,
|
||||
CalendarSkeleton,
|
||||
SettingsSkeleton,
|
||||
DiscoveryVideosSkeleton,
|
||||
} from "@/components/skeletons/PageSkeletons";
|
||||
|
||||
// Lazy-loaded pages
|
||||
@@ -94,6 +95,11 @@ const PersonDetailsPage = lazy(() =>
|
||||
const SettingsPage = lazy(() =>
|
||||
import("@/pages/SettingsPage").then((m) => ({ default: m.SettingsPage })),
|
||||
);
|
||||
const DiscoveryVideosPage = lazy(() =>
|
||||
import("@/pages/DiscoveryVideosPage").then((m) => ({
|
||||
default: m.DiscoveryVideosPage,
|
||||
})),
|
||||
);
|
||||
const DiscoverPage = lazy(() =>
|
||||
import("@/pages/DiscoverPage").then((m) => ({ default: m.DiscoverPage })),
|
||||
);
|
||||
@@ -192,6 +198,14 @@ export const router = createRouter([
|
||||
</SuspensePage>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: "/discovery-videos",
|
||||
element: (
|
||||
<SuspensePage fallback={<DiscoveryVideosSkeleton />}>
|
||||
<DiscoveryVideosPage />
|
||||
</SuspensePage>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: "/calendar",
|
||||
element: (
|
||||
|
||||
@@ -232,6 +232,30 @@ export interface Statistics {
|
||||
totalWatchTime: number;
|
||||
}
|
||||
|
||||
// Discovery videos (personal video vault)
|
||||
export interface DiscoveryVideo {
|
||||
id: number;
|
||||
title: string;
|
||||
description: string | null;
|
||||
filename: string;
|
||||
original_name: string;
|
||||
mime_type: string;
|
||||
size: number;
|
||||
duration: number | null;
|
||||
thumbnail_path: string | null;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
entries?: Entry[];
|
||||
}
|
||||
|
||||
export interface DiscoveryVideoPaginatedResponse {
|
||||
videos: DiscoveryVideo[];
|
||||
page: number;
|
||||
limit: number;
|
||||
total: number;
|
||||
totalPages: number;
|
||||
}
|
||||
|
||||
// TMDB types for discover/search
|
||||
export interface TmdbEntry {
|
||||
id: number;
|
||||
|
||||
Reference in new issue
Block a user