index.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useRef } from 'react'
  4. import { useContext } from 'use-context-selector'
  5. import s from '../style.module.css'
  6. import type { IChatItem } from '../type'
  7. import Log from '../log'
  8. import MoreInfo from '../more-info'
  9. import AppContext from '@/context/app-context'
  10. import { Markdown } from '@/app/components/base/markdown'
  11. type IQuestionProps = Pick<IChatItem, 'id' | 'content' | 'more' | 'useCurrentUserAvatar'> & {
  12. isShowPromptLog?: boolean
  13. item: IChatItem
  14. isResponsing?: boolean
  15. }
  16. const Question: FC<IQuestionProps> = ({ id, content, more, useCurrentUserAvatar, isShowPromptLog, item, isResponsing }) => {
  17. const { userProfile } = useContext(AppContext)
  18. const userName = userProfile?.name
  19. const ref = useRef(null)
  20. return (
  21. <div className={`flex items-start justify-end ${isShowPromptLog && 'first-of-type:pt-[14px]'}`} key={id} ref={ref}>
  22. <div className={s.questionWrapWrap}>
  23. <div className={`${s.question} group relative text-sm text-gray-900`}>
  24. {
  25. isShowPromptLog && !isResponsing && (
  26. <Log log={item.log!} containerRef={ref} />
  27. )
  28. }
  29. <div
  30. className={'mr-2 py-3 px-4 bg-blue-500 rounded-tl-2xl rounded-b-2xl'}
  31. >
  32. <Markdown content={content} />
  33. </div>
  34. </div>
  35. {more && <MoreInfo more={more} isQuestion={true} />}
  36. </div>
  37. {useCurrentUserAvatar
  38. ? (
  39. <div className='w-10 h-10 shrink-0 leading-10 text-center mr-2 rounded-full bg-primary-600 text-white'>
  40. {userName?.[0].toLocaleUpperCase()}
  41. </div>
  42. )
  43. : (
  44. <div className={`${s.questionIcon} w-10 h-10 shrink-0 `}></div>
  45. )}
  46. </div>
  47. )
  48. }
  49. export default React.memo(Question)