mirror of
https://github.com/pawelmalak/flame.git
synced 2026-03-10 22:43:11 +08:00
Local search for apps
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user