From e71f5f294e8d66eee60ab221a91551f324b8476b Mon Sep 17 00:00:00 2001 From: Vilas Chauvhan Date: Tue, 21 Oct 2025 18:40:45 +0530 Subject: [PATCH] fix: updated copy markdown component to toast notification --- src/components/CopyMarkdownButton.tsx | 62 ++++++++++++++------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/src/components/CopyMarkdownButton.tsx b/src/components/CopyMarkdownButton.tsx index 6d8fba82d..704134d52 100644 --- a/src/components/CopyMarkdownButton.tsx +++ b/src/components/CopyMarkdownButton.tsx @@ -54,48 +54,52 @@ export function CopyMarkdownButton({ const cached = cache.get(url) if (cached) { - navigator.clipboard.writeText(cached) - notify( -
-
Copied markdown
-
- Source content copied from cache + navigator.clipboard.writeText(cached).then(() => { + notify( +
+
Copied markdown
+
+ Source content copied from cache +
-
- ) + ) + }) } else { fetch(url) - .then((response) => response.text()) + .then((response) => { + if (!response.ok) { + throw new Error('Fetch failed') + } + return response.text() + }) .then((content) => { cache.set(url, content) - return navigator.clipboard.writeText(content) - }) - .then(() => { - notify( -
-
Copied markdown
-
- Source content copied from GitHub + return navigator.clipboard.writeText(content).then(() => { + notify( +
+
Copied markdown
+
+ Source content copied from GitHub +
-
- ) + ) + }) }) .catch(() => { // fallback: try to copy current page content if available const pageContent = document.querySelector('.styled-markdown-content')?.textContent || '' - return navigator.clipboard.writeText(pageContent) - }) - .then(() => { - notify( -
-
Copied markdown
-
- Fallback: copied rendered page content + navigator.clipboard.writeText(pageContent).then(() => { + notify( +
+
Copied markdown
+
+ Fallback: copied rendered page content +
-
- ) + ) + }) }) } })