diff --git a/src/lib/mui/MUI.util.ts b/src/lib/mui/MUI.util.ts new file mode 100644 index 00000000..6aab38a4 --- /dev/null +++ b/src/lib/mui/MUI.util.ts @@ -0,0 +1,26 @@ +/* + * Copyright (C) Contributors to the Suwayomi project + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +import React, { BaseSyntheticEvent } from 'react'; +import { chainEventHandlers } from 'material-ui-popup-state/chainEventHandlers'; + +export class MUIUtil { + static preventRipple(): (e: BaseSyntheticEvent) => void { + return (e) => e.stopPropagation(); + } + + static preventRippleProp[]>( + ...handlers: T + ): T & Pick, 'onMouseDown' | 'onTouchStart'> { + // @ts-ignore - "chainEventHandlers" is wrongly typed + return chainEventHandlers(...handlers, { + onMouseDown: MUIUtil.preventRipple(), + onTouchStart: MUIUtil.preventRipple(), + }) as T & Pick, 'onMouseDown' | 'onTouchStart'>; + } +} diff --git a/src/modules/chapter/components/buttons/ChapterDownloadButton.tsx b/src/modules/chapter/components/buttons/ChapterDownloadButton.tsx index c3bdbe48..207ac016 100644 --- a/src/modules/chapter/components/buttons/ChapterDownloadButton.tsx +++ b/src/modules/chapter/components/buttons/ChapterDownloadButton.tsx @@ -14,6 +14,7 @@ import { ChapterIdInfo, Chapters } from '@/modules/chapter/services/Chapters.ts' import { requestManager } from '@/lib/requests/RequestManager.ts'; import { makeToast } from '@/modules/core/utils/Toast.ts'; import { getErrorMessage } from '@/lib/HelperFunctions.ts'; +import { MUIUtil } from '@/lib/mui/MUI.util.ts'; export const ChapterDownloadButton = ({ chapterId, @@ -40,6 +41,7 @@ export const ChapterDownloadButton = ({ return ( { e.stopPropagation(); e.preventDefault(); diff --git a/src/modules/chapter/components/cards/ChapterCard.tsx b/src/modules/chapter/components/cards/ChapterCard.tsx index b29088af..958908bb 100644 --- a/src/modules/chapter/components/cards/ChapterCard.tsx +++ b/src/modules/chapter/components/cards/ChapterCard.tsx @@ -38,6 +38,7 @@ import { } from '@/modules/chapter/services/Chapters.ts'; import { applyStyles } from '@/modules/core/utils/ApplyStyles.ts'; import { ChapterCardMetadata } from '@/modules/chapter/components/cards/ChapterCardMetadata.tsx'; +import { MUIUtil } from '@/lib/mui/MUI.util.ts'; type TChapter = ChapterIdInfo & ChapterMangaInfo & @@ -87,11 +88,11 @@ export const ChapterCard = memo((props: IProps) => { const handleClickOpenMenu = ( event: React.MouseEvent | React.TouchEvent, - openMenu: (e: React.SyntheticEvent) => void, + openMenu?: (e: React.SyntheticEvent) => void, ) => { event.stopPropagation(); event.preventDefault(); - openMenu(event); + openMenu?.(event); }; const longPressBind = useLongPress((event, { context: openMenu }) => { @@ -187,8 +188,9 @@ export const ChapterCard = memo((props: IProps) => { handleClickOpenMenu(e, popupState.open)} + {...MUIUtil.preventRippleProp(bindTrigger(popupState), { + onClick: (e: MouseEvent) => handleClickOpenMenu(e), + })} aria-label="more" sx={{ color: 'inherit', diff --git a/src/modules/downloads/screens/DownloadQueue.tsx b/src/modules/downloads/screens/DownloadQueue.tsx index 6fa24e29..a0617e62 100644 --- a/src/modules/downloads/screens/DownloadQueue.tsx +++ b/src/modules/downloads/screens/DownloadQueue.tsx @@ -37,6 +37,7 @@ import { DownloaderState, DownloadState } from '@/lib/graphql/generated/graphql. import { AppRoutes } from '@/modules/core/AppRoute.constants.ts'; import { getErrorMessage } from '@/lib/HelperFunctions.ts'; import { useNavBarContext } from '@/modules/navigation-bar/contexts/NavbarContext.tsx'; +import { MUIUtil } from '@/lib/mui/MUI.util.ts'; const HeightPreservingItem = ({ children, ...props }: BoxProps) => ( // the height is necessary to prevent the item container from collapsing, which confuses Virtuoso measurements @@ -75,7 +76,7 @@ const DownloadChapterItem = memo( p: 1.5, }} > - + @@ -95,6 +96,7 @@ const DownloadChapterItem = memo( {item.state === DownloadState.Error && ( { e.preventDefault(); e.stopPropagation(); @@ -107,6 +109,7 @@ const DownloadChapterItem = memo( )} { e.preventDefault(); e.stopPropagation(); diff --git a/src/modules/manga/components/ContinueReadingButton.tsx b/src/modules/manga/components/ContinueReadingButton.tsx index a134ca5d..8a7943a9 100644 --- a/src/modules/manga/components/ContinueReadingButton.tsx +++ b/src/modules/manga/components/ContinueReadingButton.tsx @@ -12,6 +12,7 @@ import PlayArrowIcon from '@mui/icons-material/PlayArrow'; import { Link } from 'react-router-dom'; import { CustomTooltip } from '@/modules/core/components/CustomTooltip.tsx'; import { ChapterReadInfo, Chapters, ChapterSourceOrderInfo } from '@/modules/chapter/services/Chapters.ts'; +import { MUIUtil } from '@/lib/mui/MUI.util.ts'; export const ContinueReadingButton = ({ showContinueReadingButton, @@ -34,6 +35,7 @@ export const ContinueReadingButton = ({ return ( diff --git a/src/modules/manga/components/MangaBadges.tsx b/src/modules/manga/components/MangaBadges.tsx index 8b06b015..57174906 100644 --- a/src/modules/manga/components/MangaBadges.tsx +++ b/src/modules/manga/components/MangaBadges.tsx @@ -13,6 +13,7 @@ import Typography from '@mui/material/Typography'; import { MangaCardMode } from '@/modules/manga/Manga.types.ts'; import { MediaQuery } from '@/modules/core/utils/MediaQuery.tsx'; import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.ts'; +import { MUIUtil } from '@/lib/mui/MUI.util.ts'; const BadgeContainer = styled('div')(({ theme }) => ({ display: 'flex', @@ -57,7 +58,7 @@ export const MangaBadges = ({ component="div" variant="contained" size="small" - onMouseDown={(e) => e.stopPropagation()} + {...MUIUtil.preventRippleProp()} onClick={(e) => { e.preventDefault(); e.stopPropagation(); diff --git a/src/modules/manga/components/MangaOptionButton.tsx b/src/modules/manga/components/MangaOptionButton.tsx index fc89f29e..eac8dfb4 100644 --- a/src/modules/manga/components/MangaOptionButton.tsx +++ b/src/modules/manga/components/MangaOptionButton.tsx @@ -7,7 +7,7 @@ */ import { useTranslation } from 'react-i18next'; -import { BaseSyntheticEvent, MouseEvent, TouchEvent, ChangeEvent, useMemo, forwardRef, ForwardedRef } from 'react'; +import { BaseSyntheticEvent, ChangeEvent, useMemo, forwardRef, ForwardedRef } from 'react'; import Button from '@mui/material/Button'; import Checkbox from '@mui/material/Checkbox'; import IconButton from '@mui/material/IconButton'; @@ -17,6 +17,7 @@ import { bindTrigger } from 'material-ui-popup-state'; import { CustomTooltip } from '@/modules/core/components/CustomTooltip.tsx'; import { SelectableCollectionReturnType } from '@/modules/collection/hooks/useSelectableCollection.ts'; import { MangaType } from '@/lib/graphql/generated/graphql.ts'; +import { MUIUtil } from '@/lib/mui/MUI.util.ts'; export const MangaOptionButton = forwardRef( ( @@ -49,12 +50,6 @@ export const MangaOptionButton = forwardRef( handleSelection?.(id, isSelected); }; - const handleClick = (e: MouseEvent | TouchEvent) => { - preventDefaultAction(e); - popupState.open(e); - bindTriggerProps.onClick(e as any); - }; - if (!handleSelection) { return null; } @@ -67,7 +62,7 @@ export const MangaOptionButton = forwardRef( return ( - + ); } @@ -77,10 +72,8 @@ export const MangaOptionButton = forwardRef( @@ -92,8 +85,7 @@ export const MangaOptionButton = forwardRef( diff --git a/src/modules/source/components/SourceCard.tsx b/src/modules/source/components/SourceCard.tsx index e297770e..81ecdaab 100644 --- a/src/modules/source/components/SourceCard.tsx +++ b/src/modules/source/components/SourceCard.tsx @@ -24,6 +24,7 @@ import { GetSourcesListQuery } from '@/lib/graphql/generated/graphql.ts'; import { MediaQuery } from '@/modules/core/utils/MediaQuery.tsx'; import { translateExtensionLanguage } from '@/modules/extension/Extensions.utils.ts'; import { AppRoutes } from '@/modules/core/AppRoute.constants.ts'; +import { MUIUtil } from '@/lib/mui/MUI.util.ts'; interface IProps { source: GetSourcesListQuery['sources']['nodes'][number]; @@ -134,6 +135,7 @@ export const SourceCard: React.FC = (props: IProps) => { {supportsLatest && ( @@ -91,13 +91,13 @@ const TrackerMangaCardSummary = ({ summary }: { summary: string }) => { const TrackerMangaCardLink = ({ children, url }: { children: React.ReactNode; url: string }) => ( e.stopPropagation()} - onMouseDown={(e) => e.stopPropagation()} > {children}