Skip to content

Commit

Permalink
fix: Fixed stale search
Browse files Browse the repository at this point in the history
  • Loading branch information
JureSotosek committed Sep 16, 2018
1 parent d264ffe commit 64fea67
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Powered by [Algolia search API](https://www.algolia.com/), [npm-suggestions](https://github.com/JureSotosek/npm-suggestions) and the [Yarn](http://yarnpkg.com/) package manager.

<p align="center"><img src="media/example.gif" width="655" /></p>
<p align="center"><img src="media/newExample.gif" width="655" /></p>

## Overview

Expand Down
Binary file removed media/example.gif
Binary file not shown.
Binary file added media/newExample.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 9 additions & 17 deletions src/emma.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,7 @@ const SelectedPackages = ({ selectedPackages }) => (

// Restults

const SearchResults = ({
foundPackages,
onToggle,
loading,
loadingBackground,
focused,
}) => {
const SearchResults = ({ foundPackages, onToggle, loading, focused }) => {
if (loading === PROGRESS_LOADING) {
return (
<div>
Expand All @@ -150,7 +144,7 @@ const SearchResults = ({
return <ErrorInfo err="Couldn't reach Algolia search!" />
}

if (isEmpty(foundPackages) && !loadingBackground) {
if (isEmpty(foundPackages)) {
return <NotFoundSearchInfo />
}

Expand Down Expand Up @@ -252,7 +246,6 @@ class Emma extends Component {
foundSuggestionsPackages,
selectedPackages,
loadingSearch,
loadingSearchBackground,
loadingSuggestions,
focused,
} = this.state
Expand All @@ -271,7 +264,6 @@ class Emma extends Component {
foundPackages={foundSearchPackages}
onToggle={this.handleTogglePackage}
loading={loadingSearch}
loadingBackground={loadingSearchBackground}
focused={focused === FOCUSED_SEARCH}
/>
)}
Expand Down Expand Up @@ -368,28 +360,28 @@ class Emma extends Component {
})

setTimeout(() => {
if (this.state.loadingSearchBackground) {
if (this.state.loadingSearchBackground && this.state.query == query) {
this.setState({
loadingSearch: PROGRESS_LOADING,
loadingSearchBackground: false,
})
}
}, 1500)
}, 500)

try {
const hits = await getSearch(query, limit)
const cells = hitsToCells(hits)

this.setState({
loadingSearch: PROGRESS_LOADED,
loadingSearchBackground: false,
})

if (this.state.query === query) {
this.setState({
foundSearchPackages: cells,
})
}

this.setState({
loadingSearch: PROGRESS_LOADED,
loadingSearchBackground: false,
})
} catch (err) {
this.setState({
loadingSearchBackground: PROGRESS_ERROR,
Expand Down

0 comments on commit 64fea67

Please sign in to comment.