mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-07-27 06:28:50 +00:00
have messages working but streaming still not fixed yet
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
This commit is contained in:
parent
fc3286be7e
commit
f7c9651ca7
23 changed files with 4749 additions and 184 deletions
36
llama_stack/ui/hooks/use-copy-to-clipboard.ts
Normal file
36
llama_stack/ui/hooks/use-copy-to-clipboard.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
import { useCallback, useRef, useState } from "react"
|
||||
import { toast } from "sonner"
|
||||
|
||||
type UseCopyToClipboardProps = {
|
||||
text: string
|
||||
copyMessage?: string
|
||||
}
|
||||
|
||||
export function useCopyToClipboard({
|
||||
text,
|
||||
copyMessage = "Copied to clipboard!",
|
||||
}: UseCopyToClipboardProps) {
|
||||
const [isCopied, setIsCopied] = useState(false)
|
||||
const timeoutRef = useRef<NodeJS.Timeout | null>(null)
|
||||
|
||||
const handleCopy = useCallback(() => {
|
||||
navigator.clipboard
|
||||
.writeText(text)
|
||||
.then(() => {
|
||||
toast.success(copyMessage)
|
||||
setIsCopied(true)
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current)
|
||||
timeoutRef.current = null
|
||||
}
|
||||
timeoutRef.current = setTimeout(() => {
|
||||
setIsCopied(false)
|
||||
}, 2000)
|
||||
})
|
||||
.catch(() => {
|
||||
toast.error("Failed to copy to clipboard.")
|
||||
})
|
||||
}, [text, copyMessage])
|
||||
|
||||
return { isCopied, handleCopy }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue