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,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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user