Skip to content

Commit

Permalink
feat(AIReplySection): add collapse / expand logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed Mar 28, 2023
1 parent 0fd82d6 commit 772cdf3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
43 changes: 43 additions & 0 deletions components/AIReplySection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { useState } from 'react';
import { t } from 'ttag';

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';

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

return (
<Card>
<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 ChatGPT`}
{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>
</CardContent>
)}
</Card>
);
}

export default AIReplySection;
17 changes: 5 additions & 12 deletions pages/article/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ import CurrentReplies from 'components/CurrentReplies';
import ReplyRequestReason from 'components/ReplyRequestReason';
import CreateReplyRequestForm from 'components/CreateReplyRequestForm';
import NewReplySection from 'components/NewReplySection';
import Hint from 'components/NewReplySection/ReplyForm/Hint';
import ArticleInfo from 'components/ArticleInfo';
import ArticleCategories from 'components/ArticleCategories';
import TrendPlot from 'components/TrendPlot';
import Infos, { TimeInfo } from 'components/Infos';
import Thumbnail from 'components/Thumbnail';
import AIReplySection from 'components/AIReplySection';

const useStyles = makeStyles(theme => ({
root: {
Expand Down Expand Up @@ -532,17 +532,10 @@ function ArticlePage() {
)}

{article.aiReplies?.length > 0 && (
<Card>
<CardHeader>{t`Automated analysis from ChatGPT`}</CardHeader>
<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 }}>
{article.aiReplies[0].text}
</div>
</CardContent>
</Card>
<AIReplySection
defaultExpand={replyCount === 0}
aiReplyText={article.aiReplies[0].text}
/>
)}

<Hidden smDown implementation="css">
Expand Down

0 comments on commit 772cdf3

Please sign in to comment.