phanpy/src/components/compose-button.jsx

34 lines
754 B
React
Raw Normal View History

import { useHotkeys } from 'react-hotkeys-hook';
2023-09-05 10:49:16 +00:00
import openCompose from '../utils/open-compose';
import states from '../utils/states';
import Icon from './icon';
export default function ComposeButton() {
function handleButton(e) {
if (e.shiftKey) {
const newWin = openCompose();
if (!newWin) {
states.showCompose = true;
}
} else {
states.showCompose = true;
}
}
2023-09-05 10:49:16 +00:00
useHotkeys('c, shift+c', handleButton, {
ignoreEventWhen: (e) => {
const hasModal = !!document.querySelector('#modal-container > *');
return hasModal;
},
});
return (
<button type="button" id="compose-button" onClick={handleButton}>
2023-09-05 10:49:16 +00:00
<Icon icon="quill" size="xl" alt="Compose" />
</button>
);
}