Skip to content

Commit a5b838f

Browse files
fix:change promprt ui
1 parent 7eeb004 commit a5b838f

3 files changed

Lines changed: 33 additions & 24 deletions

File tree

gui_v2/src/pages/Prompts/components/PromptExamples.tsx

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from 'react';
1+
import React, { useState, useEffect, useMemo } from 'react';
22
import { Card, Typography, Space, Tag, Divider, Collapse, Tabs, Spin, Alert } from 'antd';
33
import {
44
CheckCircleOutlined,
@@ -14,6 +14,28 @@ import ReactMarkdown from 'react-markdown';
1414

1515
const { Title, Text, Paragraph } = Typography;
1616

17+
// Style constants to prevent recreation on every render
18+
const CONTAINER_STYLE = {
19+
height: '100%',
20+
display: 'flex' as const,
21+
flexDirection: 'column' as const,
22+
background: '#0f172a'
23+
};
24+
25+
const TABS_STYLE = {
26+
flex: 1,
27+
display: 'flex' as const,
28+
flexDirection: 'column' as const
29+
};
30+
31+
const TAB_BAR_STYLE = {
32+
margin: '0 20px',
33+
paddingTop: '16px',
34+
marginBottom: 16,
35+
borderBottom: '1px solid rgba(148,163,184,0.14)',
36+
flexShrink: 0
37+
};
38+
1739
interface Example {
1840
id: string;
1941
category: string;
@@ -32,6 +54,7 @@ const PromptExamples: React.FC = () => {
3254
const [loading, setLoading] = useState(false);
3355
const [error, setError] = useState<string | null>(null);
3456

57+
// Load markdown only once on mount
3558
useEffect(() => {
3659
const loadMarkdown = async () => {
3760
setLoading(true);
@@ -331,7 +354,8 @@ class User(BaseModel):
331354
return acc;
332355
}, {} as Record<string, Example[]>);
333356

334-
const tabItems = [
357+
// Memoize tabItems to prevent recreation on every render
358+
const tabItems = useMemo(() => [
335359
{
336360
key: 'builtin',
337361
label: (
@@ -636,33 +660,18 @@ class User(BaseModel):
636660
</>
637661
),
638662
},
639-
];
663+
], [t, loading, error, markdownContent, groupedExamples, getLevelColor, getLevelText]);
640664

641665
return (
642-
<div style={{
643-
height: '100%',
644-
display: 'flex',
645-
flexDirection: 'column',
646-
background: '#0f172a'
647-
}}>
666+
<div style={CONTAINER_STYLE}>
648667
<Tabs
649668
defaultActiveKey="builtin"
650669
items={tabItems}
651-
style={{
652-
flex: 1,
653-
display: 'flex',
654-
flexDirection: 'column'
655-
}}
656-
tabBarStyle={{
657-
margin: '0 20px',
658-
paddingTop: '16px',
659-
marginBottom: 16,
660-
borderBottom: '1px solid rgba(148,163,184,0.14)',
661-
flexShrink: 0
662-
}}
670+
style={TABS_STYLE}
671+
tabBarStyle={TAB_BAR_STYLE}
663672
/>
664673
</div>
665674
);
666675
};
667676

668-
export default PromptExamples;
677+
export default React.memo(PromptExamples);

gui_v2/src/pages/Prompts/components/PromptGuide.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,4 @@ const PromptGuide: React.FC<PromptGuideProps> = ({ visible = true }) => {
328328
);
329329
};
330330

331-
export default PromptGuide;
331+
export default React.memo(PromptGuide);

gui_v2/src/pages/Prompts/components/PromptTemplates.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,4 +585,4 @@ Output Format:
585585
);
586586
};
587587

588-
export default PromptTemplates;
588+
export default React.memo(PromptTemplates);

0 commit comments

Comments
 (0)