From af147c0da012e611abd1cc76757d3debb10f23f0 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 27 Feb 2023 18:21:24 -0800 Subject: [PATCH 2/2] Support open url in quicklaunch --- public/locales/en/common.json | 4 +++- src/components/quicklaunch.jsx | 28 +++++++++++++++++++++++++--- src/pages/index.jsx | 1 - 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 5b3608b69..ba88d14cc 100755 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -286,7 +286,9 @@ "bookmark": "Bookmark", "service": "Service", "search": "Search", - "custom": "Custom" + "custom": "Custom", + "visit": "Visit", + "url": "URL" }, "wmo": { "0-day": "Sunny", diff --git a/src/components/quicklaunch.jsx b/src/components/quicklaunch.jsx index cc19aaf94..fbcae2c76 100644 --- a/src/components/quicklaunch.jsx +++ b/src/components/quicklaunch.jsx @@ -6,14 +6,16 @@ import ResolvedIcon from "./resolvedicon"; import { SettingsContext } from "utils/contexts/settings"; -export default function QuickLaunch({servicesAndBookmarks, searchString, setSearchString, isOpen, close, searchDescriptions, searchProvider}) { +export default function QuickLaunch({servicesAndBookmarks, searchString, setSearchString, isOpen, close, searchProvider}) { const { t } = useTranslation(); const { settings } = useContext(SettingsContext); + const { searchDescriptions, hideVisitURL } = settings?.quicklaunch ? settings.quicklaunch : { searchDescriptions: false, hideVisitURL: false }; const searchField = useRef(); const [results, setResults] = useState([]); const [currentItemIndex, setCurrentItemIndex] = useState(null); + const [url, setUrl] = useState(null); function openCurrentItem(newWindow) { const result = results[currentItemIndex]; @@ -29,7 +31,16 @@ export default function QuickLaunch({servicesAndBookmarks, searchString, setSear }, [close, setSearchString, setCurrentItemIndex]); function handleSearchChange(event) { - setSearchString(event.target.value.toLowerCase()) + const rawSearchString = event.target.value.toLowerCase(); + try { + if (!/.+[.:].+/g.test(rawSearchString)) throw new Error(); // basic test for probably a url + let urlString = rawSearchString; + if (urlString.indexOf('http') !== 0) urlString = `https://${rawSearchString}`; + setUrl(new URL(urlString)); // basic validation + } catch (e) { + setUrl(null); + } + setSearchString(rawSearchString); } function handleSearchKeyDown(event) { @@ -76,6 +87,7 @@ export default function QuickLaunch({servicesAndBookmarks, searchString, setSear if (searchDescriptions) { newResults = newResults.sort((a, b) => b.priority - a.priority); } + if (searchProvider) { newResults.push( { @@ -86,13 +98,23 @@ export default function QuickLaunch({servicesAndBookmarks, searchString, setSear ) } + if (!hideVisitURL && url) { + newResults.unshift( + { + href: url.toString(), + name: `${t("quicklaunch.visit")} URL`, + type: 'url', + } + ) + } + setResults(newResults); if (newResults.length) { setCurrentItemIndex(0); } } - }, [searchString, servicesAndBookmarks, searchDescriptions, searchProvider, t]); + }, [searchString, servicesAndBookmarks, searchDescriptions, hideVisitURL, searchProvider, url, t]); const [hidden, setHidden] = useState(true); diff --git a/src/pages/index.jsx b/src/pages/index.jsx index 3eacc60e4..00852436e 100644 --- a/src/pages/index.jsx +++ b/src/pages/index.jsx @@ -265,7 +265,6 @@ function Home({ initialSettings }) { setSearchString={setSearchString} isOpen={searching} close={setSearching} - searchDescriptions={settings.quicklaunch?.searchDescriptions} searchProvider={settings.quicklaunch?.hideInternetSearch ? null : searchProvider} /> {widgets && (