index.tsx 2.0 KB

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