mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-12-01 09:15:33 +08:00
feat: add copy button functionality to OAuthMethodCard
- Implemented a new button to copy the user code in the OAuthMethodCard, enhancing user experience. - Added styles for the copy button to match the UI design. - Updated localization files to include new strings for the copy action in both English and Chinese.
This commit is contained in:
1 parent
3a2d47954e
commit
5e405b31b2
6 files changed
+136
-81
No files matched your search
@@ -46,6 +46,20 @@
|
||||
letter-spacing: 0.08em;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button.copy {
|
||||
padding: 6px 2px;
|
||||
color: var(--vscode-textLink-foreground);
|
||||
background: none;
|
||||
border: none;
|
||||
font-family: inherit;
|
||||
letter-spacing: normal;
|
||||
font-size: type.$font-size-xs;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.fileButton {
|
||||
|
||||
@@ -56,8 +56,15 @@ function OAuthMethodCard({ pluginId, resourceType, method, onConfigured }: {
|
||||
const [status, setStatus] = useState<"idle" | "starting" | "polling" | "success" | "error">("idle");
|
||||
const [begun, setBegun] = useState<PluginOAuthBegin | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [copied, setCopied] = useState(false);
|
||||
const stopped = useRef(false);
|
||||
|
||||
const copyCode = async (code: string) => {
|
||||
await api.copyCursorText(code).catch(() => undefined);
|
||||
setCopied(true);
|
||||
window.setTimeout(() => setCopied(false), 2000);
|
||||
};
|
||||
|
||||
useEffect(() => () => { stopped.current = true; }, []);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -115,7 +122,10 @@ function OAuthMethodCard({ pluginId, resourceType, method, onConfigured }: {
|
||||
{method.description && <span>{pluginText(method.description, locale)}</span>}
|
||||
{begun && status === "polling" && <div className={styles.deviceCode}>
|
||||
<small>{t("设备验证码")}</small>
|
||||
<button type="button" onClick={() => void api.copyCursorText(begun.userCode)}>{begun.userCode}</button>
|
||||
<button type="button" onClick={() => void copyCode(begun.userCode)}>{begun.userCode}</button>
|
||||
<button type="button" className={styles.copy} onClick={() => void copyCode(begun.userCode)}>
|
||||
{copied ? t("已复制") : t("复制")}
|
||||
</button>
|
||||
</div>}
|
||||
<div className={styles.actions}>
|
||||
<Button variant="primary" disabled={status === "starting" || status === "polling"} onClick={() => void start()}>
|
||||
|
||||
Reference in new issue
Block a user