Skip to content

Commit

Permalink
feat(AIReplySection): add AIReplySection component with expandable vi…
Browse files Browse the repository at this point in the history
…ew and voting functionality
  • Loading branch information
MrOrz committed Jan 26, 2025
1 parent 6002bf6 commit 003b6a8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
Empty file added components/AIReplySection.js
Empty file.
51 changes: 51 additions & 0 deletions components/AIReplySection/AIReplySection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { useState } from 'react';
import { t } from 'ttag';
import { Box } from '@material-ui/core';
import KeyboardArrowUpIcon from '@material-ui/icons/KeyboardArrowUp';
import KeyboardArrowDownIcon from '@material-ui/icons/KeyboardArrowDown';

import { Card, CardHeader, CardContent } from 'components/Card';
import Hint from 'components/NewReplySection/ReplyForm/Hint';
import VoteButtons from './VoteButtons';

function AIReplySection({
defaultExpand = false,
aiReplyText = '',
aiResponseId,
}) {
const [expand, setExpand] = useState(defaultExpand);

return (
<Card style={{ background: '#fafafa' }}>
<CardHeader
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
borderBottomColor: expand ? '#333' : 'transparent',
paddingBottom: expand ? undefined : 12,
cursor: 'pointer',
}}
onClick={() => setExpand(v => !v)}
>
{t`Automated analysis from AI`}
{expand ? <KeyboardArrowDownIcon /> : <KeyboardArrowUpIcon />}
</CardHeader>
{expand && (
<CardContent>
<Hint>
{t`The following is the AI's preliminary analysis of this message, which we hope will provide you with some ideas before it is fact-checked by a human.`}
</Hint>
<div style={{ whiteSpace: 'pre-line', marginTop: 16 }}>
{aiReplyText}
</div>
<Box display="flex" justifyContent="space-between" mt={2}>
<VoteButtons aiResponseId={aiResponseId} />
</Box>
</CardContent>
)}
</Card>
);
}

export default AIReplySection;
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ const useStyles = makeStyles(theme => ({
},
}));

function VoteButtons({ aiResponseId }) {
type Props = {
aiResponseId: string;
};

function VoteButtons({ aiResponseId }: Props) {
const classes = useStyles();

const handleVote = async vote => {
const handleVote = async (vote: -1 | 1) => {
await langfuseWeb.score({
traceId: aiResponseId,
name: 'user-feedback',
Expand Down
2 changes: 2 additions & 0 deletions components/AIReplySection/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import AIReplySection from './AIReplySection';
export default AIReplySection;

0 comments on commit 003b6a8

Please sign in to comment.