mirror of
https://github.com/10h30/astroplate.git
synced 2026-06-05 15:08:00 +09:00
update searchModal
This commit is contained in:
@@ -8,35 +8,9 @@ const SearchModal = () => {
|
||||
|
||||
// handle input change
|
||||
const handleSearch = (e: React.FormEvent<HTMLInputElement>) => {
|
||||
setSearchString(e.currentTarget.value.toLowerCase());
|
||||
setSearchString(e.currentTarget.value.replace("\\", "").toLowerCase());
|
||||
};
|
||||
|
||||
// set input value from url
|
||||
useEffect(() => {
|
||||
const searchUrl = new URLSearchParams(window.location.search);
|
||||
const searchStr = searchUrl.get("q");
|
||||
searchStr && setSearchString(searchStr.toLowerCase());
|
||||
|
||||
// set cursor position
|
||||
setTimeout(function () {
|
||||
searchInputRef.current!.selectionStart =
|
||||
searchInputRef.current!.selectionEnd = searchStr?.length || 0;
|
||||
}, 50);
|
||||
}, []);
|
||||
|
||||
// update url
|
||||
useEffect(() => {
|
||||
if (searchString.length > 0) {
|
||||
const searchParams = new URLSearchParams(window.location.search);
|
||||
searchParams.set("s", searchString);
|
||||
const newRelativePathQuery =
|
||||
window.location.pathname + "?" + searchParams.toString();
|
||||
history.pushState(null, "", newRelativePathQuery);
|
||||
} else {
|
||||
history.pushState(null, "", window.location.pathname);
|
||||
}
|
||||
}, [searchString]);
|
||||
|
||||
// generate search result
|
||||
const doSearch = (searchData: ISearchItem[]) => {
|
||||
const regex = new RegExp(`${searchString}`, "gi");
|
||||
|
||||
Reference in New Issue
Block a user