From 6953ebad5227aa2f2d117144efceee097a10498d Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 26 Jan 2019 02:23:50 -0800 Subject: [PATCH] Ergonomic improvements --- App.jsx | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/App.jsx b/App.jsx index dee5e50..9bb95d3 100644 --- a/App.jsx +++ b/App.jsx @@ -41,9 +41,10 @@ class Results extends Component { } content() { + const num = this.props.searchResults.length; const header = (
- Searched for { this.props.searchTerm } search type: { this.props.searchType } + Searched for { this.props.searchTerm } search type: { this.props.searchType }, found { num } result(s)
); const entries = this.props.searchResults.map( (entry, idx) => @@ -55,7 +56,7 @@ class Results extends Component { const results = this.props.searchResults; return(
- { results ? this.content() : "No results" } + { results ? this.content() : "No search" }
); } @@ -78,19 +79,25 @@ class App extends Component { searchSaimiar(evt) { const searchTerm = this.input.current.value; const request = `saimiar?sai=like.*${searchTerm}*` - makeRequest(request, (json) => { - const searchResults = json.length === 0 ? null : json; - this.setState({ searchResults, searchType: "saimiar", searchTerm }); - }); + if (searchTerm === "") { + this.setState({ searchResults: null, searchTerm: null, searchType: null }); + } else { + makeRequest(request, (json) => { + this.setState({ searchResults: json, searchType: "saimiar", searchTerm }); + }); + } } searchEng(evt) { const searchTerm = this.input.current.value; const request = `saimiar?eng=like.*${searchTerm}*` - makeRequest(request, (json) => { - const searchResults = json.length === 0 ? null : json; - this.setState({ searchResults, searchType: "eng-saimiar", searchTerm }); - }); + if (searchTerm === "") { + this.setState({ searchResults: null, searchTerm: null, searchType: null }); + } else { + makeRequest(request, (json) => { + this.setState({ searchResults: json, searchType: "eng-saimiar", searchTerm }); + }); + } } render() {