Fixed infinite loop
Now the search request is only sent, if the *searchString* changed.
This commit is contained in:
parent
769beb7dc6
commit
0907c89b41
@ -115,29 +115,33 @@ export default function QuickLaunch({
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!hideSearchSuggestions) {
|
if (!hideSearchSuggestions) {
|
||||||
fetch(`/api/searchSuggestion?query=${encodeURIComponent(searchString)}&providerName=${searchProvider.name}`).then(async (searchSuggestionResult) => {
|
if (searchString.trim() !== searchSuggestions[0]) {
|
||||||
const newSearchSuggestions = (await searchSuggestionResult.json())[1];
|
fetch(`/api/searchSuggestion?query=${encodeURIComponent(searchString)}&providerName=${searchProvider.name}`).then(async (searchSuggestionResult) => {
|
||||||
|
const newSearchSuggestions = await searchSuggestionResult.json();
|
||||||
// Check if there is a search suggestion
|
|
||||||
if (newSearchSuggestions) {
|
|
||||||
// Restrict the searchSuggestion to 4 entries
|
|
||||||
if (newSearchSuggestions.length - 4 > 0) {
|
|
||||||
newSearchSuggestions.splice(-(newSearchSuggestions.length-4));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save the new search suggestions in their state.
|
// Check if there is a search suggestion
|
||||||
setSearchSuggestions(newSearchSuggestions);
|
if (newSearchSuggestions) {
|
||||||
}
|
// Restrict the searchSuggestion to 4 entries
|
||||||
}).catch(() => {
|
if (newSearchSuggestions[1].length - 4 > 0) {
|
||||||
// If there is an error, just ignore it. There just will be no search suggestions.
|
newSearchSuggestions[1].splice(-(newSearchSuggestions[1].length-4));
|
||||||
});
|
}
|
||||||
|
|
||||||
|
// Save the new search suggestions in their state.
|
||||||
|
setSearchSuggestions(newSearchSuggestions);
|
||||||
|
}
|
||||||
|
}).catch(() => {
|
||||||
|
// If there is an error, just ignore it. There just will be no search suggestions.
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Show search suggestions from their state. This will show the "old" suggestions until they are updated.
|
// Show search suggestions from their state. This will show the "old" suggestions until they are updated.
|
||||||
newResults = newResults.concat(searchSuggestions.map((suggestion)=>({
|
if (searchSuggestions[1]) {
|
||||||
href: searchProvider.url + encodeURIComponent(suggestion),
|
newResults = newResults.concat(searchSuggestions[1].map((suggestion)=>({
|
||||||
name: suggestion,
|
href: searchProvider.url + encodeURIComponent(suggestion),
|
||||||
type: "search",
|
name: suggestion,
|
||||||
})));
|
type: "search",
|
||||||
|
})));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user