From b16aadf7a254bfc4f8500d6da92e868c3013aac7 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 8 Mar 2023 22:39:26 +0800 Subject: [PATCH] theme-simple searchInput --- themes/simple/LayoutSearch.js | 4 -- themes/simple/components/SearchInput.js | 87 ------------------------- 2 files changed, 91 deletions(-) delete mode 100644 themes/simple/components/SearchInput.js diff --git a/themes/simple/LayoutSearch.js b/themes/simple/LayoutSearch.js index 23b10b7a..1ba8fef7 100644 --- a/themes/simple/LayoutSearch.js +++ b/themes/simple/LayoutSearch.js @@ -3,7 +3,6 @@ import { BlogListPage } from './components/BlogListPage' import { BlogListScroll } from './components/BlogListScroll' import { useRouter } from 'next/router' import { useEffect } from 'react' -import SearchInput from './components/SearchInput' import Mark from 'mark.js' import LayoutBase from './LayoutBase' import { isBrowser } from '@/lib/utils' @@ -44,9 +43,6 @@ export const LayoutSearch = props => { }, []) return -
- -
{BLOG.POST_LIST_STYLE === 'page' ? : } diff --git a/themes/simple/components/SearchInput.js b/themes/simple/components/SearchInput.js deleted file mode 100644 index 6a95ba01..00000000 --- a/themes/simple/components/SearchInput.js +++ /dev/null @@ -1,87 +0,0 @@ -import { useRouter } from 'next/router' -import { useGlobal } from '@/lib/global' -import { useImperativeHandle, useRef, useState } from 'react' - -let lock = false - -const SearchInput = ({ currentTag, currentSearch, cRef }) => { - const { locale } = useGlobal() - const router = useRouter() - const searchInputRef = useRef(null) - useImperativeHandle(cRef, () => { - return { - focus: () => { - searchInputRef?.current?.focus() - } - } - }) - const handleSearch = () => { - const key = searchInputRef.current.value - if (key && key !== '') { - router.push({ pathname: '/search/' + key }).then(r => { - console.log('搜索', key) - }) - } else { - router.push({ pathname: '/' }).then(r => { - }) - } - } - const handleKeyUp = (e) => { - if (e.keyCode === 13) { // 回车 - handleSearch(searchInputRef.current.value) - } else if (e.keyCode === 27) { // ESC - cleanSearch() - } - } - const cleanSearch = () => { - searchInputRef.current.value = '' - setShowClean(false) - } - function lockSearchInput () { - lock = true - } - - function unLockSearchInput () { - lock = false - } - const [showClean, setShowClean] = useState(false) - const updateSearchKey = (val) => { - if (lock) { - return - } - searchInputRef.current.value = val - if (val) { - setShowClean(true) - } else { - setShowClean(false) - } - } - - return
- updateSearchKey(e.target.value)} - defaultValue={currentSearch || ''} - /> - -
- -
- - {(showClean && -
- -
- )} -
-} - -export default SearchInput