<commit_before>import React, { useEffect, useRef, useState } from 'react';
import { useContentObj } from 'helpers/hooks';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import {
  changeByUserStatusForThumbs,
  editVideoThumbs,
  likeVideo,
  setDifficulty
} from 'redux/actions/VideoActions';
import Carousel from 'components/Carousel';
import Button from 'components/Button';
import Loading from 'components/Loading';
import VideoPlayer from 'components/VideoPlayer';
import NotFound from 'components/NotFound';
import CheckListGroup from 'components/CheckListGroup';
import PageTab from './PageTab';
import Comments from 'components/Comments';
import Details from './Details';
import NavMenu from './NavMenu';
import ResultModal from './Modals/ResultModal';
import QuestionsBuilder from './QuestionsBuilder';
import ConfirmModal from 'components/Modals/ConfirmModal';
import { fetchedVideoCodeFromURL, stringIsEmpty } from 'helpers/stringHelpers';
import queryString from 'query-string';
import ErrorBoundary from 'components/Wrappers/ErrorBoundary';
import Subjects from 'components/Subjects';
import RewardStatus from 'components/RewardStatus';
import request from 'axios';
import { Color, mobileMaxWidth } from 'constants/css';
import { css } from 'emotion';
import {
  auth,
  fetchPlaylistsContaining,
  handleError,
  loadComments,
  loadSubjects
} from 'helpers/requestHelpers';
import URL from 'constants/URL';

VideoPage.propTypes = {
  authLevel: PropTypes.number,
  canEdit: PropTypes.bool,
  changeByUserStatusForThumbs: PropTypes.func.isRequired,
  dispatch: PropTypes.func.isRequired,
  editVideoThumbs: PropTypes.func.isRequired,
  history: PropTypes.object.isRequired,
  likeVideo: PropTypes.func.isRequired,
  location: PropTypes.object.isRequired,
  match: PropTypes.object.isRequired,
  setDifficulty: PropTypes.func.isRequired,
  userId: PropTypes.number
};

