Refactor quicklaunch fallback to search widget suggestions setting

This commit is contained in:
shamoon 2024-01-30 10:10:06 -08:00
parent 2729a3b03e
commit ef25756534
2 changed files with 5 additions and 16 deletions

View File

@ -1,7 +1,6 @@
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";
@ -17,18 +16,11 @@ export default function QuickLaunch({
}) { }) {
const { t } = useTranslation(); const { t } = useTranslation();
const { data: widgets } = useSWR("/api/widgets");
const searchWidget = Object.values(widgets).find((w) => w.type === "search");
const { settings } = useContext(SettingsContext); const { settings } = useContext(SettingsContext);
const { searchDescriptions, hideVisitURL } = settings?.quicklaunch const { searchDescriptions = false, hideVisitURL = false } = settings?.quicklaunch ?? {};
? settings.quicklaunch const showSearchSuggestions = !!(
: { settings?.quicklaunch?.showSearchSuggestions ?? searchProvider.showSearchSuggestions
searchDescriptions: false, );
hideVisitURL: false,
};
const showSearchSuggestions =
settings?.quicklaunch?.showSearchSuggestions ?? searchWidget.options.showSearchSuggestions ?? false;
const searchField = useRef(); const searchField = useRef();

View File

@ -211,10 +211,7 @@ function Home({ initialSettings }) {
// if search provider is a list, try to retrieve from localstorage, fall back to the first // if search provider is a list, try to retrieve from localstorage, fall back to the first
searchProvider = getStoredProvider() ?? searchProviders[searchWidget.options.provider[0]]; searchProvider = getStoredProvider() ?? searchProviders[searchWidget.options.provider[0]];
} else if (searchWidget.options?.provider === "custom") { } else if (searchWidget.options?.provider === "custom") {
searchProvider = { searchProvider = searchWidget.options;
url: searchWidget.options.url,
suggestionUrl: searchWidget.options.suggestionUrl,
};
} else { } else {
searchProvider = searchProviders[searchWidget.options?.provider]; searchProvider = searchProviders[searchWidget.options?.provider];
} }