1- import { useState } from 'react'
1+ import { memo , useState } from 'react'
22import { ChevronDownIcon , XCircleIcon , SyncIcon } from '@primer/octicons-react'
33import CopyButton from '../CopyButton'
44import ReadButton from '../ReadButton'
@@ -8,12 +8,30 @@ import { useTranslation } from 'react-i18next'
88import { isUsingCustomModel } from '../../config/index.mjs'
99import { useConfig } from '../../hooks/use-config.mjs'
1010
11- // eslint-disable-next-line
12- export function ConversationItem ( { type, content, session, onRetry } ) {
11+ function AnswerTitle ( { descName, modelName } ) {
1312 const { t } = useTranslation ( )
14- const [ collapsed , setCollapsed ] = useState ( false )
1513 const config = useConfig ( )
1614
15+ return (
16+ < p style = "white-space: nowrap;" >
17+ { descName && modelName
18+ ? `${ t ( descName ) } ${
19+ isUsingCustomModel ( { modelName } ) ? ' (' + config . customModelName + ')' : ''
20+ } :`
21+ : t ( 'Loading...' ) }
22+ </ p >
23+ )
24+ }
25+
26+ AnswerTitle . propTypes = {
27+ descName : PropTypes . string ,
28+ modelName : PropTypes . string ,
29+ }
30+
31+ export function ConversationItem ( { type, content, descName, modelName, onRetry } ) {
32+ const { t } = useTranslation ( )
33+ const [ collapsed , setCollapsed ] = useState ( false )
34+
1735 switch ( type ) {
1836 case 'question' :
1937 return (
@@ -49,23 +67,17 @@ export function ConversationItem({ type, content, session, onRetry }) {
4967 return (
5068 < div className = { type } dir = "auto" >
5169 < div className = "gpt-header" >
52- < p style = "white-space: nowrap;" >
53- { session && session . aiName
54- ? `${ t ( session . aiName ) } ${
55- isUsingCustomModel ( session ) ? ' (' + config . customModelName + ')' : ''
56- } :`
57- : t ( 'Loading...' ) }
58- </ p >
70+ < AnswerTitle descName = { descName } modelName = { modelName } />
5971 < div className = "gpt-util-group" >
6072 { onRetry && (
6173 < span title = { t ( 'Retry' ) } className = "gpt-util-icon" onClick = { onRetry } >
6274 < SyncIcon size = { 14 } />
6375 </ span >
6476 ) }
65- { session && (
77+ { modelName && (
6678 < CopyButton contentFn = { ( ) => content . replace ( / \n < h r \/ > $ / , '' ) } size = { 14 } />
6779 ) }
68- { session && < ReadButton contentFn = { ( ) => content } size = { 14 } /> }
80+ { modelName && < ReadButton contentFn = { ( ) => content } size = { 14 } /> }
6981 { ! collapsed ? (
7082 < span
7183 title = { t ( 'Collapse' ) }
@@ -128,8 +140,9 @@ export function ConversationItem({ type, content, session, onRetry }) {
128140ConversationItem . propTypes = {
129141 type : PropTypes . oneOf ( [ 'question' , 'answer' , 'error' ] ) . isRequired ,
130142 content : PropTypes . string . isRequired ,
131- session : PropTypes . object . isRequired ,
143+ descName : PropTypes . string ,
144+ modelName : PropTypes . string ,
132145 onRetry : PropTypes . func ,
133146}
134147
135- export default ConversationItem
148+ export default memo ( ConversationItem )
0 commit comments