|
|
@ -34,16 +34,33 @@ export const Watch: Component = () => {
|
|
|
|
|
|
|
|
|
|
|
|
const searchParams = useSearchParams();
|
|
|
|
const searchParams = useSearchParams();
|
|
|
|
|
|
|
|
|
|
|
|
const videoId = searchParams.get("v") as string;
|
|
|
|
const videoId = useMemo(() => {
|
|
|
|
|
|
|
|
const param = searchParams.get("v");
|
|
|
|
|
|
|
|
|
|
|
|
const videoIdIsInvalid = useMemo(() => videoId === null, [videoId]);
|
|
|
|
if (param === null) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return param;
|
|
|
|
|
|
|
|
}, [searchParams]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const timestamp = useMemo(() => {
|
|
|
|
|
|
|
|
const param = searchParams.get("t");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (param === null) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const time = parseInt(param);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isNaN(time)) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return time;
|
|
|
|
|
|
|
|
}, [searchParams]);
|
|
|
|
|
|
|
|
|
|
|
|
const { data, isLoading, error } = useQuery({
|
|
|
|
const { data, isLoading, error } = useQuery({
|
|
|
|
queryKey: ["watch", videoId],
|
|
|
|
queryKey: ["watch", videoId],
|
|
|
|
queryFn: () => {
|
|
|
|
queryFn: () => {
|
|
|
|
|
|
|
|
if (!videoId) return;
|
|
|
|
return client.getWatchable(videoId);
|
|
|
|
return client.getWatchable(videoId);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
enabled: !videoIdIsInvalid
|
|
|
|
enabled: !!videoId
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
const {
|
|
|
@ -54,9 +71,10 @@ export const Watch: Component = () => {
|
|
|
|
} = useQuery({
|
|
|
|
} = useQuery({
|
|
|
|
queryKey: ["comments", videoId],
|
|
|
|
queryKey: ["comments", videoId],
|
|
|
|
queryFn: () => {
|
|
|
|
queryFn: () => {
|
|
|
|
|
|
|
|
if (!videoId) return;
|
|
|
|
return client.getComments(videoId);
|
|
|
|
return client.getComments(videoId);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
enabled: !videoIdIsInvalid
|
|
|
|
enabled: !!videoId
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) console.log(error);
|
|
|
|
if (error) console.log(error);
|
|
|
@ -66,7 +84,11 @@ export const Watch: Component = () => {
|
|
|
|
{isLoading && <LoadingPage />}
|
|
|
|
{isLoading && <LoadingPage />}
|
|
|
|
{data && !isLoading && (
|
|
|
|
{data && !isLoading && (
|
|
|
|
<div className="flex flex-col gap-4">
|
|
|
|
<div className="flex flex-col gap-4">
|
|
|
|
<Player streams={data.streams} />
|
|
|
|
<Player
|
|
|
|
|
|
|
|
initialTimestamp={timestamp}
|
|
|
|
|
|
|
|
initialDuration={data.video.duration / 1000}
|
|
|
|
|
|
|
|
streams={data.streams}
|
|
|
|
|
|
|
|
/>
|
|
|
|
<div className="flex flex-col xl:flex-row gap-4">
|
|
|
|
<div className="flex flex-col xl:flex-row gap-4">
|
|
|
|
<div className="flex flex-1 flex-col gap-4">
|
|
|
|
<div className="flex flex-1 flex-col gap-4">
|
|
|
|
<div className="flex flex-col">
|
|
|
|
<div className="flex flex-col">
|
|
|
|