Skip to content

Commit dc75cd5

Browse files
committed
ui: fix: CodeWithCopyButton: instead of cleaning up what is copied by the button, I am cleaning up what is displayed
1 parent 2225eea commit dc75cd5

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

components/setup/CodeWithCopyButton.tsx

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import { CopyToClipboard } from 'react-copy-to-clipboard';
33
import { MdContentCopy } from "react-icons/md";
44
import Markdown from 'react-markdown';
@@ -12,10 +12,10 @@ const CodeWithCopyButton: React.FC<CodeWithCopyButtonProps> = ({ text }) => {
1212
const [isCopied, setIsCopied] = useState<boolean>(false);
1313
const [isButtonDisabled, setIsButtonDisabled] = useState<boolean>(false);
1414

15-
// Function to clean up the text before copying
15+
// Function to clean up the text before displaying
1616
const cleanUpText = (text: string) => {
17-
// Replace multiple newlines with a single newline
18-
return text.replace(/\n{2,}/g, '\n');
17+
// Make sure that backslashes are properly escaped for Markdown
18+
return text.replace(/\\/g, '\\\\');
1919
};
2020

2121
const handleCopyClick = () => {
@@ -27,12 +27,25 @@ const CodeWithCopyButton: React.FC<CodeWithCopyButtonProps> = ({ text }) => {
2727
setIsButtonDisabled(false);
2828
};
2929

30+
useEffect(() => {
31+
let timer: NodeJS.Timeout;
32+
if (isCopied) {
33+
timer = setTimeout(() => {
34+
setIsCopied(false);
35+
setIsButtonDisabled(false);
36+
}, 2000); // Reset after 2 seconds
37+
}
38+
return () => clearTimeout(timer);
39+
}, [isCopied]);
40+
3041
return (
3142
<div className='relative border p-4 my-4'>
32-
<Markdown remarkPlugins={[remarkGfm]}>
33-
{text}
34-
</Markdown>
35-
<CopyToClipboard text={cleanUpText(text)} onCopy={handleCopy}>
43+
<pre style={{ whiteSpace: 'pre-wrap' }}>
44+
<Markdown remarkPlugins={[remarkGfm]}>
45+
{cleanUpText(text)}
46+
</Markdown>
47+
</pre>
48+
<CopyToClipboard text={text} onCopy={handleCopy}>
3649
<button
3750
className="absolute top-0 right-0 p-1 cursor-pointer bg-transparent border-none"
3851
onClick={handleCopyClick}

components/setup/DockerInstructions.tsx

-5
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@ interface DockerInstructionsProps {
1515
const DockerInstructions: React.FC<DockerInstructionsProps> = ({ selectedInstallationType, selectedProvider, installId }) => {
1616
const selfHostingCode = `
1717
docker run \\
18-
1918
-v ~/.config/vibinex:/app/config \\
20-
2119
-e INSTALL_ID=${installId} \\
22-
2320
${selectedProvider === 'github' && selectedInstallationType === 'pat' ? `-e PROVIDER=github \\
24-
2521
-e GITHUB_PAT=<Your gh cli token> \\
26-
2722
` : ''}asia.gcr.io/vibi-prod/dpu/dpu
2823
`;
2924

0 commit comments

Comments
 (0)