Ran pre-commit hook
This commit is contained in:
parent
262d9f7d44
commit
ac0ca8c14f
@ -89,7 +89,7 @@ export default function QuickLaunch({
|
||||
}
|
||||
}
|
||||
|
||||
const [searchSuggestions, setSearchSuggestions] = useState([])
|
||||
const [searchSuggestions, setSearchSuggestions] = useState([]);
|
||||
useEffect(() => {
|
||||
if (searchString.length === 0) setResults([]);
|
||||
else {
|
||||
@ -116,31 +116,35 @@ export default function QuickLaunch({
|
||||
|
||||
if (!hideSearchSuggestions && searchProvider.suggestionUrl) {
|
||||
if (searchString.trim() !== searchSuggestions[0]) {
|
||||
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[1].length - 4 > 0) {
|
||||
newSearchSuggestions[1].splice(-(newSearchSuggestions[1].length-4));
|
||||
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[1].length - 4 > 0) {
|
||||
newSearchSuggestions[1].splice(-(newSearchSuggestions[1].length - 4));
|
||||
}
|
||||
|
||||
// Save the new search suggestions in their state.
|
||||
setSearchSuggestions(newSearchSuggestions);
|
||||
}
|
||||
|
||||
// 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.
|
||||
});
|
||||
})
|
||||
.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.
|
||||
if (searchSuggestions[1]) {
|
||||
newResults = newResults.concat(searchSuggestions[1].map((suggestion)=>({
|
||||
href: searchProvider.url + encodeURIComponent(suggestion),
|
||||
name: suggestion,
|
||||
type: "search",
|
||||
})));
|
||||
newResults = newResults.concat(
|
||||
searchSuggestions[1].map((suggestion) => ({
|
||||
href: searchProvider.url + encodeURIComponent(suggestion),
|
||||
name: suggestion,
|
||||
type: "search",
|
||||
})),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -159,7 +163,17 @@ export default function QuickLaunch({
|
||||
setCurrentItemIndex(0);
|
||||
}
|
||||
}
|
||||
}, [searchString, servicesAndBookmarks, searchDescriptions, hideVisitURL, hideSearchSuggestions, searchSuggestions, searchProvider, url, t]);
|
||||
}, [
|
||||
searchString,
|
||||
servicesAndBookmarks,
|
||||
searchDescriptions,
|
||||
hideVisitURL,
|
||||
hideSearchSuggestions,
|
||||
searchSuggestions,
|
||||
searchProvider,
|
||||
url,
|
||||
t,
|
||||
]);
|
||||
|
||||
const [hidden, setHidden] = useState(true);
|
||||
useEffect(() => {
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
import { searchProviders } from "components/widgets/search/search";
|
||||
import cachedFetch from "utils/proxy/cached-fetch";
|
||||
import { widgetsFromConfig } from "utils/config/widget-helpers"
|
||||
import { widgetsFromConfig } from "utils/config/widget-helpers";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { query, providerName } = req.query;
|
||||
|
||||
const provider = Object.values(searchProviders).find(({ name }) => name === providerName);
|
||||
|
||||
|
||||
if (provider.name === "Custom") {
|
||||
const widgets = await widgetsFromConfig();
|
||||
const searchWidget = widgets.find((w) => w.type === "search");
|
||||
|
||||
|
||||
provider.url = searchWidget.options.url ?? "";
|
||||
provider.suggestionUrl = searchWidget.options.suggestionUrl ?? "";
|
||||
}
|
||||
|
||||
@ -211,10 +211,13 @@ function Home({ initialSettings }) {
|
||||
// if search provider is a list, try to retrieve from localstorage, fall back to the first
|
||||
searchProvider = getStoredProvider() ?? searchProviders[searchWidget.options.provider[0]];
|
||||
} else if (searchWidget.options?.provider === "custom") {
|
||||
searchProvider = {...searchProviders.custom, ...{
|
||||
url: searchWidget.options.url,
|
||||
suggestionUrl: searchWidget.options.suggestionUrl,
|
||||
}};
|
||||
searchProvider = {
|
||||
...searchProviders.custom,
|
||||
...{
|
||||
url: searchWidget.options.url,
|
||||
suggestionUrl: searchWidget.options.suggestionUrl,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
searchProvider = searchProviders[searchWidget.options?.provider];
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user