phanpy/src/components/compose-button.jsx
2024-04-13 00:11:00 +08:00

34 lines
808 B
JavaScript

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