mirror of
https://github.com/whyour/qinglong.git
synced 2025-11-22 16:38:33 +08:00
Fix environment variable copy reliability by validating clipboard operation (#2833)
* Initial plan * Fix env variable copy issue by using onCopy callback Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
This commit is contained in:
parent
d01ec3b310
commit
e84ddb6cfc
|
|
@ -1,6 +1,6 @@
|
|||
import intl from 'react-intl-universal';
|
||||
import React, { useRef, useState, useEffect } from 'react';
|
||||
import { Tooltip, Typography } from 'antd';
|
||||
import { Tooltip, Typography, message } from 'antd';
|
||||
import { CopyOutlined, CheckOutlined } from '@ant-design/icons';
|
||||
import { CopyToClipboard } from 'react-copy-to-clipboard';
|
||||
|
||||
|
|
@ -10,16 +10,21 @@ const Copy = ({ text }: { text: string }) => {
|
|||
const [copied, setCopied] = useState(false);
|
||||
const copyIdRef = useRef<number>();
|
||||
|
||||
const copyText = (e?: React.MouseEvent) => {
|
||||
e?.preventDefault();
|
||||
e?.stopPropagation();
|
||||
|
||||
const handleCopy = (text: string, result: boolean) => {
|
||||
if (result) {
|
||||
setCopied(true);
|
||||
message.success(intl.get('复制成功'));
|
||||
|
||||
cleanCopyId();
|
||||
copyIdRef.current = window.setTimeout(() => {
|
||||
setCopied(false);
|
||||
}, 3000);
|
||||
}
|
||||
};
|
||||
|
||||
const handleClick = (e?: React.MouseEvent) => {
|
||||
e?.preventDefault();
|
||||
e?.stopPropagation();
|
||||
};
|
||||
|
||||
const cleanCopyId = () => {
|
||||
|
|
@ -27,8 +32,8 @@ const Copy = ({ text }: { text: string }) => {
|
|||
};
|
||||
|
||||
return (
|
||||
<Link onClick={copyText} style={{ marginLeft: 1 }}>
|
||||
<CopyToClipboard text={text}>
|
||||
<Link onClick={handleClick} style={{ marginLeft: 1 }}>
|
||||
<CopyToClipboard text={text} onCopy={handleCopy}>
|
||||
<Tooltip
|
||||
key="copy"
|
||||
title={copied ? intl.get('复制成功') : intl.get('复制')}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user