From d9bb64328484374f28d4ffdb7439c8e2cb819d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Fri, 23 Aug 2024 19:02:08 +0200 Subject: [PATCH] Improve dropdown+modal behavior again? MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- .../dropdown-menu/dropdown-menu-item.tsx | 14 ++++++++++---- src/components/modal-root.tsx | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/components/dropdown-menu/dropdown-menu-item.tsx b/src/components/dropdown-menu/dropdown-menu-item.tsx index e934d079d..7cbc5ddb2 100644 --- a/src/components/dropdown-menu/dropdown-menu-item.tsx +++ b/src/components/dropdown-menu/dropdown-menu-item.tsx @@ -2,6 +2,8 @@ import clsx from 'clsx'; import React, { useEffect, useRef } from 'react'; import { useHistory } from 'react-router-dom'; +import { userTouching } from 'soapbox/is-mobile'; + import { Counter, Icon } from '../ui'; interface MenuItem { @@ -21,7 +23,7 @@ interface MenuItem { interface IDropdownMenuItem { index: number; item: MenuItem | null; - onClick?(): void; + onClick?(goBack?: boolean): void; autoFocus?: boolean; } @@ -35,14 +37,18 @@ const DropdownMenuItem = ({ index, item, onClick, autoFocus }: IDropdownMenuItem if (!item) return; - if (onClick) onClick(); + if (onClick) onClick(!(item.to && userTouching.matches)); if (item.to) { event.preventDefault(); - history.push(item.to); + if (userTouching.matches) { + history.replace(item.to); + } else history.push(item.to); } else if (typeof item.action === 'function') { + const action = item.action; event.preventDefault(); - item.action(event); + // TODO + setTimeout(() => action(event), userTouching.matches ? 10 : 0); } }; diff --git a/src/components/modal-root.tsx b/src/components/modal-root.tsx index 1a35c963d..afb898e35 100644 --- a/src/components/modal-root.tsx +++ b/src/components/modal-root.tsx @@ -227,7 +227,7 @@ const ModalRoot: React.FC = ({ children, onCancel, onClose, type }) unlistenHistory.current(); } else if (!isDropdownOpen && wasDropdownOpen) { // TODO find a better solution - setTimeout(() => handleModalOpen(), 100); + setTimeout(() => handleModalOpen(), 50); } }, [isDropdownOpen]);