fix: reset copy state after copying in MarkdownCodeBlock component

There were 2 issues.

The copy state was not being reset after copying, which caused the
"Copied!" message to persist indefinitely.

The return value from the copy function was not being used to determine
if the copy was successful. Even on false(i.e. copy unsuccessful), the user would see a success message.
This commit is contained in:
Haileyesus
2026-02-23 10:16:03 +03:00
parent 30c5da8984
commit dd11345e09

View File

@@ -43,7 +43,13 @@ export default function MarkdownCodeBlock({
<button
type="button"
onClick={() => copyTextToClipboard(rawContent).then(() => setCopied(true))}
onClick={() =>
copyTextToClipboard(rawContent).then((success) => {
if (success) {
setCopied(true);
setTimeout(() => setCopied(false), 2000);
}
})}
className="absolute top-2 right-2 z-10 opacity-0 group-hover:opacity-100 transition-opacity text-xs px-2 py-1 rounded-md bg-gray-700/80 hover:bg-gray-700 text-white border border-gray-600"
>
{copied ? 'Copied!' : 'Copy'}