question.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import type {
  2. FC,
  3. ReactNode,
  4. } from 'react'
  5. import {
  6. memo,
  7. useRef,
  8. } from 'react'
  9. import type { ChatItem } from '../types'
  10. import { QuestionTriangle } from '@/app/components/base/icons/src/vender/solid/general'
  11. import { User } from '@/app/components/base/icons/src/public/avatar'
  12. import Log from '@/app/components/app/chat/log'
  13. import { Markdown } from '@/app/components/base/markdown'
  14. import ImageGallery from '@/app/components/base/image-gallery'
  15. type QuestionProps = {
  16. item: ChatItem
  17. showPromptLog?: boolean
  18. questionIcon?: ReactNode
  19. isResponding?: boolean
  20. }
  21. const Question: FC<QuestionProps> = ({
  22. item,
  23. showPromptLog,
  24. isResponding,
  25. questionIcon,
  26. }) => {
  27. const ref = useRef(null)
  28. const {
  29. content,
  30. message_files,
  31. } = item
  32. const imgSrcs = message_files?.length ? message_files.map(item => item.url) : []
  33. return (
  34. <div className='flex justify-end mb-2 last:mb-0 pl-10' ref={ref}>
  35. <div className='group relative mr-4'>
  36. <QuestionTriangle className='absolute -right-2 top-0 w-2 h-3 text-[#D1E9FF]/50' />
  37. {
  38. showPromptLog && !isResponding && (
  39. <Log log={item.log!} containerRef={ref} />
  40. )
  41. }
  42. <div className='px-4 py-3 bg-[#D1E9FF]/50 rounded-b-2xl rounded-tl-2xl text-sm text-gray-900'>
  43. {
  44. !!imgSrcs.length && (
  45. <ImageGallery srcs={imgSrcs} />
  46. )
  47. }
  48. <Markdown content={content} />
  49. </div>
  50. <div className='mt-1 h-[18px]' />
  51. </div>
  52. <div className='shrink-0 w-10 h-10'>
  53. {
  54. questionIcon || (
  55. <div className='w-full h-full rounded-full border-[0.5px] border-black/5'>
  56. <User className='w-full h-full' />
  57. </div>
  58. )
  59. }
  60. </div>
  61. </div>
  62. )
  63. }
  64. export default memo(Question)