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

Local search for apps

This commit is contained in:
unknown 2021-09-06 12:24:01 +02:00
parent 8521995758
commit 6ae6c58f4c
14 changed files with 297 additions and 4751 deletions

View file

@ -15,36 +15,41 @@ import { searchParser } from '../../utility';
interface ComponentProps {
createNotification: (notification: NewNotification) => void;
setLocalSearch: (query: string) => void;
}
const SearchBar = (props: ComponentProps): JSX.Element => {
const { setLocalSearch, createNotification } = props;
const inputRef = useRef<HTMLInputElement>(document.createElement('input'));
useEffect(() => {
inputRef.current.focus();
}, [])
}, []);
const searchHandler = (e: KeyboardEvent<HTMLInputElement>) => {
if (e.code === 'Enter') {
const prefixFound = searchParser(inputRef.current.value);
const searchResult = searchParser(inputRef.current.value);
if (!prefixFound) {
props.createNotification({
if (!searchResult.prefix) {
createNotification({
title: 'Error',
message: 'Prefix not found'
})
message: 'Prefix not found',
});
} else if (searchResult.isLocal) {
setLocalSearch(searchResult.query);
}
}
}
};
return (
<input
ref={inputRef}
type='text'
type="text"
className={classes.SearchBar}
onKeyDown={(e) => searchHandler(e)}
/>
)
}
);
};
export default connect(null, { createNotification })(SearchBar);
export default connect(null, { createNotification })(SearchBar);