diff --git a/src/components/nav-menu.jsx b/src/components/nav-menu.jsx index b67053f4..14fd26dd 100644 --- a/src/components/nav-menu.jsx +++ b/src/components/nav-menu.jsx @@ -1,4 +1,11 @@ -import { Menu, MenuDivider, MenuItem } from '@szhsin/react-menu'; +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'; @@ -39,147 +46,162 @@ function NavMenu(props) { }, ); + 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… + + + )} - - - )} - > - {!!snapStates.appVersion?.commitHash && - __COMMIT_HASH__ !== snapStates.appVersion.commitHash && ( + + Home + + {authenticated && ( <> - { - const yes = confirm('Reload page now to update?'); - if (yes) { - (async () => { - try { - location.reload(); - } catch (e) {} - })(); - } - }} - > - {' '} - New update available… - + {showFollowing && ( + + Following + + )} + + Mentions + + + Notifications + {snapStates.notificationsShowNew && ( + + {' '} + • + + )} + + + Lists + + + Followed Hashtags + + + Bookmarks + + + Favourites + )} - - Home - - {authenticated && ( - <> - {showFollowing && ( - - Following - - )} - - Mentions - - - Notifications - {snapStates.notificationsShowNew && ( - - {' '} - • - + + + Search + + + Local + + + Federated + + + Trending + + {authenticated && ( + <> + + {currentAccount?.info?.id && ( + + Profile + )} - - - - 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… - - - )} - + { + states.showAccounts = true; + }} + > + Accounts… + + { + states.showShortcutsSettings = true; + }} + > + {' '} + Shortcuts Settings… + + { + states.showSettings = true; + }} + > + Settings… + + + )} + + ); }