Skip to content

Commit

Permalink
feat(VoteButtons): improve vote handling and immediate feedback mecha…
Browse files Browse the repository at this point in the history
…nism
  • Loading branch information
MrOrz committed Jan 26, 2025
1 parent 2eef3f9 commit 436ade4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions components/AIReplySection/VoteButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,29 @@ type Props = {
aiResponseId: string;
};

// One browser refresh represents one voter
const aiReplyVoterId = Math.random().toString(36).substring(2);

Check failure on line 83 in components/AIReplySection/VoteButtons.tsx

View workflow job for this annotation

GitHub Actions / install-and-test

Replace `.toString(36)` with `⏎··.toString(36)⏎··`

Check failure on line 83 in components/AIReplySection/VoteButtons.tsx

View workflow job for this annotation

GitHub Actions / install-and-test

Replace `.toString(36)` with `⏎··.toString(36)⏎··`

function VoteButtons({ aiResponseId }: Props) {
const classes = useStyles();
const [
votePopoverAnchorEl,
setVotePopoverAnchorEl,
] = useState<HTMLElement | null>(null);
] = useState<EventTarget | null>(null);
const [currentVote, setCurrentVote] = useState<number>(0);
const [comment, setComment] = useState('');

const handleVoteClick = async (
event: React.MouseEvent<HTMLElement>,
vote: number
) => {
const buttonElem = event.target;
// If clicking same vote again, set to 0 (no vote)
const newVote = vote === currentVote ? 0 : vote;

// Send vote immediately
await langfuseWeb.score({
// Send vote immediately, no ned to wait
langfuseWeb.score({
id: `${aiResponseId}__${aiReplyVoterId}`,
traceId: aiResponseId,
name: 'user-feedback',
value: newVote,
Expand All @@ -106,7 +111,7 @@ function VoteButtons({ aiResponseId }: Props) {

// Only open popover if setting a new vote (not removing)
if (newVote !== 0) {
setVotePopoverAnchorEl(event.currentTarget);
setVotePopoverAnchorEl(buttonElem);
}
};

Expand Down

0 comments on commit 436ade4

Please sign in to comment.