Set only a single click on the text, to avoid multiple notifications if the user wants to select it

This commit is contained in:
pierrbt
2023-06-23 16:21:53 +02:00
parent e40a0c844c
commit e5718700bc

View File

@@ -3,12 +3,14 @@ import toast from "../../utils/toast.util";
import {ActionIcon, TextInput} from "@mantine/core"; import {ActionIcon, TextInput} from "@mantine/core";
import {TbCheck, TbCopy} from "react-icons/tb"; import {TbCheck, TbCopy} from "react-icons/tb";
import {useClipboard} from "@mantine/hooks"; import {useClipboard} from "@mantine/hooks";
import {text} from "stream/consumers";
function CopyTextField(props: { link: string }) function CopyTextField(props: { link: string })
{ {
const clipboard = useClipboard({ timeout: 500 }); const clipboard = useClipboard({ timeout: 500 });
const [checkState, setCheckState] = useState(false); const [checkState, setCheckState] = useState(false);
const [textClicked, setTextClicked] = useState(false);
const timerRef = useRef<number | ReturnType<typeof setTimeout> | undefined>( const timerRef = useRef<number | ReturnType<typeof setTimeout> | undefined>(
undefined undefined
); );
@@ -30,7 +32,12 @@ function CopyTextField(props: { link: string })
label="Link" label="Link"
variant="filled" variant="filled"
value={props.link} value={props.link}
onClick={copyLink} onClick={() => {
if (!textClicked) {
copyLink();
setTextClicked(true);
}
}}
rightSection={ rightSection={
window.isSecureContext && ( window.isSecureContext && (
<ActionIcon onClick={copyLink}> <ActionIcon onClick={copyLink}>