diff --git a/src/components/menu.jsx b/src/components/menu.jsx deleted file mode 100644 index 7c24dcd3..00000000 --- a/src/components/menu.jsx +++ /dev/null @@ -1,185 +0,0 @@ -import { Menu, MenuDivider, MenuItem } from '@szhsin/react-menu'; -import { useLongPress } from 'use-long-press'; -import { useSnapshot } from 'valtio'; - -import { api } from '../utils/api'; -import states from '../utils/states'; -import store from '../utils/store'; - -import Avatar from './avatar'; -import Icon from './icon'; -import MenuLink from './menu-link'; - -function NavMenu(props) { - const snapStates = useSnapshot(states); - const { instance, authenticated } = api(); - const accounts = store.local.getJSON('accounts') || []; - const currentAccount = accounts.find( - (account) => account.info.id === store.session.get('currentAccount'), - ); - const moreThanOneAccount = accounts.length > 1; - - // Home = Following - // But when in multi-column mode, Home becomes columns of anything - // User may choose pin or not to pin Following - // If user doesn't pin Following, we show it in the menu - const showFollowing = - (snapStates.settings.shortcutsColumnsMode || - snapStates.settings.shortcutsViewMode === 'multi-column') && - !snapStates.shortcuts.find((pin) => pin.type === 'following'); - - const bindLongPress = useLongPress( - () => { - states.showAccounts = true; - }, - { - threshold: 600, - detect: 'touch', - cancelOnMovement: true, - }, - ); - - return ( - ( - - )} - > - {!!snapStates.appVersion?.commitHash && - __COMMIT_HASH__ !== snapStates.appVersion.commitHash && ( - <> - { - const yes = confirm('Reload page now to update?'); - if (yes) { - (async () => { - try { - location.reload(); - } catch (e) {} - })(); - } - }} - > - {' '} - New update available… - - - - )} - - Home - - {authenticated && ( - <> - {showFollowing && ( - - Following - - )} - - Mentions - - - Notifications - {snapStates.notificationsShowNew && ( - - {' '} - • - - )} - - - - Lists - - - Followed Hashtags - - - Bookmarks - - - Favourites - - - )} - - - Search - - - Local - - - Federated - - - Trending - - {authenticated && ( - <> - - {currentAccount?.info?.id && ( - - Profile - - )} - { - states.showAccounts = true; - }} - > - Accounts… - - { - states.showShortcutsSettings = true; - }} - > - {' '} - Shortcuts Settings… - - { - states.showSettings = true; - }} - > - Settings… - - - )} - - ); -} - -export default NavMenu; diff --git a/src/components/nav-menu.jsx b/src/components/nav-menu.jsx new file mode 100644 index 00000000..14fd26dd --- /dev/null +++ b/src/components/nav-menu.jsx @@ -0,0 +1,208 @@ +import { + ControlledMenu, + MenuDivider, + MenuItem, + useClick, + useMenuState, +} from '@szhsin/react-menu'; +import { useRef } from 'preact/hooks'; +import { useLongPress } from 'use-long-press'; +import { useSnapshot } from 'valtio'; + +import { api } from '../utils/api'; +import states from '../utils/states'; +import store from '../utils/store'; + +import Avatar from './avatar'; +import Icon from './icon'; +import MenuLink from './menu-link'; + +function NavMenu(props) { + const snapStates = useSnapshot(states); + const { instance, authenticated } = api(); + const accounts = store.local.getJSON('accounts') || []; + const currentAccount = accounts.find( + (account) => account.info.id === store.session.get('currentAccount'), + ); + const moreThanOneAccount = accounts.length > 1; + + // Home = Following + // But when in multi-column mode, Home becomes columns of anything + // User may choose pin or not to pin Following + // If user doesn't pin Following, we show it in the menu + const showFollowing = + (snapStates.settings.shortcutsColumnsMode || + snapStates.settings.shortcutsViewMode === 'multi-column') && + !snapStates.shortcuts.find((pin) => pin.type === 'following'); + + const bindLongPress = useLongPress( + () => { + states.showAccounts = true; + }, + { + threshold: 600, + detect: 'touch', + cancelOnMovement: true, + }, + ); + + const buttonRef = useRef(); + const [menuState, toggleMenu] = useMenuState(); + const anchorProps = useClick(menuState.state, toggleMenu); + + return ( + <> + + { + toggleMenu(false); + }} + containerProps={{ + onClick: () => { + toggleMenu(false); + }, + }} + portal={{ + target: document.body, + }} + {...props} + overflow="auto" + viewScroll="close" + boundingBoxPadding="8 8 8 8" + unmountOnClose + > + {!!snapStates.appVersion?.commitHash && + __COMMIT_HASH__ !== snapStates.appVersion.commitHash && ( + <> + { + const yes = confirm('Reload page now to update?'); + if (yes) { + (async () => { + try { + location.reload(); + } catch (e) {} + })(); + } + }} + > + {' '} + New update available… + + + + )} + + Home + + {authenticated && ( + <> + {showFollowing && ( + + Following + + )} + + Mentions + + + Notifications + {snapStates.notificationsShowNew && ( + + {' '} + • + + )} + + + + Lists + + + Followed Hashtags + + + Bookmarks + + + Favourites + + + )} + + + Search + + + Local + + + Federated + + + Trending + + {authenticated && ( + <> + + {currentAccount?.info?.id && ( + + Profile + + )} + { + states.showAccounts = true; + }} + > + Accounts… + + { + states.showShortcutsSettings = true; + }} + > + {' '} + Shortcuts Settings… + + { + states.showSettings = true; + }} + > + Settings… + + + )} + + + ); +} + +export default NavMenu; diff --git a/src/components/status.jsx b/src/components/status.jsx index 074db7a8..0ed25459 100644 --- a/src/components/status.jsx +++ b/src/components/status.jsx @@ -679,6 +679,8 @@ function Status({ }, ); + const showContextMenu = size !== 'l' && !previewMode && !_deleted; + return (
{ - if (size === 'l') return; + if (!showContextMenu) return; if (e.metaKey) return; - if (previewMode) return; - if (_deleted) return; // console.log('context menu', e); const link = e.target.closest('a'); if (link && /^https?:\/\//.test(link.getAttribute('href'))) return; @@ -708,9 +708,9 @@ function Status({ }); setIsContextMenuOpen(true); }} - {...bindLongPress()} + {...(showContextMenu ? bindLongPress() : {})} > - {size !== 'l' && ( + {showContextMenu && (
- + {headerStart !== null && headerStart !== undefined ? ( headerStart ) : ( diff --git a/src/pages/followed-hashtags.jsx b/src/pages/followed-hashtags.jsx index 5e07a53f..ba107332 100644 --- a/src/pages/followed-hashtags.jsx +++ b/src/pages/followed-hashtags.jsx @@ -3,7 +3,7 @@ import { useEffect, useState } from 'preact/hooks'; import Icon from '../components/icon'; import Link from '../components/link'; import Loader from '../components/loader'; -import Menu from '../components/menu'; +import NavMenu from '../components/nav-menu'; import { api } from '../utils/api'; import useTitle from '../utils/useTitle'; @@ -45,7 +45,7 @@ function FollowedHashtags() {
- + diff --git a/src/pages/lists.jsx b/src/pages/lists.jsx index 5aa3ceea..a8dbb119 100644 --- a/src/pages/lists.jsx +++ b/src/pages/lists.jsx @@ -6,8 +6,8 @@ import Icon from '../components/icon'; import Link from '../components/link'; import ListAddEdit from '../components/list-add-edit'; import Loader from '../components/loader'; -import Menu from '../components/menu'; import Modal from '../components/modal'; +import NavMenu from '../components/nav-menu'; import { api } from '../utils/api'; import useTitle from '../utils/useTitle'; @@ -41,7 +41,7 @@ function Lists() {
- + diff --git a/src/pages/notifications.jsx b/src/pages/notifications.jsx index 9476fdb9..4492263f 100644 --- a/src/pages/notifications.jsx +++ b/src/pages/notifications.jsx @@ -8,8 +8,8 @@ import Avatar from '../components/avatar'; import Icon from '../components/icon'; import Link from '../components/link'; import Loader from '../components/loader'; -import Menu from '../components/menu'; import NameText from '../components/name-text'; +import NavMenu from '../components/nav-menu'; import RelativeTime from '../components/relative-time'; import Status from '../components/status'; import { api } from '../utils/api'; @@ -166,7 +166,7 @@ function Notifications() { >
- + diff --git a/src/pages/search.jsx b/src/pages/search.jsx index ba12823e..d6e9a7ac 100644 --- a/src/pages/search.jsx +++ b/src/pages/search.jsx @@ -7,7 +7,7 @@ import AccountBlock from '../components/account-block'; import Icon from '../components/icon'; import Link from '../components/link'; import Loader from '../components/loader'; -import Menu from '../components/menu'; +import NavMenu from '../components/nav-menu'; import Status from '../components/status'; import { api } from '../utils/api'; import useTitle from '../utils/useTitle'; @@ -53,7 +53,7 @@ function Search(props) {
- +
{