mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
* feat(tools): added sentry, incidentio, and posthog tools * update docs * fixed docs to use native fumadocs for llms.txt and copy markdown, fixed tool issues * cleanup * enhance error extractor, fixed posthog tools * docs enhancements, cleanup * added more incident io ops, remove zustand/shallow in favor of zustand/react/shallow * fix type errors * remove unnecessary comments * added vllm to docs
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
'use client'
|
|
|
|
import { useState } from 'react'
|
|
import { Check, Copy } from 'lucide-react'
|
|
|
|
const cache = new Map<string, string>()
|
|
|
|
interface CopyPageButtonProps {
|
|
markdownUrl: string
|
|
}
|
|
|
|
export function CopyPageButton({ markdownUrl }: CopyPageButtonProps) {
|
|
const [copied, setCopied] = useState(false)
|
|
const [isLoading, setLoading] = useState(false)
|
|
|
|
const handleCopy = async () => {
|
|
const cached = cache.get(markdownUrl)
|
|
if (cached) {
|
|
await navigator.clipboard.writeText(cached)
|
|
setCopied(true)
|
|
setTimeout(() => setCopied(false), 2000)
|
|
return
|
|
}
|
|
|
|
setLoading(true)
|
|
try {
|
|
await navigator.clipboard.write([
|
|
new ClipboardItem({
|
|
'text/plain': fetch(markdownUrl).then(async (res) => {
|
|
const content = await res.text()
|
|
cache.set(markdownUrl, content)
|
|
return content
|
|
}),
|
|
}),
|
|
])
|
|
setCopied(true)
|
|
setTimeout(() => setCopied(false), 2000)
|
|
} catch (err) {
|
|
console.error('Failed to copy:', err)
|
|
} finally {
|
|
setLoading(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<button
|
|
disabled={isLoading}
|
|
onClick={handleCopy}
|
|
className='flex cursor-pointer items-center gap-1.5 rounded-lg border border-border/40 bg-background px-2.5 py-2 text-muted-foreground/60 text-sm leading-none transition-all hover:border-border hover:bg-accent/50 hover:text-muted-foreground'
|
|
aria-label={copied ? 'Copied to clipboard' : 'Copy page content'}
|
|
>
|
|
{copied ? (
|
|
<>
|
|
<Check className='h-3.5 w-3.5' />
|
|
<span>Copied</span>
|
|
</>
|
|
) : (
|
|
<>
|
|
<Copy className='h-3.5 w-3.5' />
|
|
<span>Copy page</span>
|
|
</>
|
|
)}
|
|
</button>
|
|
)
|
|
}
|