From 297ec2580b33e20ef5cf7cbdcb28ed5164cf10b9 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Thu, 23 May 2024 02:28:37 +0200 Subject: [PATCH] Copy manga title on long press --- public/locales/en.json | 1 + src/components/manga/MangaDetails.tsx | 18 +++++++++++++++++- src/lib/ui/MediaQuery.tsx | 15 +++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/lib/ui/MediaQuery.tsx diff --git a/public/locales/en.json b/public/locales/en.json index ce015c94..72f702e1 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -385,6 +385,7 @@ "browse": "Browse", "client": "Client", "close": "Close", + "copied": "Copied", "disabled": "Disabled", "discord": "Discord", "display": "Display", diff --git a/src/components/manga/MangaDetails.tsx b/src/components/manga/MangaDetails.tsx index 558a2407..7036b938 100644 --- a/src/components/manga/MangaDetails.tsx +++ b/src/components/manga/MangaDetails.tsx @@ -15,6 +15,7 @@ import { useTranslation } from 'react-i18next'; import { t as translate } from 'i18next'; import Link from '@mui/material/Link'; import Typography from '@mui/material/Typography'; +import { useLongPress } from 'use-long-press'; import { ISource, TManga } from '@/typings'; import { makeToast } from '@/components/util/Toast'; import { Mangas } from '@/lib/data/Mangas.ts'; @@ -23,6 +24,7 @@ import { CustomIconButton } from '@/components/atoms/CustomIconButton'; import { TrackMangaButton } from '@/components/manga/TrackMangaButton.tsx'; import { useManageMangaLibraryState } from '@/components/manga/useManageMangaLibraryState.tsx'; import { Metadata as BaseMetadata } from '@/components/atoms/Metadata.tsx'; +import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts'; const DetailsWrapper = styled('div')(({ theme }) => ({ width: '100%', @@ -180,6 +182,15 @@ export const MangaDetails: React.FC = ({ manga }) => { const { CategorySelectComponent, updateLibraryState } = useManageMangaLibraryState(manga); + const copyTitleLongPressBind = useLongPress(async () => { + try { + await navigator.clipboard.writeText(manga.title); + makeToast(t('global.label.copied'), 'info'); + } catch (e) { + defaultPromiseErrorHandler('MangaDetails::copyTitleLongPress')(e); + } + }); + return ( <> @@ -189,7 +200,12 @@ export const MangaDetails: React.FC = ({ manga }) => { - + {manga.title} diff --git a/src/lib/ui/MediaQuery.tsx b/src/lib/ui/MediaQuery.tsx new file mode 100644 index 00000000..1c86dcbd --- /dev/null +++ b/src/lib/ui/MediaQuery.tsx @@ -0,0 +1,15 @@ +/* + * 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 useMediaQuery from '@mui/material/useMediaQuery'; + +export class MediaQuery { + static useIsTouchDevice(): boolean { + return useMediaQuery('not (pointer: fine)'); + } +}