index.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. return (
  27. <div
  28. 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'
  29. style={{ width }}
  30. ref={ref}
  31. >
  32. <div className='shrink-0 flex justify-between items-center pl-6 pr-5 h-14 border-b border-b-gray-100'>
  33. <div className='text-base font-semibold text-gray-900'>PROMPT LOG</div>
  34. <div className='flex items-center'>
  35. {
  36. log.length === 1 && (
  37. <>
  38. <CopyFeedbackNew className='w-6 h-6' content={log[0].text} />
  39. <div className='mx-2.5 w-[1px] h-[14px] bg-gray-200' />
  40. </>
  41. )
  42. }
  43. <div
  44. onClick={onCancel}
  45. className='flex justify-center items-center w-6 h-6 cursor-pointer'
  46. >
  47. <XClose className='w-4 h-4 text-gray-500' />
  48. </div>
  49. </div>
  50. </div>
  51. <div className='grow p-2 overflow-y-auto'>
  52. <Card log={log} />
  53. </div>
  54. </div>
  55. )
  56. }
  57. export default PromptLogModal