@@ -2,12 +2,14 @@ import { hooks } from 'botframework-webchat-api';
22import { getOrgSchemaMessage , OrgSchemaAction , parseAction , WebChatActivity } from 'botframework-webchat-core' ;
33import classNames from 'classnames' ;
44import React , { memo , useCallback , useMemo , useState } from 'react' ;
5+ import { useRefFrom } from 'use-ref-from' ;
6+
57import useStyleSet from '../hooks/useStyleSet' ;
68import dereferenceBlankNodes from '../Utils/JSONLinkedData/dereferenceBlankNodes' ;
79import Feedback from './private/Feedback' ;
10+ import FeedbackForm from './private/FeedbackForm' ;
811import getDisclaimer from './private/getDisclaimer' ;
912import hasFeedbackLoop from './private/hasFeedbackLoop' ;
10- import FeedbackForm from './private/FeedbackForm' ;
1113
1214const { useStyleOptions } = hooks ;
1315
@@ -47,6 +49,7 @@ function ActivityFeedback({ activity }: ActivityFeedbackProps) {
4749
4850 const [ selectedAction , setSelectedAction ] = useState < OrgSchemaAction | undefined > ( ) ;
4951 const [ feedbackSubmitted , setFeedbackSubmitted ] = useState < boolean > ( false ) ;
52+ const selectedActionRef = useRefFrom ( selectedAction ) ;
5053
5154 const isFeedbackLoopSupported = hasFeedbackLoop ( activity ) ;
5255
@@ -62,14 +65,13 @@ function ActivityFeedback({ activity }: ActivityFeedbackProps) {
6265 try {
6366 const reactActions = ( messageThing ?. potentialAction || [ ] )
6467 . filter ( ( { '@type' : type } ) => type === 'LikeAction' || type === 'DislikeAction' )
65- . map ( action =>
66- Object . assign ( { } , action , {
67- actionStatus :
68- action [ '@type' ] === selectedAction ?. [ '@type' ] && feedbackSubmitted
69- ? 'CompletedActionStatus'
70- : action . actionStatus
71- } )
72- ) ;
68+ . map ( action => ( {
69+ ...action ,
70+ actionStatus :
71+ action [ '@type' ] === selectedActionRef . current ?. [ '@type' ] && feedbackSubmitted
72+ ? 'CompletedActionStatus'
73+ : action . actionStatus
74+ } ) ) ;
7375
7476 if ( reactActions . length ) {
7577 return Object . freeze ( new Set ( reactActions ) ) ;
@@ -84,9 +86,7 @@ function ActivityFeedback({ activity }: ActivityFeedbackProps) {
8486 // Intentionally left blank.
8587 }
8688 return Object . freeze ( new Set ( [ ] as OrgSchemaAction [ ] ) ) ;
87- // Do not want to add selectedAction to the dependency array as it will cause an infinite loop
88- // eslint-disable-next-line react-hooks/exhaustive-deps
89- } , [ feedbackSubmitted , graph , messageThing ?. potentialAction ] ) ;
89+ } , [ feedbackSubmitted , graph , messageThing , selectedActionRef ] ) ;
9090
9191 const handleFeedbackActionClick = useCallback (
9292 ( action : OrgSchemaAction ) => setSelectedAction ( action === selectedAction ? undefined : action ) ,
0 commit comments