(messageId: string, text: string)
| 211 | >({}) |
| 212 | |
| 213 | const copyMessageToClipboard = async (messageId: string, text: string) => { |
| 214 | try { |
| 215 | await navigator.clipboard.writeText(text) |
| 216 | |
| 217 | setCopiedMessageId(messageId) |
| 218 | setTimeout(() => setCopiedMessageId(null), 2000) |
| 219 | } catch (err) { |
| 220 | // Fallback for non-secure contexts (HTTP) or permission denied |
| 221 | const textarea = document.createElement("textarea") |
| 222 | textarea.value = text |
| 223 | textarea.style.position = "fixed" |
| 224 | textarea.style.left = "-9999px" |
| 225 | textarea.style.opacity = "0" |
| 226 | document.body.appendChild(textarea) |
| 227 | |
| 228 | try { |
| 229 | textarea.select() |
| 230 | const success = document.execCommand("copy") |
| 231 | if (!success) { |
| 232 | throw new Error("Copy command failed") |
| 233 | } |
| 234 | setCopiedMessageId(messageId) |
| 235 | setTimeout(() => setCopiedMessageId(null), 2000) |
| 236 | } catch (fallbackErr) { |
| 237 | console.error("Failed to copy message:", fallbackErr) |
| 238 | toast.error( |
| 239 | "Failed to copy message. Please copy manually or check clipboard permissions.", |
| 240 | ) |
| 241 | setCopyFailedMessageId(messageId) |
| 242 | setTimeout(() => setCopyFailedMessageId(null), 2000) |
| 243 | } finally { |
| 244 | document.body.removeChild(textarea) |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | const submitFeedback = async (messageId: string, value: "good" | "bad") => { |
| 250 | // Toggle off if already selected |
no outgoing calls
no test coverage detected