Cmen
3 years ago
13 changed files with 121 additions and 2 deletions
@ -0,0 +1,41 @@
|
||||
import { Modal, Input } from "antd"; |
||||
import { debounce } from "lodash"; |
||||
import { useState } from "react"; |
||||
import { editorAction, searchResultsSelector } from "@store"; |
||||
import { useSelector } from "react-redux"; |
||||
|
||||
export type SearchModalProps = { |
||||
visible: boolean; |
||||
onCancel: () => void; |
||||
}; |
||||
|
||||
const delaySearch = debounce((keyword: string) => { |
||||
editorAction.searchPlace(keyword); |
||||
}, 500); |
||||
|
||||
export const SearchModal = (props: SearchModalProps) => { |
||||
const { visible, onCancel } = props; |
||||
const [keyword, setKeyword] = useState(""); |
||||
const searchResults = useSelector(searchResultsSelector); |
||||
const searchPlace = (keyword: string) => { |
||||
setKeyword(keyword); |
||||
delaySearch(keyword); |
||||
}; |
||||
|
||||
return ( |
||||
<Modal visible={visible} onCancel={onCancel} footer={[]} title="搜索定位"> |
||||
<Input |
||||
placeholder="输入关键字" |
||||
value={keyword} |
||||
onChange={(e) => searchPlace(e.target.value)} |
||||
/> |
||||
<div className="search-result-container"> |
||||
{searchResults.map((item) => ( |
||||
<div key={item.name} className="search-result-item"> |
||||
{item.name} |
||||
</div> |
||||
))} |
||||
</div> |
||||
</Modal> |
||||
); |
||||
}; |
Loading…
Reference in new issue