Skip to content

Commit

Permalink
Further expand usage of SubMenu2
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeaun committed Apr 4, 2024
1 parent 2ad9706 commit 015ed5e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 54 deletions.
9 changes: 5 additions & 4 deletions src/components/account-info.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import './account-info.css';

import { Menu, MenuDivider, MenuItem, SubMenu } from '@szhsin/react-menu';
import { MenuDivider, MenuItem } from '@szhsin/react-menu';
import {
useCallback,
useEffect,
Expand All @@ -11,7 +11,6 @@ import {
} from 'preact/hooks';
import punycode from 'punycode';

import MenuLink from '../components/menu-link';
import { api } from '../utils/api';
import enhanceContent from '../utils/enhance-content';
import getHTMLText from '../utils/getHTMLText';
Expand All @@ -34,7 +33,9 @@ import ListAddEdit from './list-add-edit';
import Loader from './loader';
import Menu2 from './menu2';
import MenuConfirm from './menu-confirm';
import MenuLink from './menu-link';
import Modal from './modal';
import SubMenu2 from './submenu2';
import TranslationBlock from './translation-block';

const MUTE_DURATIONS = [
Expand Down Expand Up @@ -1284,7 +1285,7 @@ function RelatedActions({
<span>Unmute @{username}</span>
</MenuItem>
) : (
<SubMenu
<SubMenu2
menuClassName="menu-blur"
openTrigger="clickOnly"
direction="bottom"
Expand Down Expand Up @@ -1338,7 +1339,7 @@ function RelatedActions({
</MenuItem>
))}
</div>
</SubMenu>
</SubMenu2>
)}
{followedBy && (
<MenuConfirm
Expand Down
21 changes: 3 additions & 18 deletions src/components/menu-confirm.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { MenuItem, SubMenu } from '@szhsin/react-menu';
import { MenuItem } from '@szhsin/react-menu';
import { cloneElement } from 'preact';
import { useRef } from 'preact/hooks';

import Menu2 from './menu2';
import SubMenu2 from './submenu2';

function MenuConfirm({
subMenu = false,
Expand All @@ -23,11 +23,9 @@ function MenuConfirm({
}
return children;
}
const Parent = subMenu ? SubMenu : Menu2;
const menuRef = useRef();
const Parent = subMenu ? SubMenu2 : Menu2;
return (
<Parent
instanceRef={menuRef}
openTrigger="clickOnly"
direction="bottom"
overflow="auto"
Expand All @@ -37,19 +35,6 @@ function MenuConfirm({
{...restProps}
menuButton={subMenu ? undefined : children}
label={subMenu ? children : undefined}
// Test fix for bug; submenus not opening on Android
itemProps={{
onPointerMove: (e) => {
if (e.pointerType === 'touch') {
menuRef.current?.openMenu?.();
}
},
onPointerLeave: (e) => {
if (e.pointerType === 'touch') {
menuRef.current?.openMenu?.();
}
},
}}
>
<MenuItem className={menuItemClassName} onClick={onClick}>
{confirmLabel}
Expand Down
31 changes: 2 additions & 29 deletions src/components/nav-menu.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import './nav-menu.css';

import {
ControlledMenu,
MenuDivider,
MenuItem,
SubMenu,
} from '@szhsin/react-menu';
import { ControlledMenu, MenuDivider, MenuItem } from '@szhsin/react-menu';
import { memo } from 'preact/compat';
import { useEffect, useMemo, useRef, useState } from 'preact/hooks';
import { useLongPress } from 'use-long-press';
Expand All @@ -20,6 +15,7 @@ import store from '../utils/store';
import Avatar from './avatar';
import Icon from './icon';
import MenuLink from './menu-link';
import SubMenu2 from './submenu2';

function NavMenu(props) {
const snapStates = useSnapshot(states);
Expand Down Expand Up @@ -371,27 +367,4 @@ function NavMenu(props) {
);
}

function SubMenu2(props) {
const menuRef = useRef();
return (
<SubMenu
{...props}
instanceRef={menuRef}
// Test fix for bug; submenus not opening on Android
itemProps={{
onPointerMove: (e) => {
if (e.pointerType === 'touch') {
menuRef.current?.openMenu?.();
}
},
onPointerLeave: (e) => {
if (e.pointerType === 'touch') {
menuRef.current?.openMenu?.();
}
},
}}
/>
);
}

export default memo(NavMenu);
7 changes: 4 additions & 3 deletions src/components/shortcuts.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import './shortcuts.css';

import { MenuDivider, SubMenu } from '@szhsin/react-menu';
import { MenuDivider } from '@szhsin/react-menu';
import { memo } from 'preact/compat';
import { useRef, useState } from 'preact/hooks';
import { useHotkeys } from 'react-hotkeys-hook';
Expand All @@ -17,6 +17,7 @@ import Icon from './icon';
import Link from './link';
import Menu2 from './menu2';
import MenuLink from './menu-link';
import SubMenu2 from './submenu2';

function Shortcuts() {
const { instance } = api();
Expand Down Expand Up @@ -182,7 +183,7 @@ function Shortcuts() {
{formattedShortcuts.map(({ id, path, title, subtitle, icon }, i) => {
if (id === 'lists') {
return (
<SubMenu
<SubMenu2
menuClassName="glass-menu"
overflow="auto"
gap={-8}
Expand All @@ -205,7 +206,7 @@ function Shortcuts() {
<span>{list.title}</span>
</MenuLink>
))}
</SubMenu>
</SubMenu2>
);
}

Expand Down
25 changes: 25 additions & 0 deletions src/components/submenu2.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { SubMenu } from '@szhsin/react-menu';
import { useRef } from 'preact/hooks';

export default function SubMenu2(props) {
const menuRef = useRef();
return (
<SubMenu
{...props}
instanceRef={menuRef}
// Test fix for bug; submenus not opening on Android
itemProps={{
onPointerMove: (e) => {
if (e.pointerType === 'touch') {
menuRef.current?.openMenu?.();
}
},
onPointerLeave: (e) => {
if (e.pointerType === 'touch') {
menuRef.current?.openMenu?.();
}
},
}}
/>
);
}

0 comments on commit 015ed5e

Please sign in to comment.