({ onRequestFix }: { onRequestFix: (e: string) => void })
| 37 | } |
| 38 | |
| 39 | function ErrorMessage({ onRequestFix }: { onRequestFix: (e: string) => void }) { |
| 40 | const { sandpack } = useSandpack(); |
| 41 | const [didCopy, setDidCopy] = useState(false); |
| 42 | |
| 43 | if (!sandpack.error) return null; |
| 44 | |
| 45 | return ( |
| 46 | <div className="absolute inset-0 flex flex-col items-center justify-center gap-4 bg-white/5 text-base backdrop-blur-sm"> |
| 47 | <div className="max-w-[400px] rounded-md bg-red-500 p-4 text-white shadow-xl shadow-black/20"> |
| 48 | <p className="text-lg font-medium">Error</p> |
| 49 | |
| 50 | <p className="mt-4 line-clamp-[10] overflow-x-auto whitespace-pre font-mono text-xs"> |
| 51 | {sandpack.error.message} |
| 52 | </p> |
| 53 | |
| 54 | <div className="mt-8 flex justify-between gap-4"> |
| 55 | <button |
| 56 | onClick={async () => { |
| 57 | if (!sandpack.error) return; |
| 58 | |
| 59 | setDidCopy(true); |
| 60 | await window.navigator.clipboard.writeText( |
| 61 | sandpack.error.message, |
| 62 | ); |
| 63 | await new Promise((resolve) => setTimeout(resolve, 2000)); |
| 64 | setDidCopy(false); |
| 65 | }} |
| 66 | className="rounded border-red-300 px-2.5 py-1.5 text-sm font-semibold text-red-50" |
| 67 | > |
| 68 | {didCopy ? <CheckIcon size={18} /> : <CopyIcon size={18} />} |
| 69 | </button> |
| 70 | <button |
| 71 | onClick={() => { |
| 72 | if (!sandpack.error) return; |
| 73 | onRequestFix(sandpack.error.message); |
| 74 | }} |
| 75 | className="rounded bg-white px-2.5 py-1.5 text-sm font-medium text-black" |
| 76 | > |
| 77 | Try to fix |
| 78 | </button> |
| 79 | </div> |
| 80 | </div> |
| 81 | </div> |
| 82 | ); |
| 83 | } |
nothing calls this directly
no outgoing calls
no test coverage detected