{"size": 1605, "ext": "js", "max_stars_repo_path": "packages/react/src/content/components/base/contentList/ContentList.js", "max_stars_repo_name": "vinicaval/blackout", "max_stars_repo_stars_event_min_datetime": "2021-11-30T09:50:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T16:15:24.000Z", "max_issues_repo_path": "packages/react/src/content/components/base/contentList/ContentList.js", "max_issues_repo_name": "vinicaval/blackout", "max_issues_repo_issues_event_min_datetime": "2021-11-30T19:35:43.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T16:30:08.000Z", "max_forks_repo_path": "packages/react/src/content/components/base/contentList/ContentList.js", "max_forks_repo_name": "vinicaval/blackout", "max_forks_repo_forks_event_min_datetime": "2021-11-30T09:46:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-02T12:38:24.000Z"}
{"max_stars_count": 20, "max_issues_count": 18, "max_forks_count": 16, "avg_line_length": 31.4705882353, "max_line_length": 68, "alphanum_fraction": 0.6797507788}
import {
  getCountryCode,
  getCultureCode,
} from '@farfetch/blackout-core/locale/redux';
import { sortContentType } from '../../../utils';
import { useContentType } from '../../../hooks';
import { useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import renderContent from '../../../helpers/renderContent';

const ContentList = ({ data, location, viewportBreakpoint }) => {
  const { pageSize, orderOption, contentTypes } = data.fields;
  const countryCode = useSelector(getCountryCode);
  const cultureCode = useSelector(getCultureCode);
  const isRoutePreview = !!location.query?.['target.preview'];
  const { isContentTypeLoading, contentType } = useContentType(
    null,
    contentTypes?.components?.[0]?.fields?.key?.value,
    {
      countryCode: isRoutePreview
        ? location.query?.['target.country']
        : countryCode,
      cultureCode: isRoutePreview
        ? location.query?.['target.language']
        : cultureCode,
      contentzone: location.query?.['target.contentzone'],
      spacecode: location.query?.['spacecode'],
      channel: location.query?.['target.channel'],
      // We can't have target.preview so the default should be live
      environmentcode: 'live',
    },
    pageSize?.value,
  );

  if (isContentTypeLoading) {
    return null;
  }

  return contentType && contentType.length > 0
    ? sortContentType(contentType, orderOption.value).map(content =>
        renderContent(content, location, viewportBreakpoint),
      )
    : null;
};

ContentList.propTypes = {
  data: PropTypes.object.isRequired,
};

export default ContentList;
