2020-04-04 05:39:53 +00:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
2020-07-05 01:46:09 +00:00
|
|
|
import { faSearch } from '@fortawesome/free-solid-svg-icons';
|
2020-04-04 05:39:53 +00:00
|
|
|
import useEventListener from '@/plugins/useEventListener';
|
|
|
|
import SearchModal from '@/components/dashboard/search/SearchModal';
|
|
|
|
|
|
|
|
export default () => {
|
|
|
|
const [ visible, setVisible ] = useState(false);
|
|
|
|
|
|
|
|
useEventListener('keydown', (e: KeyboardEvent) => {
|
|
|
|
if ([ 'input', 'textarea' ].indexOf(((e.target as HTMLElement).tagName || 'input').toLowerCase()) < 0) {
|
2020-12-25 23:55:31 +00:00
|
|
|
if (!visible && e.metaKey && e.key.toLowerCase() === '/') {
|
2020-04-04 05:39:53 +00:00
|
|
|
setVisible(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{visible &&
|
|
|
|
<SearchModal
|
2020-07-04 22:19:46 +00:00
|
|
|
appear
|
2020-04-04 05:39:53 +00:00
|
|
|
visible={visible}
|
|
|
|
onDismissed={() => setVisible(false)}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
<div className={'navigation-link'} onClick={() => setVisible(true)}>
|
|
|
|
<FontAwesomeIcon icon={faSearch}/>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|