From 772cdf3be36cd5e18cb8477a55c7e7557e2663f6 Mon Sep 17 00:00:00 2001 From: MrOrz Date: Wed, 29 Mar 2023 02:12:08 +0800 Subject: [PATCH] feat(AIReplySection): add collapse / expand logic --- components/AIReplySection.js | 43 ++++++++++++++++++++++++++++++++++++ pages/article/[id].js | 17 +++++--------- 2 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 components/AIReplySection.js diff --git a/components/AIReplySection.js b/components/AIReplySection.js new file mode 100644 index 00000000..fdbd6dee --- /dev/null +++ b/components/AIReplySection.js @@ -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 ( + + setExpand(v => !v)} + > + {t`Automated analysis from ChatGPT`} + {expand ? : } + + {expand && ( + + + {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.`} + +
+ {aiReplyText} +
+
+ )} +
+ ); +} + +export default AIReplySection; diff --git a/pages/article/[id].js b/pages/article/[id].js index 19244a55..fb36310a 100644 --- a/pages/article/[id].js +++ b/pages/article/[id].js @@ -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: { @@ -532,17 +532,10 @@ function ArticlePage() { )} {article.aiReplies?.length > 0 && ( - - {t`Automated analysis from ChatGPT`} - - - {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.`} - -
- {article.aiReplies[0].text} -
-
-
+ )}