index.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import type { FC } from 'react'
  2. import { useEffect, useRef, useState } from 'react'
  3. import { useClickAway } from 'ahooks'
  4. import Card from './card'
  5. import { CopyFeedbackNew } from '@/app/components/base/copy-feedback'
  6. import { XClose } from '@/app/components/base/icons/src/vender/line/general'
  7. type PromptLogModalProps = {
  8. log: { role: string; text: string }[]
  9. width: number
  10. onCancel: () => void
  11. }
  12. const PromptLogModal: FC<PromptLogModalProps> = ({
  13. log,
  14. width,
  15. onCancel,
  16. }) => {
  17. const ref = useRef(null)
  18. const [mounted, setMounted] = useState(false)
  19. useClickAway(() => {
  20. if (mounted)
  21. onCancel()
  22. }, ref)
  23. useEffect(() => {
  24. setMounted(true)
  25. }, [])
  26. if (!log)
  27. return null
  28. return (
  29. <div
  30. className='fixed top-16 left-2 bottom-2 flex flex-col bg-white border-[0.5px] border-gray-200 rounded-xl shadow-xl z-10'
  31. style={{ width }}
  32. ref={ref}
  33. >
  34. <div className='shrink-0 flex justify-between items-center pl-6 pr-5 h-14 border-b border-b-gray-100'>
  35. <div className='text-base font-semibold text-gray-900'>PROMPT LOG</div>
  36. <div className='flex items-center'>
  37. {
  38. log?.length === 1 && (
  39. <>
  40. <CopyFeedbackNew className='w-6 h-6' content={log[0].text} />
  41. <div className='mx-2.5 w-[1px] h-[14px] bg-gray-200' />
  42. </>
  43. )
  44. }
  45. <div
  46. onClick={onCancel}
  47. className='flex justify-center items-center w-6 h-6 cursor-pointer'
  48. >
  49. <XClose className='w-4 h-4 text-gray-500' />
  50. </div>
  51. </div>
  52. </div>
  53. <div className='grow p-2 overflow-y-auto'>
  54. <Card log={log} />
  55. </div>
  56. </div>
  57. )
  58. }
  59. export default PromptLogModal