From 0a4f7c5e6c6dd09ac4457460cbff0e33f0ab934f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 29 May 2021 17:06:38 -0500 Subject: fetch results on mount --- src/web/src/components/Search/Search.js | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/Search/Search.js b/src/web/src/components/Search/Search.js index ab1257e9..ccb9c874 100644 --- a/src/web/src/components/Search/Search.js +++ b/src/web/src/components/Search/Search.js @@ -83,9 +83,9 @@ class Search extends Component { this.setState(JSON.parse(localStorage.getItem('soulseek-example-search-state')) || initialState, resolve)); } - componentDidMount = () => { - this.fetchStatus(); - this.loadState(); + componentDidMount = async () => { + await this.loadState(); + this.fetchResults(); this.setState({ interval: window.setInterval(this.fetchStatus, 500) }, () => this.setSearchText()); @@ -104,12 +104,25 @@ class Search extends Component { document.removeEventListener("keyup", this.keyUp, false); } - fetchStatus = () => { - if (this.state.searchState === 'pending') { - search.getStatus({ id: this.state.searchId }) - .then(response => this.setState({ - searchStatus: response - })); + fetchResults = async () => { + const { searchId } = this.state; + + if (!!searchId) { + this.setState({ fetching: true }, async () => { + try { + const responses = await search.getResponses({ id: searchId }); + + this.setState({ + results: responses, + fetching: false + }, this.saveState); + } catch (error) { + console.log(error); + this.clear(); + } + }); + } + } } } -- cgit v1.2.3