From cb474c1fe45e00a48093a562836141bd33a1e390 Mon Sep 17 00:00:00 2001 From: STetsing <41009393+STetsing@users.noreply.github.com> Date: Mon, 6 Jan 2025 17:35:46 +0100 Subject: [PATCH] minor --- .../remix-ai/src/lib/components/Default.tsx | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/libs/remix-ui/remix-ai/src/lib/components/Default.tsx b/libs/remix-ui/remix-ai/src/lib/components/Default.tsx index ae1a376d93..e82504e850 100644 --- a/libs/remix-ui/remix-ai/src/lib/components/Default.tsx +++ b/libs/remix-ui/remix-ai/src/lib/components/Default.tsx @@ -11,6 +11,19 @@ import '@nlux/themes/unstyled.css'; export let ChatApi = null export const Default = (props) => { + + const HandleCopyToClipboard = () => { + const codeBlocks = document.getElementsByClassName('code-block') + Array.from(codeBlocks).forEach((block) => { + const copyButtons = block.getElementsByClassName('nlux-comp-copyButton') + Array.from(copyButtons).forEach((cp_btn) => { + cp_btn.removeEventListener('click', () => {}) + cp_btn.addEventListener('click', async () => { + await navigator.clipboard.writeText(block.textContent) + }) + }) + }) + } const send: StreamSend = async ( prompt: string, observer: StreamingAdapterObserver, @@ -31,24 +44,13 @@ export const Default = (props) => { observer.next(' ') // Add a space to flush the last message ChatHistory.pushHistory(prompt, result) observer.complete() - const codeBlocks = document.getElementsByClassName('code-block') - - Array.from(codeBlocks).forEach((block) => { - const copyButtons = block.getElementsByClassName('nlux-comp-copyButton'); - Array.from(copyButtons).forEach((cp_btn) => { - // remove click event listener if existing - cp_btn.removeEventListener('click', () => {}); - - cp_btn.addEventListener('click', async () => { - await navigator.clipboard.writeText(block.textContent); - }); - }) - }) + HandleCopyToClipboard() } ) else { observer.next(response) observer.complete() + HandleCopyToClipboard() } };