mirror of
https://github.com/pawelmalak/flame.git
synced 2025-08-05 19:05:18 +02:00
Live search for apps
This commit is contained in:
parent
6ae6c58f4c
commit
fac280ff0a
3 changed files with 32 additions and 18 deletions
|
@ -28,16 +28,28 @@ const SearchBar = (props: ComponentProps): JSX.Element => {
|
|||
}, []);
|
||||
|
||||
const searchHandler = (e: KeyboardEvent<HTMLInputElement>) => {
|
||||
if (e.code === 'Enter') {
|
||||
const searchResult = searchParser(inputRef.current.value);
|
||||
const searchResult = searchParser(inputRef.current.value);
|
||||
|
||||
if (!searchResult.prefix) {
|
||||
if (searchResult.isLocal) {
|
||||
setLocalSearch(searchResult.search);
|
||||
}
|
||||
|
||||
if (e.code === 'Enter') {
|
||||
if (!searchResult.query.prefix) {
|
||||
createNotification({
|
||||
title: 'Error',
|
||||
message: 'Prefix not found',
|
||||
});
|
||||
} else if (searchResult.isLocal) {
|
||||
setLocalSearch(searchResult.query);
|
||||
setLocalSearch(searchResult.search);
|
||||
} else {
|
||||
if (searchResult.sameTab) {
|
||||
document.location.replace(
|
||||
`${searchResult.query.template}${searchResult.search}`
|
||||
);
|
||||
} else {
|
||||
window.open(`${searchResult.query.template}${searchResult.search}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -47,7 +59,7 @@ const SearchBar = (props: ComponentProps): JSX.Element => {
|
|||
ref={inputRef}
|
||||
type="text"
|
||||
className={classes.SearchBar}
|
||||
onKeyDown={(e) => searchHandler(e)}
|
||||
onKeyUp={(e) => searchHandler(e)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue