From 4e17628f971ad1bdc85baad9ec206193cf4c0c1d Mon Sep 17 00:00:00 2001 From: Alex Sinelnikov Date: Mon, 30 Jan 2023 10:16:45 +0200 Subject: [PATCH] Added search to quicklaunch --- public/locales/en/common.json | 7 ++++--- src/components/quicklaunch.jsx | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 34058db9c..f2e09f581 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -282,7 +282,8 @@ }, "quicklaunch": { "bookmark": "Bookmark", - "service": "Service" + "service": "Service", + "searchGoogle": "Search Google" }, "wmo": { "0-day": "Sunny", @@ -432,7 +433,7 @@ }, "cloudflared": { "origin_ip": "Origin IP", - "status": "Status" + "status": "Status" }, "proxmoxbackupserver": { "datastore_usage": "Datastore", @@ -446,4 +447,4 @@ "videos": "Videos", "storage": "Storage" } -} \ No newline at end of file +} diff --git a/src/components/quicklaunch.jsx b/src/components/quicklaunch.jsx index 050de448f..b7dbba458 100644 --- a/src/components/quicklaunch.jsx +++ b/src/components/quicklaunch.jsx @@ -34,7 +34,7 @@ export default function QuickLaunch({servicesAndBookmarks, searchString, setSear function handleSearchKeyDown(event) { if (!isOpen) return; - + if (event.key === "Escape") { closeAndReset(); event.preventDefault(); @@ -50,6 +50,7 @@ export default function QuickLaunch({servicesAndBookmarks, searchString, setSear } } + function handleItemHover(event) { setCurrentItemIndex(parseInt(event.target?.dataset?.index, 10)); } @@ -75,6 +76,15 @@ export default function QuickLaunch({servicesAndBookmarks, searchString, setSear if (searchDescriptions) { newResults = newResults.sort((a, b) => b.priority - a.priority); } + newResults.push( + { + name: searchString, + href: `http://google.com/search?q=${searchString}`, + description: t("quicklaunch.searchGoogle"), + type: 'service', + weight: 1 + } + ) setResults(newResults); @@ -82,7 +92,7 @@ export default function QuickLaunch({servicesAndBookmarks, searchString, setSear setCurrentItemIndex(0); } } - }, [searchString, servicesAndBookmarks, searchDescriptions]); + }, [searchString, servicesAndBookmarks, searchDescriptions, t]); const [hidden, setHidden] = useState(true); @@ -90,7 +100,7 @@ export default function QuickLaunch({servicesAndBookmarks, searchString, setSear function handleBackdropClick(event) { if (event.target?.tagName === "DIV") closeAndReset(); } - + if (isOpen) { searchField.current.focus(); document.body.addEventListener('click', handleBackdropClick); @@ -141,7 +151,7 @@ export default function QuickLaunch({servicesAndBookmarks, searchString, setSear
{r.name} - {r.description && + {r.description && {searchDescriptions && r.priority < 2 ? highlightText(r.description) : r.description}