Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
STetsing authored and Aniket-Engg committed Jan 13, 2025
1 parent 66405d2 commit 73cc89a
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions libs/remix-ui/remix-ai/src/lib/components/Default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
}

};
Expand Down

0 comments on commit 73cc89a

Please sign in to comment.