<commit_before>import React, { Component } from 'react';
import SearchForm from './SearchForm';
import FreesoundList from './FreesoundList';

class FreesoundSearch extends React.Component {
  constructor(props) {
    super(props);
    this.state = { searches: ['wind'] };
  }

  searchFreesound = (inTerm) => {
    this.setState(function(prevState) {
      return {
        searches: prevState.searches.concat([inTerm])
      };
    });
  }

  handleRemoveSearch = (event) => {
    let aSearchTerm = event.target.getAttribute('data-freesound-search');
    console.log('FreesoundSearch.handleRemoveSearch', aSearchTerm);

    this.setState(function(prevState) {
      return {
        searches: prevState.searches.filter(item => (item != aSearchTerm))
      }
    })
  }

  createQueryURL = (term) => (
    'http://localhost:3001/apiv2/search/text?format=json&query=' + term + '&filter=duration:[1 TO 90]'
  )

  createFreesoundList = (aTerm) => (
    <FreesoundList
      audioContext={this.props.audioContext}
      onRemoveSearch={this.handleRemoveSearch}
      key={aTerm}
      title={aTerm}
      queryURL={this.createQueryURL(aTerm)} />
  )

  createFreesoundLists = () => (
    this.state.searches.map(this.createFreesoundList)
  )

  render() {
    return (
      <div>
        <SearchForm onSubmit={this.searchFreesound} />
        {this.createFreesoundLists()}
      </div>
    )
  }
}

export default FreesoundSearch;
<commit_msg>oh for heaven's sake, grab the preview url's and durations in the first search instead of doing N extra queries to the API. duh.<commit_after>import React, { Component } from 'react';
import SearchForm from './SearchForm';
import FreesoundList from './FreesoundList';

class FreesoundSearch extends React.Component {
  constructor(props) {
    super(props);
    this.state = { searches: ['wind'] };
  }

  searchFreesound = (inTerm) => {
    this.setState(function(prevState) {
      return {
        searches: prevState.searches.concat([inTerm])
      };
    });
  }

  handleRemoveSearch = (event) => {
    let aSearchTerm = event.target.getAttribute('data-freesound-search');
    console.log('FreesoundSearch.handleRemoveSearch', aSearchTerm);

    this.setState(function(prevState) {
      return {
        searches: prevState.searches.filter(item => (item != aSearchTerm))
      }
    })
  }

  createQueryURL = (term) => (
    'http://localhost:3001/apiv2/search/text?format=json&query=' + term + '&filter=duration:[1 TO 90]&fields=id,name,description,previews,duration'
  )

  createFreesoundList = (aTerm) => (
    <FreesoundList
      audioContext={this.props.audioContext}
      onRemoveSearch={this.handleRemoveSearch}
      key={aTerm}
      title={aTerm}
      queryURL={this.createQueryURL(aTerm)} />
  )

  createFreesoundLists = () => (
    this.state.searches.map(this.createFreesoundList)
  )

  render() {
    return (
      <div>
        <SearchForm onSubmit={this.searchFreesound} />
        {this.createFreesoundLists()}
      </div>
    )
  }
}

export default FreesoundSearch;

{'fraction_non_alphanumeric': 0.1390532544378698, 'fraction_numerical': 0.005259697567389875, 'mean_word_length': 3.310198300283286, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, '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': '1669378', 'n_tokens_mistral': 999, 'n_tokens_neox': 976, 'n_words': 159}