From 3bc9b5c9706ea32a348dcfd808e887187a863232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Tue, 20 Aug 2024 09:56:31 +0200 Subject: [PATCH] Fix sidebar menu bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- src/components/sidebar-menu.tsx | 420 ++++++++++++++++---------------- 1 file changed, 206 insertions(+), 214 deletions(-) diff --git a/src/components/sidebar-menu.tsx b/src/components/sidebar-menu.tsx index 43d6e8e8c..fecc64477 100644 --- a/src/components/sidebar-menu.tsx +++ b/src/components/sidebar-menu.tsx @@ -1,6 +1,6 @@ /* eslint-disable jsx-a11y/interactive-supports-focus */ import clsx from 'clsx'; -import React, { useCallback, useEffect, useState } from 'react'; +import React, { useCallback, useEffect, useRef, useState } from 'react'; import { defineMessages, useIntl, FormattedMessage } from 'react-intl'; import { Link, NavLink } from 'react-router-dom'; @@ -86,8 +86,8 @@ const SidebarMenu: React.FC = (): JSX.Element | null => { const draftCount = useAppSelector((state) => state.draft_statuses.size); // const dashboardCount = useAppSelector((state) => state.admin.openReports.count() + state.admin.awaitingApproval.count()); const [sidebarVisible, setSidebarVisible] = useState(sidebarOpen); - const [touchStart, setTouchStart] = useState(0); - const [touchEnd, setTouchEnd] = useState(0); + const touchStart = useRef(0); + const touchEnd = useRef(null); const instance = useInstance(); const restrictUnauth = instance.pleroma.metadata.restrict_unauthenticated; @@ -132,21 +132,18 @@ const SidebarMenu: React.FC = (): JSX.Element | null => { ); - const handleOutsideClick: React.MouseEventHandler = (e) => { - if ((e.target as HTMLElement).isSameNode(e.currentTarget)) handleClose(); - }; - const handleKeyDown: React.KeyboardEventHandler = (e) => { if (e.key === 'Escape') handleClose(); }; - const handleTouchStart: React.TouchEventHandler = (e) => setTouchStart(e.targetTouches[0].clientX); - const handleTouchMove: React.TouchEventHandler = (e) => setTouchEnd(e.targetTouches[0].clientX); + const handleTouchStart: React.TouchEventHandler = (e) => touchStart.current = e.targetTouches[0].clientX; + const handleTouchMove: React.TouchEventHandler = (e) => touchEnd.current = e.targetTouches[0].clientX; - const handleTouchEnd = () => { - if (touchStart - touchEnd > 100) { + const handleTouchEnd: React.TouchEventHandler = (e) => { + if (touchEnd.current !== null && touchStart.current - touchEnd.current > 100) { handleClose(); } + touchEnd.current = null; }; useEffect(() => { @@ -174,7 +171,7 @@ const SidebarMenu: React.FC = (): JSX.Element | null => { onTouchEnd={handleTouchEnd} >
{ />
-
-
-
- {account ? ( - - - - +
+
+ {account ? ( + + + + - + + + + + - - - + {(account.locked || followRequestsCount > 0) && ( + )} - {(account.locked || followRequestsCount > 0) && ( - - )} - - {features.bookmarks && ( - - )} - - {features.groups && ( - - )} - - {features.lists && ( - - )} - - {features.events && ( - - )} - - {features.profileDirectory && ( - - )} - - {draftCount > 0 && ( - - )} - - {features.publicTimeline && <> - - - : } - onClick={onClose} - /> - - {features.federating && ( - } - onClick={onClose} - /> - )} - - {features.bubbleTimeline && ( - } - onClick={onClose} - /> - )} - } - - - + {features.bookmarks && ( + )} - {features.followedHashtagsList && ( - - )} - - {settings.get('isDeveloper') && ( - - )} - - {(account.is_admin || account.is_moderator) && ( - - )} - - - + {features.groups && ( + )} + {features.lists && ( + + )} + + {features.events && ( + + )} + + {features.profileDirectory && ( + + )} + + {draftCount > 0 && ( + + )} + + {features.publicTimeline && <> - - - - {switcher && ( -
- {otherAccounts.map(account => renderAccount(account))} - - - - {intl.formatMessage(messages.addAccount)} - -
- )} -
-
-
- ) : ( - - {features.publicTimeline && !restrictUnauth.timelines.local && <> { onClick={onClose} /> - {features.federating && !restrictUnauth.timelines.federated && ( + {features.federating && ( { /> )} - {features.bubbleTimeline && !restrictUnauth.timelines.bubble && ( + {features.bubbleTimeline && ( { onClick={onClose} /> )} - - } + + + {features.followedHashtagsList && ( + + )} + + {settings.get('isDeveloper') && ( + + )} + + {(account.is_admin || account.is_moderator) && ( + + )} + + + + + + + + + + {switcher && ( +
+ {otherAccounts.map(account => renderAccount(account))} + + + + {intl.formatMessage(messages.addAccount)} + +
+ )} +
+
+
+ ) : ( + + {features.publicTimeline && !restrictUnauth.timelines.local && <> + : } onClick={onClose} /> - - )} -
+ + {features.federating && !restrictUnauth.timelines.federated && ( + } + onClick={onClose} + /> + )} + + {features.bubbleTimeline && !restrictUnauth.timelines.bubble && ( + } + onClick={onClose} + /> + )} + + + } + + + + + + )}