1- import { createEffect , createMemo , Show , createSignal , onMount , For } from 'solid-js' ;
1+ import { createEffect , createMemo , Show , createSignal , onMount , For , untrack } from 'solid-js' ;
22import { Avatar } from '../avatars/Avatar' ;
33import { Marked } from '@ts-stack/markdown' ;
44import DOMPurify from 'dompurify' ;
@@ -38,6 +38,7 @@ type Props = {
3838 handleSourceDocumentsClick : ( src : any ) => void ;
3939 onRegenerateResponse ?: ( ) => void ;
4040 showRegenerateResponseButton ?: boolean ;
41+ onRatingUpdate ?: ( messageId : string , rating : FeedbackRatingType ) => void ;
4142 // TTS props
4243 isTTSEnabled ?: boolean ;
4344 isTTSLoading ?: Record < string , boolean > ;
@@ -58,12 +59,9 @@ export const BotBubble = (props: Props) => {
5859
5960 Marked . setOptions ( { isNoP : true , sanitize : props . renderHTML !== undefined ? ! props . renderHTML : true } ) ;
6061
61- const [ rating , setRating ] = createSignal ( '' ) ;
6262 const [ feedbackId , setFeedbackId ] = createSignal ( '' ) ;
6363 const [ showFeedbackContentDialog , setShowFeedbackContentModal ] = createSignal ( false ) ;
6464 const [ copiedMessage , setCopiedMessage ] = createSignal ( false ) ;
65- const [ thumbsUpColor , setThumbsUpColor ] = createSignal ( props . feedbackColor ?? defaultFeedbackColor ) ; // default color
66- const [ thumbsDownColor , setThumbsDownColor ] = createSignal ( props . feedbackColor ?? defaultFeedbackColor ) ; // default color
6765 const [ responseVersionIndex , setResponseVersionIndex ] = createSignal ( 0 ) ;
6866 const [ ratingByMessageId , setRatingByMessageId ] = createSignal < Record < string , FeedbackRatingType > > ( { } ) ;
6967
@@ -77,7 +75,6 @@ export const BotBubble = (props: Props) => {
7775
7876 const totalResponseVersions = createMemo ( ( ) => responseVersions ( ) . length ) ;
7977 const hasMultipleResponseVersions = createMemo ( ( ) => totalResponseVersions ( ) > 1 ) ;
80- console . log ( 'hasMultipleResponseVersions' , hasMultipleResponseVersions ( ) ) ;
8178
8279 const activeMessage = createMemo ( ( ) => {
8380 const versions = responseVersions ( ) ;
@@ -98,6 +95,9 @@ export const BotBubble = (props: Props) => {
9895 return active . rating ?? '' ;
9996 } ;
10097
98+ const thumbsUpColor = ( ) => currentRating ( ) === 'THUMBS_UP' ? '#006400' : ( props . feedbackColor ?? defaultFeedbackColor ) ;
99+ const thumbsDownColor = ( ) => currentRating ( ) === 'THUMBS_DOWN' ? '#8B0000' : ( props . feedbackColor ?? defaultFeedbackColor ) ;
100+
101101 const setBotMessageRef = ( el : HTMLSpanElement ) => {
102102 if ( el ) {
103103 setBotMessageElement ( el ) ;
@@ -115,6 +115,18 @@ export const BotBubble = (props: Props) => {
115115 setResponseVersionIndex ( safeIndex ) ;
116116 } ) ;
117117
118+ createEffect ( ( ) => {
119+ responseVersionIndex ( ) ; // subscribe to version switches
120+ untrack ( ( ) => {
121+ responseVersions ( ) . forEach ( ( version ) => {
122+ const id = version . id || version . messageId ;
123+ if ( id && ( props . isTTSPlaying ?. [ id ] || props . isTTSLoading ?. [ id ] ) ) {
124+ props . handleTTSStop ?.( id ) ;
125+ }
126+ } ) ;
127+ } ) ;
128+ } ) ;
129+
118130 createEffect ( ( ) => {
119131 const el = botMessageElement ( ) ;
120132 const messageData = activeMessage ( ) ;
@@ -146,18 +158,6 @@ export const BotBubble = (props: Props) => {
146158 link . target = '_blank' ;
147159 } ) ;
148160
149- const activeRating = currentRating ( ) ;
150- setRating ( activeRating ) ;
151- if ( activeRating === 'THUMBS_UP' ) {
152- setThumbsUpColor ( '#006400' ) ;
153- setThumbsDownColor ( props . feedbackColor ?? defaultFeedbackColor ) ;
154- } else if ( activeRating === 'THUMBS_DOWN' ) {
155- setThumbsDownColor ( '#8B0000' ) ;
156- setThumbsUpColor ( props . feedbackColor ?? defaultFeedbackColor ) ;
157- } else {
158- setThumbsUpColor ( props . feedbackColor ?? defaultFeedbackColor ) ;
159- setThumbsDownColor ( props . feedbackColor ?? defaultFeedbackColor ) ;
160- }
161161 const fileAnnotations = messageData . fileAnnotations ?? props . fileAnnotations ;
162162 if ( fileAnnotations && fileAnnotations . length ) {
163163 for ( const annotations of fileAnnotations ) {
@@ -267,7 +267,7 @@ export const BotBubble = (props: Props) => {
267267 } ;
268268
269269 const onThumbsUpClick = async ( ) => {
270- if ( rating ( ) === '' ) {
270+ if ( currentRating ( ) === '' ) {
271271 const activeMessageId = activeMessage ( ) . messageId ;
272272 if ( ! activeMessageId ) return ;
273273 const body = {
@@ -288,19 +288,17 @@ export const BotBubble = (props: Props) => {
288288 const data = result . data as any ;
289289 let id = '' ;
290290 if ( data && data . id ) id = data . id ;
291- setRating ( 'THUMBS_UP' ) ;
292291 setRatingByMessageId ( ( prev ) => ( { ...prev , [ activeMessageId ] : 'THUMBS_UP' } ) ) ;
292+ props . onRatingUpdate ?.( activeMessageId , 'THUMBS_UP' ) ;
293293 setFeedbackId ( id ) ;
294294 setShowFeedbackContentModal ( true ) ;
295- // update the thumbs up color state
296- setThumbsUpColor ( '#006400' ) ;
297295 saveToLocalStorage ( 'THUMBS_UP' ) ;
298296 }
299297 }
300298 } ;
301299
302300 const onThumbsDownClick = async ( ) => {
303- if ( rating ( ) === '' ) {
301+ if ( currentRating ( ) === '' ) {
304302 const activeMessageId = activeMessage ( ) . messageId ;
305303 if ( ! activeMessageId ) return ;
306304 const body = {
@@ -321,12 +319,10 @@ export const BotBubble = (props: Props) => {
321319 const data = result . data as any ;
322320 let id = '' ;
323321 if ( data && data . id ) id = data . id ;
324- setRating ( 'THUMBS_DOWN' ) ;
325322 setRatingByMessageId ( ( prev ) => ( { ...prev , [ activeMessageId ] : 'THUMBS_DOWN' } ) ) ;
323+ props . onRatingUpdate ?.( activeMessageId , 'THUMBS_DOWN' ) ;
326324 setFeedbackId ( id ) ;
327325 setShowFeedbackContentModal ( true ) ;
328- // update the thumbs down color state
329- setThumbsDownColor ( '#8B0000' ) ;
330326 saveToLocalStorage ( 'THUMBS_DOWN' ) ;
331327 }
332328 }
@@ -544,7 +540,7 @@ export const BotBubble = (props: Props) => {
544540 < ThinkingCard
545541 thinking = { activeMessage ( ) . thinking }
546542 thinkingDuration = { activeMessage ( ) . thinkingDuration }
547- isThinking = { activeMessage ( ) . isThinking }
543+ isThinking = { props . message . isThinking }
548544 backgroundColor = { props . backgroundColor ?? defaultBackgroundColor }
549545 textColor = { props . textColor ?? defaultTextColor }
550546 />
@@ -696,14 +692,14 @@ export const BotBubble = (props: Props) => {
696692 Copied!
697693 </ div >
698694 </ Show >
699- { rating ( ) === '' || rating ( ) === 'THUMBS_UP' ? (
700- < ThumbsUpButton feedbackColor = { thumbsUpColor ( ) } isDisabled = { rating ( ) === 'THUMBS_UP' } rating = { rating ( ) } onClick = { onThumbsUpClick } />
695+ { currentRating ( ) === '' || currentRating ( ) === 'THUMBS_UP' ? (
696+ < ThumbsUpButton feedbackColor = { thumbsUpColor ( ) } isDisabled = { currentRating ( ) === 'THUMBS_UP' } rating = { currentRating ( ) } onClick = { onThumbsUpClick } />
701697 ) : null }
702- { rating ( ) === '' || rating ( ) === 'THUMBS_DOWN' ? (
698+ { currentRating ( ) === '' || currentRating ( ) === 'THUMBS_DOWN' ? (
703699 < ThumbsDownButton
704700 feedbackColor = { thumbsDownColor ( ) }
705- isDisabled = { rating ( ) === 'THUMBS_DOWN' }
706- rating = { rating ( ) }
701+ isDisabled = { currentRating ( ) === 'THUMBS_DOWN' }
702+ rating = { currentRating ( ) }
707703 onClick = { onThumbsDownClick }
708704 />
709705 ) : null }
0 commit comments