@@ -80,28 +80,33 @@ type Props = {
80
80
} ;
81
81
82
82
// One browser refresh represents one voter
83
- const aiReplyVoterId = Math . random ( ) . toString ( 36 ) . substring ( 2 ) ;
83
+ const aiReplyVoterId = Math . random ( )
84
+ . toString ( 36 )
85
+ . substring ( 2 ) ;
84
86
85
87
function VoteButtons ( { aiResponseId } : Props ) {
86
88
const classes = useStyles ( ) ;
87
89
const [
88
90
votePopoverAnchorEl ,
89
91
setVotePopoverAnchorEl ,
90
- ] = useState < EventTarget | null > ( null ) ;
92
+ ] = useState < HTMLElement | null > ( null ) ;
91
93
const [ currentVote , setCurrentVote ] = useState < number > ( 0 ) ;
92
94
const [ comment , setComment ] = useState ( '' ) ;
93
95
96
+ // Creates and updates score using the same ID
97
+ const scoreId = `${ aiResponseId } __${ aiReplyVoterId } ` ;
98
+
94
99
const handleVoteClick = async (
95
100
event : React . MouseEvent < HTMLElement > ,
96
101
vote : number
97
102
) => {
98
- const buttonElem = event . target ;
103
+ const buttonElem = event . target as HTMLElement ;
99
104
// If clicking same vote again, set to 0 (no vote)
100
105
const newVote = vote === currentVote ? 0 : vote ;
101
106
102
107
// Send vote immediately, no ned to wait
103
108
langfuseWeb . score ( {
104
- id : ` ${ aiResponseId } __ ${ aiReplyVoterId } ` ,
109
+ id : scoreId ,
105
110
traceId : aiResponseId ,
106
111
name : 'user-feedback' ,
107
112
value : newVote ,
@@ -124,6 +129,7 @@ function VoteButtons({ aiResponseId }: Props) {
124
129
if ( currentVote === 0 || ! comment . trim ( ) ) return ;
125
130
126
131
await langfuseWeb . score ( {
132
+ id : scoreId ,
127
133
traceId : aiResponseId ,
128
134
name : 'user-feedback' ,
129
135
value : currentVote ,
0 commit comments