function VideoPage({
  authLevel,
  canEdit,
  changeByUserStatusForThumbs,
  dispatch,
  editVideoThumbs,
  history,
  likeVideo,
  location: { search },
  match: {
    params: { videoId: initialVideoId }
  },
  setDifficulty,
  userId
}) {
  const [changingPage, setChangingPage] = useState(false);
  const [watchTabActive, setWatchTabActive] = useState(true);
  const [currentSlide, setCurrentSlide] = useState(0);
  const [userAnswers, setUserAnswers] = useState([]);
  const [resultModalShown, setResultModalShown] = useState(false);
  const [confirmModalShown, setConfirmModalShown] = useState(false);
  const [onEdit, setOnEdit] = useState(false);
  const [questionsBuilderShown, setQuestionsBuilderShown] = useState(false);
  const [videoId, setVideoId] = useState(initialVideoId);
  const [videoLoading, setVideoLoading] = useState(true);
  const [videoUnavailable, setVideoUnavailable] = useState(false);
  const mounted = useRef(true);
  const CommentInputAreaRef = useRef(null);
  const videoIdRef = useRef(initialVideoId);
  const {
    contentObj,
    contentObj: {
      byUser,
      childComments: comments,
      commentsLoadMoreButton,
      content,
      description,
      difficulty,
      hasHqThumb,
      likes,
      questions,
      stars,
      subjects,
      subjectsLoadMoreButton,
      tags,
      timeStamp,
      title,
      uploader,
      views
    },
    setContentObj,
    onAddTags,
    onAttachStar,
    onDeleteComment,
    onDeleteSubject,
    onEditComment,
    onEditRewardComment,
    onEditSubject,
    onInitContent,
    onLikeComment,
    onLikeContent,
    onLoadSubjectComments,
    onLoadMoreComments,
    onLoadMoreReplies,
    onLoadMoreSubjects,
    onLoadMoreSubjectComments,
    onLoadMoreSubjectReplies,
    onSetDifficulty,
    onSetSubjectDifficulty,
    onUploadComment,
    onUploadReply,
    onUploadSubject
  } = useContentObj({
    type: 'video',
    contentId: Number(videoId)
  });

  useEffect(() => {
    mounted.current = true;
    videoIdRef.current = initialVideoId;
    setChangingPage(true);
    loadVideoPage();
    setVideoId(initialVideoId);
    setChangingPage(false);
    async function loadVideoPage() {
      try {
        const { data } = await request.get(
          `${URL}/video/page?videoId=${videoIdRef.current}`
        );
        const subjectsObj = await loadSubjects({
          type: 'video',
          contentId: videoIdRef.current
        });
        const commentsObj = await loadComments({
          id: videoIdRef.current,
          type: 'video'
        });
        const tags = await fetchPlaylistsContaining({
          videoId: videoIdRef.current
        });
        if (mounted.current) {
          setVideoLoading(false);
          onInitContent({
            content: {
              ...data,
              tags,
              contentId: Number(videoIdRef.current),
              childComments: commentsObj?.comments || [],
              commentsLoadMoreButton: commentsObj?.loadMoreButton || false,
              subjects: subjectsObj?.results || [],
              subjectsLoadMoreButton: subjectsObj?.loadMoreButton || false
            }
          });
        }
      } catch (error) {
        if (error.response) {
          const { data = {} } = error.response;<commit_msg>minor fix<commit_after>import React, { useEffect, useRef, useState } from 'react';
import { useContentObj } from 'helpers/hooks';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import {
  changeByUserStatusForThumbs,
  editVideoThumbs,
  likeVideo,
  setDifficulty
} from 'redux/actions/VideoActions';
import Carousel from 'components/Carousel';
import Button from 'components/Button';
import Loading from 'components/Loading';
import VideoPlayer from 'components/VideoPlayer';
import NotFound from 'components/NotFound';
import CheckListGroup from 'components/CheckListGroup';
import PageTab from './PageTab';
import Comments from 'components/Comments';
import Details from './Details';
import NavMenu from './NavMenu';
import ResultModal from './Modals/ResultModal';
import QuestionsBuilder from './QuestionsBuilder';
import ConfirmModal from 'components/Modals/ConfirmModal';
import { fetchedVideoCodeFromURL, stringIsEmpty } from 'helpers/stringHelpers';
import queryString from 'query-string';
import ErrorBoundary from 'components/Wrappers/ErrorBoundary';
import Subjects from 'components/Subjects';
import RewardStatus from 'components/RewardStatus';
import request from 'axios';
import { Color, mobileMaxWidth } from 'constants/css';
import { css } from 'emotion';
import {
  auth,
  fetchPlaylistsContaining,
  handleError,
  loadComments,
  loadSubjects
} from 'helpers/requestHelpers';
import URL from 'constants/URL';

VideoPage.propTypes = {
  authLevel: PropTypes.number,
  canEdit: PropTypes.bool,
  changeByUserStatusForThumbs: PropTypes.func.isRequired,
  dispatch: PropTypes.func.isRequired,
  editVideoThumbs: PropTypes.func.isRequired,
  history: PropTypes.object.isRequired,
  likeVideo: PropTypes.func.isRequired,
  location: PropTypes.object.isRequired,
  match: PropTypes.object.isRequired,
  setDifficulty: PropTypes.func.isRequired,
  userId: PropTypes.number
};

function VideoPage({
  authLevel,
  canEdit,
  changeByUserStatusForThumbs,
  dispatch,
  editVideoThumbs,
  history,
  likeVideo,
  location: { search },
  match: {
    params: { videoId: initialVideoId }
  },
  setDifficulty,
  userId
}) {
  const [changingPage, setChangingPage] = useState(false);
  const [watchTabActive, setWatchTabActive] = useState(true);
  const [currentSlide, setCurrentSlide] = useState(0);
  const [userAnswers, setUserAnswers] = useState([]);
  const [resultModalShown, setResultModalShown] = useState(false);
  const [confirmModalShown, setConfirmModalShown] = useState(false);
  const [onEdit, setOnEdit] = useState(false);
  const [questionsBuilderShown, setQuestionsBuilderShown] = useState(false);
  const [videoId, setVideoId] = useState(initialVideoId);
  const [videoLoading, setVideoLoading] = useState(true);
  const [videoUnavailable, setVideoUnavailable] = useState(false);
  const mounted = useRef(true);
  const CommentInputAreaRef = useRef(null);
  const videoIdRef = useRef(initialVideoId);
  const {
    contentObj,
    contentObj: {
      byUser,
      childComments: comments,
      commentsLoadMoreButton,
      content,
      description,
      difficulty,
      hasHqThumb,
      likes,
      questions,
      stars,
      subjects,
      subjectsLoadMoreButton,
      tags,
      timeStamp,
      title,
      uploader,
      views
    },
    setContentObj,
    onAddTags,
    onAttachStar,
    onDeleteComment,
    onDeleteSubject,
    onEditComment,
    onEditRewardComment,
    onEditSubject,
    onInitContent,
    onLikeComment,
    onLikeContent,
    onLoadSubjectComments,
    onLoadMoreComments,
    onLoadMoreReplies,
    onLoadMoreSubjects,
    onLoadMoreSubjectComments,
    onLoadMoreSubjectReplies,
    onSetDifficulty,
    onSetSubjectDifficulty,
    onUploadComment,
    onUploadReply,
    onUploadSubject
  } = useContentObj({
    type: 'video',
    contentId: Number(videoId)
  });

  useEffect(() => {
    mounted.current = true;
    videoIdRef.current = initialVideoId;
    setChangingPage(true);
    loadVideoPage();
    setChangingPage(false);
    async function loadVideoPage() {
      try {
        const { data } = await request.get(
          `${URL}/video/page?videoId=${videoIdRef.current}`
        );
        const subjectsObj = await loadSubjects({
          type: 'video',
          contentId: videoIdRef.current
        });
        const commentsObj = await loadComments({
          id: videoIdRef.current,
          type: 'video'
        });
        const tags = await fetchPlaylistsContaining({
          videoId: videoIdRef.current
        });
        if (mounted.current) {
          setVideoId(initialVideoId);
          setVideoLoading(false);
          onInitContent({
            content: {
              ...data,
              tags,
              contentId: Number(videoIdRef.current),
              childComments: commentsObj?.comments || [],
              commentsLoadMoreButton: commentsObj?.loadMoreButton || false,
              subjects: subjectsObj?.results || [],
              subjectsLoadMoreButton: subjectsObj?.loadMoreButton || false
            }
          });
        }
      } catch (error) {
        if (error.response) {
          const { data = {} } = error.response;
{'fraction_non_alphanumeric': 0.09951876804619826, 'fraction_numerical': 0.00019249278152069297, 'mean_word_length': 3.4904926534140017, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7133166', 'n_tokens_mistral': 2951, 'n_tokens_neox': 3004, 'n_words': 662}