1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-08-05 02:45:18 +02:00

Live search for apps

This commit is contained in:
unknown 2021-09-06 12:47:17 +02:00
parent 6ae6c58f4c
commit fac280ff0a
3 changed files with 32 additions and 18 deletions

View file

@ -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)}
/>
);
};