diff --git a/app/(main)/playlist/[id]/page.tsx b/app/(main)/playlist/[id]/page.tsx index d998680..636a81b 100644 --- a/app/(main)/playlist/[id]/page.tsx +++ b/app/(main)/playlist/[id]/page.tsx @@ -1,5 +1,6 @@ import { getPlaylistById } from "@/api/queries"; import PlaylistVideos from "@/components/playlist"; +import { notFound, redirect } from "next/navigation"; interface IParams { params: { @@ -12,6 +13,10 @@ const Page = async ({ params }: IParams) => { const videos = await getPlaylistById(id); + if (videos?.data?.length === 0) { + notFound(); + } + return (
diff --git a/components/playlist/index.tsx b/components/playlist/index.tsx index 54a9f3a..efb4dd9 100644 --- a/components/playlist/index.tsx +++ b/components/playlist/index.tsx @@ -6,26 +6,31 @@ 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 { useQuery } from "@tanstack/react-query"; +import { Queries } from "@/api/queries"; +import Loader from "../Loader"; const PlaylistVideos = ({ id, data }: { id: string; data: any }) => { - const [index, setIndex] = useState(0); + const searchParams = useSearchParams(); + const videoId = searchParams.get("video"); return (
- +
{data?.data.map( (item: any, i: number) => - i !== index && ( - + ) )}
@@ -36,91 +41,106 @@ const PlaylistVideos = ({ id, data }: { id: string; data: any }) => { export default PlaylistVideos; -const InfoBlock = ({ data }: { data: any }) => ( -
-
-
-
-
-
-
- -
+const InfoBlock = ({ video_id }: { video_id: number }) => { + const { data, isFetching, error } = useQuery({ + queryKey: ["video", video_id], + queryFn: () => Queries.getVideo(video_id), + }); -
- {data?.desc ? ( -

- {data.desc} -

- ) : null} + if (isFetching) + return ( +
+ +
+ ); + if (error) return

{JSON.stringify(error)}

; - {data?.aydym_com_url || - data?.horjun_content_url || - data?.belet_url ? ( -
-

- Beýleki platformalarda seret: -

-
- {data.aydym_com_url ? ( - -
- Aydym.com -
-

Aydym.com

- - ) : null} - {data.horjun_content_url ? ( - -
- HorjunTv -
-

HorjunTv

- - ) : null} - {data.belet_url ? ( - -
- BeletTv -
-

BeletFilm

- - ) : null} + return ( +
+
+
+
+
+
+
+ +
+ +
+ {data?.data?.desc ? ( +

+ {data?.data.desc} +

+ ) : null} + + {data?.data?.aydym_com_url || + data?.data?.horjun_content_url || + data?.data?.belet_url ? ( +
+

+ Beýleki platformalarda seret: +

+
+ {data?.data.aydym_com_url ? ( + +
+ Aydym.com +
+

Aydym.com

+ + ) : null} + {data?.data.horjun_content_url ? ( + +
+ HorjunTv +
+

HorjunTv

+ + ) : null} + {data?.data.belet_url ? ( + +
+ BeletTv +
+

BeletFilm

+ + ) : null} +
-
- ) : null} + ) : null} +
-
-); + ); +}; const VideoPlayer = ({ content }: { content: any }) => { const [hasWindow, setHasWindow] = useState(false);