diff --git a/components/playlist/index.tsx b/components/playlist/index.tsx index efb4dd9..c14f283 100644 --- a/components/playlist/index.tsx +++ b/components/playlist/index.tsx @@ -6,19 +6,24 @@ import aydym from "@/public/aydym-com.webp"; import horjun from "@/public/horjun.png"; import belet from "@/public/belet.jpg"; import { v4 } from "uuid"; -import { useRouter, useSearchParams } from "next/navigation"; +import { usePathname, useRouter, useSearchParams } from "next/navigation"; import { useQuery } from "@tanstack/react-query"; import { Queries } from "@/api/queries"; import Loader from "../Loader"; +import { Button } from "../ui/button"; const PlaylistVideos = ({ id, data }: { id: string; data: any }) => { const searchParams = useSearchParams(); const videoId = searchParams.get("video"); + const nextVideo = (Number(videoId) + 1) % data?.data?.length; return (
- +
{data?.data.map( @@ -41,11 +46,19 @@ const PlaylistVideos = ({ id, data }: { id: string; data: any }) => { export default PlaylistVideos; -const InfoBlock = ({ video_id }: { video_id: number }) => { +const InfoBlock = ({ + video_id, + nextId, +}: { + video_id: number; + nextId: number; +}) => { const { data, isFetching, error } = useQuery({ queryKey: ["video", video_id], queryFn: () => Queries.getVideo(video_id), }); + const router = useRouter(); + const pathName = usePathname(); if (isFetching) return ( @@ -63,7 +76,7 @@ const InfoBlock = ({ video_id }: { video_id: number }) => {
- +
@@ -72,6 +85,26 @@ const InfoBlock = ({ video_id }: { video_id: number }) => { {data?.data.desc}

) : null} + {data?.data?.aydym_com_url || data?.data?.horjun_content_url || @@ -142,9 +175,11 @@ const InfoBlock = ({ video_id }: { video_id: number }) => { ); }; -const VideoPlayer = ({ content }: { content: any }) => { +const VideoPlayer = ({ content, nextId }: { content: any; nextId: number }) => { const [hasWindow, setHasWindow] = useState(false); const [data, setData] = useState(content); + const router = useRouter(); + const pathName = usePathname(); useEffect(() => { if (typeof window !== "undefined") { @@ -166,6 +201,7 @@ const VideoPlayer = ({ content }: { content: any }) => { controlsList={data?.is_downloadable === 0 ? "nodownload" : ""} // Conditionally enable/disable download poster={data?.banner_url} playsInline + onEnded={() => router.push(`${pathName}?video=${nextId}`)} > @@ -186,6 +222,7 @@ const VideoPlayer = ({ content }: { content: any }) => { controls controlsList={data?.is_downloadable === 0 ? "nodownload" : ""} // Conditionally enable/disable download className="w-full rounded bg-white" + onEnded={() => router.push(`${pathName}?video=${nextId}`)} >