mirror of
https://github.com/yuruotong1/autoMate.git
synced 2025-12-26 05:16:21 +08:00
✨ ui(autoMate): 更新搜索组件样式和功能
📝 hooks(useSelect): 优化键盘事件处理逻辑,添加Esc键关闭搜索窗口功能
This commit is contained in:
parent
70b662b575
commit
c717ddf0cf
@ -6,21 +6,14 @@ 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" >
|
||||
<section className="bg-slate-200 p-3 rounded-lg flex items-center gap-1">
|
||||
<button className="bg-red-500" onClick={()=>{
|
||||
window.api.sql('select * from categories', 'findAll').then((res)=>{
|
||||
console.log(res)
|
||||
})
|
||||
}}>
|
||||
查询
|
||||
</button>
|
||||
<main className="bg-slate-50 p-3 rounded-lg drag" >
|
||||
<section className="bg-slate-200 p-3 rounded-lg flex items-center gap-1 nodrag">
|
||||
<SettingOne
|
||||
theme="outline"
|
||||
size="22"
|
||||
fill="#34495e"
|
||||
strokeWidth={4}
|
||||
className="cursor-pointer"
|
||||
className="cursor-pointer z-10"
|
||||
onClick={()=>window.api.openWindow('code')
|
||||
}
|
||||
/>
|
||||
|
||||
@ -7,16 +7,19 @@ export default()=>{
|
||||
const selectId = useStore((state)=>state.selectId)
|
||||
const setSelectId = useStore((state)=>state.setSelectId)
|
||||
const handleKeyEvent = useCallback((e: KeyboardEvent) => {
|
||||
// 初始没有数据,所以data.length为0 ,防止向上箭头,将数据变为-1
|
||||
if (data.length === 0) return
|
||||
|
||||
switch(e.key){
|
||||
case 'ArrowUp': {
|
||||
// 初始没有数据,所以data.length为0 ,防止向上箭头,将数据变为-1
|
||||
if (data.length === 0) return
|
||||
// 找到当前id的索引
|
||||
const index = data.findIndex((item)=>item.id === selectId)
|
||||
setSelectId(data[index - 1]?.id || data[data.length - 1].id)
|
||||
break
|
||||
}
|
||||
case 'ArrowDown':{
|
||||
// 初始没有数据,所以data.length为0 ,防止向上箭头,将数据变为-1
|
||||
if (data.length === 0) return
|
||||
// 找到当前id的索引
|
||||
const index = data.findIndex((item)=>item.id === selectId)
|
||||
setSelectId(data[index + 1]?.id || data[0].id)
|
||||
@ -26,6 +29,10 @@ export default()=>{
|
||||
select(selectId)
|
||||
break
|
||||
}
|
||||
case 'Escape': {
|
||||
window.api.closeWindow('search')
|
||||
break
|
||||
}
|
||||
}
|
||||
// 将 data 和 currentIndex 变化时,重新定义该函数,currentIndex会更新为最新值
|
||||
}, [data, selectId])
|
||||
@ -36,7 +43,7 @@ export default()=>{
|
||||
setData([])
|
||||
setSearch('')
|
||||
if (content) await navigator.clipboard.writeText(content)
|
||||
window.api.hideWindow()
|
||||
window.api.closeWindow('search')
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user