From 4b28c9295900b30ff0ec48f4137e5fc7d0dce294 Mon Sep 17 00:00:00 2001 From: Greg Rickaby Date: Tue, 6 Aug 2019 10:27:59 -0500 Subject: [PATCH] linting/prettier --- assets/js/components/searchForm.js | 124 ++++++++++++++------------ assets/js/components/searchResult.js | 17 ++-- assets/js/components/searchResults.js | 71 +++++++-------- 3 files changed, 109 insertions(+), 103 deletions(-) diff --git a/assets/js/components/searchForm.js b/assets/js/components/searchForm.js index c1dc7ad..650b6a3 100644 --- a/assets/js/components/searchForm.js +++ b/assets/js/components/searchForm.js @@ -1,97 +1,99 @@ -require( 'isomorphic-fetch' ); -import React from 'react'; -import qs from 'query-string'; -import { DebounceInput } from 'react-debounce-input'; -import SearchResults from './searchResults'; +require("isomorphic-fetch"); +import React from "react"; +import qs from "query-string"; +import { DebounceInput } from "react-debounce-input"; +import SearchResults from "./searchResults"; export default class SearchForm extends React.Component { + constructor(props) { + super(props); - constructor( props ) { - super( props ); - - this.getResults = this.getResults.bind( this ); - this.getFormClass = this.getFormClass.bind( this ); + this.getResults = this.getResults.bind(this); + this.getFormClass = this.getFormClass.bind(this); this.state = { results: [], loading: false, searched: false, lengthError: false, - empty: false, + empty: false }; } - getResults( event ) { - + getResults(event) { const search = event.target.value; - if ( ! search ) { - this.setState( { + if (!search) { + this.setState({ results: [], loading: false, searched: false, lengthError: false, - empty: true, - } ); + empty: true + }); return; } - if ( search && wds_react_post_search.minimum_character_count <= search.length ) { - this.setState( { + if ( + search && + wds_react_post_search.minimum_character_count <= search.length + ) { + this.setState({ loading: true, searched: true, lengthError: false, - empty: false, - } ); + empty: false + }); const postType = this.props.postType; - let url = wds_react_post_search.rest_search_posts.replace( '%s', search ); + let url = wds_react_post_search.rest_search_posts.replace("%s", search); let query = { s: search }; - if ( postType ) { + if (postType) { query.type = postType; - }; - - const queryString = qs.stringify( query ); - url = `${ url }?${ queryString }`; - - let json = fetch( url ) - .then( - response => { - return response.json() - } - ) - .then( - results => { - this.setState( { - results: results, - loading: false - } ); - } - ); + } + + const queryString = qs.stringify(query); + url = `${url}?${queryString}`; + + let json = fetch(url) + .then(response => { + return response.json(); + }) + .then(results => { + this.setState({ + results: results, + loading: false + }); + }); } else { - this.setState( { + this.setState({ results: [], searched: false, lengthError: true, - empty: false, - } ); + empty: false + }); } } getFormClass() { - let className = 'search-form-input'; - - if ( this.state.results.length > 0 || this.state.loading || this.state.lengthError || this.state.searched ) { - className += ' search-form-performing-action'; + let className = "search-form-input"; + + if ( + this.state.results.length > 0 || + this.state.loading || + this.state.lengthError || + this.state.searched + ) { + className += " search-form-performing-action"; } - if ( this.state.empty ) { - className = 'search-form-input'; + if (this.state.empty) { + className = "search-form-input"; } return className; @@ -99,10 +101,22 @@ export default class SearchForm extends React.Component { render() { return ( -
- - +
+ +
- ) + ); } } diff --git a/assets/js/components/searchResult.js b/assets/js/components/searchResult.js index af5ff75..82baed4 100644 --- a/assets/js/components/searchResult.js +++ b/assets/js/components/searchResult.js @@ -1,16 +1,17 @@ -import React from 'react'; -import { decodeEntities } from '@wordpress/html-entities'; +import React from "react"; +import { decodeEntities } from "@wordpress/html-entities"; export default class SearchResult extends React.Component { - - constructor( props ) { - super( props ); + constructor(props) { + super(props); } - render() { + render() { return (
  • - { decodeEntities( this.props.result.title ) } + + {decodeEntities(this.props.result.title)} +
  • - ) + ); } } diff --git a/assets/js/components/searchResults.js b/assets/js/components/searchResults.js index 8d25401..211b8db 100644 --- a/assets/js/components/searchResults.js +++ b/assets/js/components/searchResults.js @@ -1,63 +1,54 @@ -import React from 'react'; -import SearchResult from './searchResult'; +import React from "react"; +import SearchResult from "./searchResult"; export default class SearchResults extends React.Component { - - constructor( props ) { - super( props ); + constructor(props) { + super(props); } render() { - - let results = '', - resultsClass = ''; + let results = "", + resultsClass = ""; // If the input is empty, like we deleted our query. - if ( this.props.empty ) { + if (this.props.empty) { return null; } // If we have results, OR we have results, but we're still typing. We don't want to take the results away to load more. - if ( 0 < this.props.results.length || 0 < this.props.results.length && this.props.loading ) { - - const queryResults = this.props.results.map( result => { - return( - - ); - } ); - - results =
      { queryResults }
    ; - resultsClass = this.props.loading ? ' has-results loading-more performed-action' : ' has-results performed-action'; - - } else if ( this.props.loading ) { - + if ( + 0 < this.props.results.length || + (0 < this.props.results.length && this.props.loading) + ) { + const queryResults = this.props.results.map(result => { + return ; + }); + + results =
      {queryResults}
    ; + resultsClass = this.props.loading + ? " has-results loading-more performed-action" + : " has-results performed-action"; + } else if (this.props.loading) { // If we're loading results for the first time. - results =

    { wds_react_post_search.loading_text }

    ; - resultsClass = ' loading performed-action'; - - } else if ( ! this.props.empty && this.props.lengthError ) { - + results =

    {wds_react_post_search.loading_text}

    ; + resultsClass = " loading performed-action"; + } else if (!this.props.empty && this.props.lengthError) { // If the input isn't empty but doesn't have enough characters. - results =

    { wds_react_post_search.length_error }

    ; - resultsClass = ' character-length performed-action'; - - } else if ( this.props.searched ) { - + results =

    {wds_react_post_search.length_error}

    ; + resultsClass = " character-length performed-action"; + } else if (this.props.searched) { // If no results were found. - results =

    { wds_react_post_search.no_results_text }

    ; - resultsClass = ' no-results performed-action'; - + results =

    {wds_react_post_search.no_results_text}

    ; + resultsClass = " no-results performed-action"; } // Bail if we have no results variables set. - if ( ! results ) { + if (!results) { return null; } return ( -
    - { results } -
    - ) +
    {results}
    + ); } }