Fix embeddable player focus by using useRef

This commit is contained in:
MerlinScheurer 2025-01-27 19:04:49 +01:00
parent 78528c4260
commit 781dd8d2fc

View File

@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { VideoResponseType } from '../pages/Video';
import VideoPlayer from './VideoPlayer';
import loadVideoById from '../api/loader/loadVideoById';
@ -24,6 +24,8 @@ type EmbeddableVideoPlayerProps = {
};
const EmbeddableVideoPlayer = ({ videoId }: EmbeddableVideoPlayerProps) => {
const inlinePlayerRef = useRef<HTMLDivElement>(null);
const [, setSearchParams] = useSearchParams();
const [refresh, setRefresh] = useState(false);
@ -63,8 +65,7 @@ const EmbeddableVideoPlayer = ({ videoId }: EmbeddableVideoPlayerProps) => {
setVideoResponse(videoResponse);
const inlinePlayer = document.getElementById('inline-player');
inlinePlayer?.scrollIntoView();
inlinePlayerRef.current?.scrollIntoView();
setRefresh(false);
setLoading(false);
@ -91,7 +92,7 @@ const EmbeddableVideoPlayer = ({ videoId }: EmbeddableVideoPlayerProps) => {
return (
<>
<div id="inline-player" className="player-wrapper">
<div ref={inlinePlayerRef} className="player-wrapper">
<div className="video-player">
{!loading && (
<VideoPlayer