aboutsummaryrefslogtreecommitdiffstats
path: root/src/web
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-05-29 17:06:38 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-05-29 17:06:38 -0500
commit0a4f7c5e6c6dd09ac4457460cbff0e33f0ab934f (patch)
tree9dfad0e396c9259134e83b246a4a3528cf4b5402 /src/web
parent61375627fb3a82bdf53cc989339d69f39dca0165 (diff)
downloadslskd-0a4f7c5e6c6dd09ac4457460cbff0e33f0ab934f.tar.gz
fetch results on mount
Diffstat (limited to 'src/web')
-rw-r--r--src/web/src/components/Search/Search.js31
1 files changed, 22 insertions, 9 deletions
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();
+ }
+ });
+ }
+ }
}
}