import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { translate } from 'react-i18next'; // import SourceIcon from './SourceIcon'; import { Button, Input, InputGroup, InputGroupAddon, Table } from 'reactstrap'; import { capitalize } from 'lodash'; import { getTitle } from '../../../../../../common/helper'; import cx from 'classnames'; import { domainNames } from '../SearchSubTab'; export class SourcesTabAvailSources extends React.Component { static propTypes = { chosenMediaTypes: PropTypes.array.isRequired, chosenLanguages: PropTypes.array.isRequired, availSources: PropTypes.array.isRequired, selectedSources: PropTypes.array.isRequired, searchBySourcesQuery: PropTypes.string.isRequired, setSearchBySourcesQuery: PropTypes.func.isRequired, getSearchBySources: PropTypes.func.isRequired, addSelectedSearchBySource: PropTypes.func.isRequired, t: PropTypes.func.isRequired }; componentDidMount = () => { this.searchSources(); }; searchSources = () => { const { chosenLanguages, chosenMediaTypes, getSearchBySources, searchBySourcesQuery } = this.props; const query = searchBySourcesQuery; const dataToSend = {}; dataToSend.page = 1; dataToSend.limit = 100; dataToSend.query = query; dataToSend.filters = {}; const source = [] const domain = [] chosenMediaTypes.map((v) => { if (domainNames.includes(v)) { domain.push(`${v}.com`); } else { source.push(v); } }) dataToSend.filters.publisher = { source, domain }; dataToSend.filters.language = chosenLanguages; getSearchBySources(dataToSend); }; chooseSource = (e) => { const dataset = e.currentTarget.dataset; const sourceTitle = dataset.sourceTitle; const sourceType = dataset.sourceType; const sourceId = dataset.sourceId; this.props.addSelectedSearchBySource({ title: sourceTitle, type: sourceType, id: sourceId }); }; onChangeSearchInput = (e) => { const val = e.target.value; this.props.setSearchBySourcesQuery(val); }; onEnterSearchInput = (e) => { if (e.keyCode === 13) this.searchSources(); }; render() { const { availSources, selectedSources } = this.props; const { t } = this.props; return (

{t('searchTab.searchBySection.sources.availSources')}

{availSources.length > 0 ? ( availSources.map((source, i) => { return ( v.id === source.id) })} data-source-title={source.title} data-source-type={source.type} data-source-id={source.id} onClick={this.chooseSource} key={i} > {/* */} ); }) ) : ( )}
{t('searchTab.searchBySection.sources.source')} {t('searchTab.searchBySection.sources.siteType')} {t('searchTab.searchBySection.sources.mediatype')} {t('searchTab.searchBySection.sources.lang')}
{getTitle(source.title)} {capitalize(source.siteType) || '-'} {capitalize(source.type) || '-'} {t(`common:language.${source.lang}`)}
{t('common:messages.noRows')}
); } } export default translate(['tabsContent'], { wait: true })( SourcesTabAvailSources );