Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Embed video trailer youtube #12 #13

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"preview": "vite preview"
},
"dependencies": {
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slot": "^1.0.2",
"class-variance-authority": "^0.7.0",
Expand Down Expand Up @@ -41,4 +43,4 @@
"typescript": "^5.2.2",
"vite": "^5.1.6"
}
}
}
122 changes: 122 additions & 0 deletions src/components/Dailog.tsx
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind, you don't need to manually create the component, just use the command line provided by shadcn/ui.

pnpm dlx shadcn-ui@latest add dialog

Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
"use client"

import * as React from "react"
import * as DialogPrimitive from "@radix-ui/react-dialog"
import { Cross2Icon } from "@radix-ui/react-icons"

import { cn } from "@/lib/utils"

const Dialog = DialogPrimitive.Root

const DialogTrigger = DialogPrimitive.Trigger

const DialogPortal = DialogPrimitive.Portal

const DialogClose = DialogPrimitive.Close

const DialogOverlay = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Overlay
ref={ref}
className={cn(
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className
)}
{...props}
/>
))
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName

const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
ref={ref}
className={cn(
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
className
)}
{...props}
>
{children}
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<Cross2Icon className="h-4 w-4" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
</DialogPortal>
))
DialogContent.displayName = DialogPrimitive.Content.displayName

const DialogHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col space-y-1.5 text-center sm:text-left",
className
)}
{...props}
/>
)
DialogHeader.displayName = "DialogHeader"

const DialogFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
className
)}
{...props}
/>
)
DialogFooter.displayName = "DialogFooter"

const DialogTitle = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Title
ref={ref}
className={cn(
"text-lg font-semibold leading-none tracking-tight",
className
)}
{...props}
/>
))
DialogTitle.displayName = DialogPrimitive.Title.displayName

const DialogDescription = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Description
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
))
DialogDescription.displayName = DialogPrimitive.Description.displayName

export {
Dialog,
DialogPortal,
DialogOverlay,
DialogTrigger,
DialogClose,
DialogContent,
DialogHeader,
DialogFooter,
DialogTitle,
DialogDescription,
}
28 changes: 18 additions & 10 deletions src/pages/Show/Movie.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link, useParams } from "react-router-dom";
import { useParams } from "react-router-dom";
import useFetch from "@/hooks/useFetch";
import type { Movie as MovieType } from "@/types/movie";
import type { Images, Media, Video } from "@/types/media";
Expand All @@ -18,6 +18,7 @@ import {
} from "@/components/ui/carousel";
import SimilarCardItem from "@/components/SimilarCardItem";
import WatchProviderContainer from "@/components/WatchProviderContainer";
import { Dialog, DialogContent, DialogTrigger, } from "@/components/Dailog";

export default function Movie() {
const params = useParams();
Expand Down Expand Up @@ -106,15 +107,22 @@ export default function Movie() {
</Carousel>
)}
{!!videos?.results.length && (
<Link
className="px-2 py-2 w-auto col-span-2 lg:col-span-1 text-center rounded-md bg-red-700"
to={`https://www.youtube.com/watch?v=${
getVideo(videos?.results)?.key
}`}
target="_blank"
>
Watch Trailer
</Link>
<Dialog>
<DialogTrigger asChild>
<div className="px-2 py-2 w-auto col-span-2 lg:col-span-1 text-center rounded-md bg-red-700 cursor-pointer">Watch Trailer</div>
</DialogTrigger>
<DialogContent className="bg-transparent p-0 border-none">
<iframe width={610}
height={365}
src={`https://www.youtube.com/embed/${getVideo(videos?.results)?.key}`}
title="YouTube video player"
frameBorder={0}
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
referrerPolicy="strict-origin-when-cross-origin"
allowFullScreen={true}
/>
</DialogContent>
</Dialog>
)}
</div>

Expand Down
28 changes: 18 additions & 10 deletions src/pages/Show/Tv.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link, useParams } from "react-router-dom";
import { useParams } from "react-router-dom";
import useFetch from "@/hooks/useFetch";
import type { Response, SimilarMixed, SimilarTv } from "@/types/response";
import type { Season, Tv as TvType } from "@/types/tv";
Expand All @@ -17,6 +17,7 @@ import imageUrl from "@/utils/image-url";
import pickRandomImages from "@/utils/pick-random-images";
import SeasonCardItem from "@/components/SeasonCardItem";
import WatchProviderContainer from "@/components/WatchProviderContainer";
import { Dialog, DialogContent, DialogTrigger, } from "@/components/Dailog";

export default function Tv() {
const params = useParams();
Expand Down Expand Up @@ -98,15 +99,22 @@ export default function Tv() {
</Carousel>
)}
{!!videos?.results.length && (
<Link
className="px-2 py-2 w-auto col-span-2 lg:col-span-1 text-center rounded-md bg-red-700"
to={`https://www.youtube.com/watch?v=${
getVideo(videos?.results)?.key
}`}
target="_blank"
>
Watch Trailer
</Link>
<Dialog>
<DialogTrigger asChild>
<div className="px-2 py-2 w-auto col-span-2 lg:col-span-1 text-center rounded-md bg-red-700 cursor-pointer">Watch Trailer</div>
</DialogTrigger>
<DialogContent className="bg-transparent p-0 border-none">
<iframe width={610}
height={365}
src={`https://www.youtube.com/embed/${getVideo(videos?.results)?.key}`}
title="YouTube video player"
frameBorder={0}
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
referrerPolicy="strict-origin-when-cross-origin"
allowFullScreen={true}
/>
</DialogContent>
</Dialog>
)}
</div>

Expand Down