Skip to content

Commit

Permalink
fixup! ⬆️(frontend) upgrade react to 18
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoLC committed Jun 28, 2023
1 parent 4bcc5f7 commit 210c010
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ export const VideoPlayer = ({
}, [setPlayerCurrentTime]);

useEffect(() => {
if (video?.urls?.manifests && playerRef.current) {
if (video?.urls?.manifests?.hls && playerRef.current) {
playerRef.current.setSource(video.urls.manifests.hls);
}
}, [video?.urls?.manifests]);
}, [video?.urls?.manifests?.hls]);

const oldTimedTextTracks = useRef(timedTextTracks);
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,10 @@ export const ToggleSubtitlesAsTranscript = () => {
state.getTimedTextTracks(),
);
const video = useCurrentVideo();
const [toggleUseTranscript, setToggleUseTranscript] = useState(
video.should_use_subtitle_as_transcript,
);
const [disabledToggle, setDisabledToggle] = useState(false);

const videoMutation = useUpdateVideo(video.id, {
const { mutate } = useUpdateVideo(video.id, {
onSuccess: (videoUpdated: Video) => {
setToggleUseTranscript(videoUpdated.should_use_subtitle_as_transcript);
toast.success(
intl.formatMessage(
videoUpdated.should_use_subtitle_as_transcript
Expand All @@ -78,11 +74,11 @@ export const ToggleSubtitlesAsTranscript = () => {
});

const onToggleChange = useCallback(() => {
videoMutation.mutate({
mutate({
should_use_subtitle_as_transcript:
!video.should_use_subtitle_as_transcript,
});
}, [video.should_use_subtitle_as_transcript, videoMutation]);
}, [video.should_use_subtitle_as_transcript, mutate]);

const transcripts = useMemo(
() =>
Expand All @@ -100,31 +96,9 @@ export const ToggleSubtitlesAsTranscript = () => {
[timedTextTracks],
);

// Sync toggle with value in the back
useEffect(() => {
setToggleUseTranscript(video.should_use_subtitle_as_transcript);
}, [video.should_use_subtitle_as_transcript]);

// Disable and uncheck toggle if there is no subtitle to use as a transcript
useEffect(() => {
if (subtitles.length === 0) {
if (!disabledToggle) {
setDisabledToggle(true);
if (video.should_use_subtitle_as_transcript) {
onToggleChange();
}
}
}
}, [
subtitles,
video.should_use_subtitle_as_transcript,
disabledToggle,
onToggleChange,
]);

// Disable and uncheck toggle if there is already an uploaded file for transcript
useEffect(() => {
if (transcripts.length > 0) {
if ((!subtitles.length && !timedTextTracks.length) || transcripts.length) {
if (!disabledToggle) {
setDisabledToggle(true);
if (video.should_use_subtitle_as_transcript) {
Expand All @@ -133,7 +107,9 @@ export const ToggleSubtitlesAsTranscript = () => {
}
}
}, [
transcripts,
subtitles.length,
timedTextTracks.length,
transcripts.length,
video.should_use_subtitle_as_transcript,
disabledToggle,
onToggleChange,
Expand All @@ -142,19 +118,15 @@ export const ToggleSubtitlesAsTranscript = () => {
// Enable toggle if there is at least one subtitle file that can be used as transcript
// and no existing transcript file
useEffect(() => {
if (
timedTextTracks.length > 0 &&
transcripts.length === 0 &&
disabledToggle
) {
if (timedTextTracks.length && !transcripts.length && disabledToggle) {
setDisabledToggle(false);
}
}, [transcripts, timedTextTracks, disabledToggle]);
}, [transcripts.length, timedTextTracks.length, disabledToggle]);

return (
<ToggleInput
disabled={disabledToggle}
checked={toggleUseTranscript}
checked={video.should_use_subtitle_as_transcript}
onChange={onToggleChange}
label={intl.formatMessage(messages.useTranscriptToggleLabel)}
truncateLabel={false}
Expand Down

0 comments on commit 210c010

Please sign in to comment.