import page from '@automattic/calypso-router'; import { map } from 'lodash'; import PropTypes from 'prop-types'; import { stringify } from 'qs'; import { Component } from 'react'; import EmptyContent from 'calypso/components/empty-content'; import SearchCard from 'calypso/components/search-card'; import { addQueryArgs } from 'calypso/lib/url'; import DocsSelectorsResult from './result'; export default class DocsSelectorsSearch extends Component { static propTypes = { search: PropTypes.string, }; state = {}; componentDidMount() { this.request( this.props.search ); } componentDidUpdate( prevProps ) { if ( prevProps.search !== this.props.search ) { this.request( this.props.search ); } } request = async ( search ) => { const query = stringify( { search } ); try { const res = await fetch( `/devdocs/service/selectors?${ query }` ); if ( res.ok ) { const results = await res.json(); this.setState( { results } ); } } catch ( error ) { // Do nothing. } }; onSearch( search ) { page( addQueryArgs( { search }, '/devdocs/selectors' ) ); } render() { const { search } = this.props; const { results } = this.state; return (
{ results && ! results.length && ( ) }
    { map( results, ( { item: { name, description, tags } } ) => (
  • ) ) }
); } }