Experimental right-click/long-press on compose button
This commit is contained in:
parent
fb2c7d5ef7
commit
8ada3cebf8
2 changed files with 72 additions and 18 deletions
|
@ -1,17 +1,27 @@
|
||||||
import { useLingui } from '@lingui/react/macro';
|
import { Trans, useLingui } from '@lingui/react/macro';
|
||||||
|
import { ControlledMenu } from '@szhsin/react-menu';
|
||||||
|
import { useRef, useState } from 'preact/hooks';
|
||||||
import { useHotkeys } from 'react-hotkeys-hook';
|
import { useHotkeys } from 'react-hotkeys-hook';
|
||||||
|
import { useLongPress } from 'use-long-press';
|
||||||
import { useSnapshot } from 'valtio';
|
import { useSnapshot } from 'valtio';
|
||||||
|
|
||||||
import openCompose from '../utils/open-compose';
|
import openCompose from '../utils/open-compose';
|
||||||
import openOSK from '../utils/open-osk';
|
import openOSK from '../utils/open-osk';
|
||||||
|
import safeBoundingBoxPadding from '../utils/safe-bounding-box-padding';
|
||||||
import states from '../utils/states';
|
import states from '../utils/states';
|
||||||
|
|
||||||
import Icon from './icon';
|
import Icon from './icon';
|
||||||
|
import MenuLink from './menu-link';
|
||||||
|
|
||||||
export default function ComposeButton() {
|
export default function ComposeButton() {
|
||||||
const { t } = useLingui();
|
const { t } = useLingui();
|
||||||
const snapStates = useSnapshot(states);
|
const snapStates = useSnapshot(states);
|
||||||
|
|
||||||
|
// Context menu state
|
||||||
|
const [menuOpen, setMenuOpen] = useState(false);
|
||||||
|
const buttonRef = useRef(null);
|
||||||
|
const menuRef = useRef(null);
|
||||||
|
|
||||||
function handleButton(e) {
|
function handleButton(e) {
|
||||||
if (snapStates.composerState.minimized) {
|
if (snapStates.composerState.minimized) {
|
||||||
states.composerState.minimized = false;
|
states.composerState.minimized = false;
|
||||||
|
@ -38,16 +48,59 @@ export default function ComposeButton() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Setup longpress handler to open context menu
|
||||||
|
const bindLongPress = useLongPress(
|
||||||
|
() => {
|
||||||
|
setMenuOpen(true);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
threshold: 600,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<>
|
||||||
type="button"
|
<button
|
||||||
id="compose-button"
|
ref={buttonRef}
|
||||||
onClick={handleButton}
|
type="button"
|
||||||
class={`${snapStates.composerState.minimized ? 'min' : ''} ${
|
id="compose-button"
|
||||||
snapStates.composerState.publishing ? 'loading' : ''
|
onClick={handleButton}
|
||||||
} ${snapStates.composerState.publishingError ? 'error' : ''}`}
|
onContextMenu={(e) => {
|
||||||
>
|
e.preventDefault();
|
||||||
<Icon icon="quill" size="xl" alt={t`Compose`} />
|
setMenuOpen(true);
|
||||||
</button>
|
}}
|
||||||
|
{...bindLongPress()}
|
||||||
|
class={`${snapStates.composerState.minimized ? 'min' : ''} ${
|
||||||
|
snapStates.composerState.publishing ? 'loading' : ''
|
||||||
|
} ${snapStates.composerState.publishingError ? 'error' : ''}`}
|
||||||
|
>
|
||||||
|
<Icon icon="quill" size="xl" alt={t`Compose`} />
|
||||||
|
</button>
|
||||||
|
<ControlledMenu
|
||||||
|
ref={menuRef}
|
||||||
|
state={menuOpen ? 'open' : undefined}
|
||||||
|
anchorRef={buttonRef}
|
||||||
|
onClose={() => setMenuOpen(false)}
|
||||||
|
direction="top"
|
||||||
|
gap={8} // Add gap between menu and button
|
||||||
|
unmountOnClose
|
||||||
|
portal={{
|
||||||
|
target: document.body,
|
||||||
|
}}
|
||||||
|
boundingBoxPadding={safeBoundingBoxPadding()}
|
||||||
|
containerProps={{
|
||||||
|
style: {
|
||||||
|
zIndex: 1001,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<MenuLink to="/sp">
|
||||||
|
<Icon icon="schedule" size="l" />{' '}
|
||||||
|
<span>
|
||||||
|
<Trans>Scheduled Posts</Trans>
|
||||||
|
</span>
|
||||||
|
</MenuLink>
|
||||||
|
</ControlledMenu>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
15
src/locales/en.po
generated
15
src/locales/en.po
generated
|
@ -565,11 +565,18 @@ msgstr ""
|
||||||
msgid "Home"
|
msgid "Home"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/components/compose-button.jsx:50
|
#: src/components/compose-button.jsx:77
|
||||||
#: src/compose.jsx:38
|
#: src/compose.jsx:38
|
||||||
msgid "Compose"
|
msgid "Compose"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/components/compose-button.jsx:100
|
||||||
|
#: src/components/nav-menu.jsx:260
|
||||||
|
#: src/pages/scheduled-posts.jsx:31
|
||||||
|
#: src/pages/scheduled-posts.jsx:76
|
||||||
|
msgid "Scheduled Posts"
|
||||||
|
msgstr "Scheduled Posts"
|
||||||
|
|
||||||
#: src/components/compose.jsx:211
|
#: src/components/compose.jsx:211
|
||||||
msgid "Add media"
|
msgid "Add media"
|
||||||
msgstr "Add media"
|
msgstr "Add media"
|
||||||
|
@ -1412,12 +1419,6 @@ msgstr ""
|
||||||
msgid "Followed Hashtags"
|
msgid "Followed Hashtags"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/components/nav-menu.jsx:260
|
|
||||||
#: src/pages/scheduled-posts.jsx:31
|
|
||||||
#: src/pages/scheduled-posts.jsx:76
|
|
||||||
msgid "Scheduled Posts"
|
|
||||||
msgstr "Scheduled Posts"
|
|
||||||
|
|
||||||
#: src/components/nav-menu.jsx:268
|
#: src/components/nav-menu.jsx:268
|
||||||
#: src/pages/account-statuses.jsx:326
|
#: src/pages/account-statuses.jsx:326
|
||||||
#: src/pages/filters.jsx:54
|
#: src/pages/filters.jsx:54
|
||||||
|
|
Loading…
Add table
Reference in a new issue