🐛 修复(Search/index.tsx):删除未使用的useStore导入和search变量

🔧 更新(useSearch.ts):优化搜索逻辑,添加默认搜索字符串
♻️ 重构(useSearch.ts):简化返回对象,去除不必要的search变量和状态管理器更新
This commit is contained in:
yuruo
2024-06-24 11:00:18 +08:00
parent ac5054d6c0
commit 8a9b4e4867
3 changed files with 7 additions and 11 deletions

View File

@@ -1,9 +1,7 @@
import { useStore } from "@renderer/store/useStore"
import useSearch from "@renderer/hooks/useSearch"
import { SettingOne } from "@icon-park/react"
import { Input } from "antd"
export default function Search(): JSX.Element {
const search = useStore((state)=>state.search)
const {handleSearch} = useSearch()
return (
<main className="bg-slate-50 p-3 rounded-lg drag" >
@@ -19,7 +17,6 @@ export default function Search(): JSX.Element {
/>
<Input
placeholder="请输入内容"
value={search}
onChange={handleSearch}
autoFocus
/>

View File

@@ -4,15 +4,15 @@ import { useStore } from "@renderer/store/useStore"
export default()=>{
// const {setData} = useCode()
const setData = useStore((state)=>state.setData)
// const [search, setSearch] = useState('')
const search = useStore((state)=>state.search)
const handleSearch = async (e: ChangeEvent<HTMLInputElement>) => {
let inputValue = e.target.value ? e.target.value : "#####@@@@@@@@@@!$%^&&"
const data = await window.api.sql(
`select * from contents where title like @content`,
'findAll',
{content: `%${e.target.value}%`})
`select * from contents where title like @content`,
'findAll',
{content: `%${inputValue}%`})
setData(data as ContentType[])
}
return {search, handleSearch}
return {handleSearch}
}

View File

@@ -1,9 +1,8 @@
import { DataType } from "@renderer/data";
import { create } from "zustand";
interface StateProps{
config: ConfigDataType,
setConfig: (config: ConfigDataType) => void,
data: DataType[],
data: ContentType[],
setData: (data: ContentType[]) => void,
search: string,
setSearch: (search: string) => void,