aboutsummaryrefslogtreecommitdiffstats
path: root/src/web
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-05-29 17:08:36 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-05-29 17:08:36 -0500
commit25ddbc2a75cec8cc3a2b5d2b1be7b86b733a2b1e (patch)
tree9f107810949b7604fb308a3910498f50f79256a1 /src/web
parent0a4f7c5e6c6dd09ac4457460cbff0e33f0ab934f (diff)
downloadslskd-25ddbc2a75cec8cc3a2b5d2b1be7b86b733a2b1e.tar.gz
display loading status
Diffstat (limited to 'src/web')
-rw-r--r--src/web/src/components/Search/Search.js31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/web/src/components/Search/Search.js b/src/web/src/components/Search/Search.js
index ccb9c874..639cc5d8 100644
--- a/src/web/src/components/Search/Search.js
+++ b/src/web/src/components/Search/Search.js
@@ -18,7 +18,7 @@ import {
const initialState = {
searchPhrase: '',
- searchId: '',
+ searchId: undefined,
searchState: 'idle',
searchStatus: {
responseCount: 0,
@@ -31,6 +31,7 @@ const initialState = {
hideNoFreeSlots: true,
hiddenResults: [],
hideLocked: true,
+ fetching: false,
};
const sortOptions = {
@@ -123,6 +124,25 @@ class Search extends Component {
});
}
}
+
+ fetchStatus = async () => {
+ const { searchState, searchId } = this.state;
+
+ if (searchState === 'pending') {
+ this.setState({ fetching: true }, async () => {
+ const response = await search.getStatus({ id: searchId });
+
+ if (response.isComplete) {
+ this.setState({
+ searchState: 'complete'
+ }, this.fetchResults);
+ } else {
+ this.setState({
+ searchStatus: response,
+ fetching: false
+ }, this.saveState);
+ }
+ });
}
}
@@ -131,7 +151,7 @@ class Search extends Component {
}
sortAndFilterResults = () => {
- const { results, hideNoFreeSlots, resultSort, hideLocked, hiddenResults } = this.state;
+ const { results = [], hideNoFreeSlots, resultSort, hideLocked, hiddenResults = [] } = this.state;
const { field, order } = sortOptions[resultSort];
return results
@@ -164,8 +184,8 @@ class Search extends Component {
}
render = () => {
- let { searchState, searchStatus, results, displayCount, resultSort, hideNoFreeSlots, hideLocked, hiddenResults } = this.state;
- let pending = searchState === 'pending';
+ let { searchState, searchStatus, results = [], displayCount, resultSort, hideNoFreeSlots, hideLocked, hiddenResults = [], fetching } = this.state;
+ let pending = fetching || searchState === 'pending';
const sortedAndFilteredResults = this.sortAndFilterResults();
@@ -195,7 +215,8 @@ class Search extends Component {
inline='centered'
size='big'
>
- Found {searchStatus.fileCount} files {searchStatus.lockedFileCount > 0 ? `(plus ${searchStatus.lockedFileCount} locked) ` : ''}from {searchStatus.responseCount} users
+ {searchState === 'pending' ? <span>Found {searchStatus.fileCount} files {searchStatus.lockedFileCount > 0 ? `(plus ${searchStatus.lockedFileCount} locked) ` : ''}from {searchStatus.responseCount} users</span>
+ : 'Fetching results'}
</Loader>
:
<div>