From 1dae378270bf4e5290923fd0e95b308f01467644 Mon Sep 17 00:00:00 2001 From: Bhwa233 <404174262@qq.com> Date: Fri, 1 Mar 2024 16:52:50 +0800 Subject: [PATCH] =?UTF-8?q?fukasawa=E6=94=AF=E6=8C=81algolia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/fukasawa/components/SearchInput.js | 28 +++- themes/fukasawa/index.js | 173 +++++++++++----------- 2 files changed, 109 insertions(+), 92 deletions(-) diff --git a/themes/fukasawa/components/SearchInput.js b/themes/fukasawa/components/SearchInput.js index ba918f56..bd7ea099 100644 --- a/themes/fukasawa/components/SearchInput.js +++ b/themes/fukasawa/components/SearchInput.js @@ -1,9 +1,12 @@ import { useGlobal } from '@/lib/global' import { useRouter } from 'next/router' import { useImperativeHandle, useRef, useState } from 'react' +import { useFukasawaGlobal } from '@/themes/fukasawa' +import { siteConfig } from '@/lib/config' const SearchInput = (props) => { const { keyword, cRef } = props + const { searchModal } = useFukasawaGlobal() const [onLoading, setLoadingState] = useState(false) const { locale } = useGlobal() const router = useRouter() @@ -20,6 +23,9 @@ const SearchInput = (props) => { * 搜索 */ const handleSearch = () => { + if (siteConfig('ALGOLIA_APP_ID')) { + searchModal?.current?.openSearch() + } const key = searchInputRef.current.value if (key && key !== '') { setLoadingState(true) @@ -34,19 +40,28 @@ const SearchInput = (props) => { } /** - * 监听案件 + * 监听事件 * @param {*} e */ const handleKeyUp = (e) => { + if (siteConfig('ALGOLIA_APP_ID')) { + searchModal?.current?.openSearch() + return + } if (e.keyCode === 13) { // 回车 handleSearch(searchInputRef.current.value) } else if (e.keyCode === 27) { // ESC cleanSearch() } } - + const handleFocus = () => { + // 使用Algolia + if (siteConfig('ALGOLIA_APP_ID')) { + searchModal?.current?.openSearch() + } + } /** - * 清理索索 + * 清理索引 */ const cleanSearch = () => { searchInputRef.current.value = '' @@ -60,19 +75,20 @@ const SearchInput = (props) => { aria-label="Search" className={'outline-none w-full text-sm pl-2 transition focus:shadow-lg font-light leading-10 text-black bg-gray-100 dark:bg-gray-800 dark:text-white'} onKeyUp={handleKeyUp} + onFocus={handleFocus} defaultValue={keyword || ''} />