Skip to content

Commit 2e6ea03

Browse files
committed
fixbug:添加类型标注
1 parent 0c39e2b commit 2e6ea03

File tree

1 file changed

+41
-30
lines changed

1 file changed

+41
-30
lines changed

app/components/markdown.tsx

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,40 @@ import { Collapse } from "antd";
2525
import styled from "styled-components";
2626
const { Panel } = Collapse;
2727

28-
const ThinkCollapse = styled(({ title, children, className }) => {
29-
// 如果是 Thinking 状态,默认展开,否则折叠
30-
const defaultActive = title === Locale.NewChat.Thinking ? ["1"] : [];
31-
const [activeKeys, setActiveKeys] = useState(defaultActive);
32-
33-
// 当标题从 Thinking 变为 Think 时自动折叠
34-
useEffect(() => {
35-
if (title === Locale.NewChat.Think) {
36-
setActiveKeys([]);
37-
} else if (title === Locale.NewChat.Thinking) {
38-
setActiveKeys(["1"]);
39-
}
40-
}, [title]);
41-
42-
return (
43-
<Collapse
44-
className={className}
45-
size="small"
46-
activeKey={activeKeys}
47-
onChange={(keys) => setActiveKeys(keys as string[])}
48-
>
49-
<Panel header={title} key="1">
50-
{children}
51-
</Panel>
52-
</Collapse>
53-
);
54-
})`
28+
interface ThinkCollapseProps {
29+
title: string | React.ReactNode;
30+
children: React.ReactNode;
31+
className?: string; // className 通常是可选的
32+
}
33+
const ThinkCollapse = styled(
34+
({ title, children, className }: ThinkCollapseProps) => {
35+
// 如果是 Thinking 状态,默认展开,否则折叠
36+
const defaultActive = title === Locale.NewChat.Thinking ? ["1"] : [];
37+
const [activeKeys, setActiveKeys] = useState(defaultActive);
38+
39+
// 当标题从 Thinking 变为 Think 时自动折叠
40+
useEffect(() => {
41+
if (title === Locale.NewChat.Think) {
42+
setActiveKeys([]);
43+
} else if (title === Locale.NewChat.Thinking) {
44+
setActiveKeys(["1"]);
45+
}
46+
}, [title]);
47+
48+
return (
49+
<Collapse
50+
className={className}
51+
size="small"
52+
activeKey={activeKeys}
53+
onChange={(keys) => setActiveKeys(keys as string[])}
54+
>
55+
<Panel header={title} key="1">
56+
{children}
57+
</Panel>
58+
</Collapse>
59+
);
60+
},
61+
)`
5562
.ant-collapse-item {
5663
border: none !important;
5764
border-radius: 6px !important;
@@ -486,9 +493,13 @@ function R_MarkDownContent(props: { content: string }) {
486493
pre: PreCode,
487494
code: CustomCode,
488495
p: (pProps) => <p {...pProps} dir="auto" />,
489-
thinkcollapse: ({ title, children }) => (
490-
<ThinkCollapse title={title}>{children}</ThinkCollapse>
491-
),
496+
thinkcollapse: ({
497+
title,
498+
children,
499+
}: {
500+
title: string;
501+
children: React.ReactNode;
502+
}) => <ThinkCollapse title={title}>{children}</ThinkCollapse>,
492503
a: (aProps) => {
493504
const href = aProps.href || "";
494505
if (/\.(aac|mp3|opus|wav)$/.test(href)) {

0 commit comments

Comments
 (0)