implemented backwards compatibilty
This commit is contained in:
parent
9bfd8dfee3
commit
7911cf7612
@ -1,9 +1,10 @@
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useEffect, useState, useRef, useCallback, useContext } from "react";
|
import { useEffect, useState, useRef, useCallback, useContext } from "react";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
|
import useSWR from "swr";
|
||||||
|
|
||||||
import ResolvedIcon from "./resolvedicon";
|
import ResolvedIcon from "./resolvedicon";
|
||||||
import { searchProviders } from "./widgets/search/search";
|
import { getStoredProvider, searchProviders } from "./widgets/search/search";
|
||||||
|
|
||||||
import { SettingsContext } from "utils/contexts/settings";
|
import { SettingsContext } from "utils/contexts/settings";
|
||||||
|
|
||||||
@ -12,7 +13,6 @@ export default function QuickLaunch({ servicesAndBookmarks, searchString, setSea
|
|||||||
|
|
||||||
const { settings } = useContext(SettingsContext);
|
const { settings } = useContext(SettingsContext);
|
||||||
const { searchDescriptions = false, hideVisitURL = false } = settings?.quicklaunch ?? {};
|
const { searchDescriptions = false, hideVisitURL = false } = settings?.quicklaunch ?? {};
|
||||||
const showSearchSuggestions = !!(settings?.quicklaunch?.showSearchSuggestions ?? true);
|
|
||||||
|
|
||||||
const searchField = useRef();
|
const searchField = useRef();
|
||||||
|
|
||||||
@ -21,15 +21,40 @@ export default function QuickLaunch({ servicesAndBookmarks, searchString, setSea
|
|||||||
const [url, setUrl] = useState(null);
|
const [url, setUrl] = useState(null);
|
||||||
const [searchSuggestions, setSearchSuggestions] = useState([]);
|
const [searchSuggestions, setSearchSuggestions] = useState([]);
|
||||||
|
|
||||||
|
const { data: widgets } = useSWR("/api/widgets");
|
||||||
|
|
||||||
function getSearchProvider() {
|
function getSearchProvider() {
|
||||||
|
if (settings?.quicklaunch?.hideInternetSearch) return null;
|
||||||
|
|
||||||
|
const searchWidget = Object.values(widgets).find((w) => w.type === "search");
|
||||||
let searchProvider = null;
|
let searchProvider = null;
|
||||||
|
|
||||||
if (settings?.quicklaunch?.provider === "custom") {
|
if (settings?.quicklaunch?.provider === "custom") {
|
||||||
searchProvider = settings.quicklaunch;
|
searchProvider = settings.quicklaunch;
|
||||||
} else if (settings?.quicklaunch?.provider) {
|
} else if (settings?.quicklaunch?.provider) {
|
||||||
searchProvider = searchProviders[settings.quicklaunch.provider];
|
searchProvider = searchProviders[settings.quicklaunch.provider];
|
||||||
|
} else if (searchWidget) {
|
||||||
|
// If there is no search provider in quick launch settings, try to get it from the search widget
|
||||||
|
|
||||||
|
if (Array.isArray(searchWidget.options?.provider)) {
|
||||||
|
// 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 = searchWidget.options;
|
||||||
|
} else {
|
||||||
|
searchProvider = searchProviders[searchWidget.options?.provider];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there is no search provider in quick launch settings try to get the value from search widget,
|
||||||
|
// if it's not specified there either then set the value to false
|
||||||
|
if (searchProvider)
|
||||||
|
searchProvider.showSearchSuggestions = !!(
|
||||||
|
settings?.quicklaunch?.showSearchSuggestions ??
|
||||||
|
searchWidget?.options?.showSearchSuggestions ??
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
return searchProvider;
|
return searchProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +154,7 @@ export default function QuickLaunch({ servicesAndBookmarks, searchString, setSea
|
|||||||
type: "search",
|
type: "search",
|
||||||
});
|
});
|
||||||
|
|
||||||
if (showSearchSuggestions && searchProvider.suggestionUrl) {
|
if (searchProvider.showSearchSuggestions && searchProvider.suggestionUrl) {
|
||||||
if (searchString.trim() !== searchSuggestions[0]?.trim()) {
|
if (searchString.trim() !== searchSuggestions[0]?.trim()) {
|
||||||
fetch(
|
fetch(
|
||||||
`/api/search/searchSuggestion?query=${encodeURIComponent(searchString)}&providerName=${
|
`/api/search/searchSuggestion?query=${encodeURIComponent(searchString)}&providerName=${
|
||||||
@ -182,17 +207,7 @@ export default function QuickLaunch({ servicesAndBookmarks, searchString, setSea
|
|||||||
return () => {
|
return () => {
|
||||||
abortController.abort();
|
abortController.abort();
|
||||||
};
|
};
|
||||||
}, [
|
}, [searchString, servicesAndBookmarks, searchDescriptions, hideVisitURL, searchSuggestions, searchProvider, url, t]);
|
||||||
searchString,
|
|
||||||
servicesAndBookmarks,
|
|
||||||
searchDescriptions,
|
|
||||||
hideVisitURL,
|
|
||||||
showSearchSuggestions,
|
|
||||||
searchSuggestions,
|
|
||||||
searchProvider,
|
|
||||||
url,
|
|
||||||
t,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const [hidden, setHidden] = useState(true);
|
const [hidden, setHidden] = useState(true);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user