Skip to content

Commit 39fd2c4

Browse files
committed
refactor: moved stuff out of chat.tsx into their own components
1 parent b3bc328 commit 39fd2c4

15 files changed

+2539
-1899
lines changed

cli/src/branch-item.tsx

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import React, { type ReactNode } from 'react'
2+
import { TextAttributes } from '@opentui/core'
3+
import type { ChatTheme } from './theme-system'
4+
5+
interface BranchItemProps {
6+
id: string
7+
name: string
8+
content: ReactNode
9+
isCollapsed: boolean
10+
isStreaming: boolean
11+
branchChar: string
12+
streamingPreview: string
13+
finishedPreview: string
14+
theme: ChatTheme
15+
onToggle: () => void
16+
}
17+
18+
export const BranchItem = ({
19+
id,
20+
name,
21+
content,
22+
isCollapsed,
23+
isStreaming,
24+
branchChar,
25+
streamingPreview,
26+
finishedPreview,
27+
theme,
28+
onToggle,
29+
}: BranchItemProps) => {
30+
return (
31+
<box style={{ flexDirection: 'row', flexShrink: 0 }}>
32+
<text wrap={false}>
33+
<span fg={theme.agentPrefix}>{branchChar}</span>
34+
</text>
35+
<box
36+
style={{
37+
flexDirection: 'column',
38+
gap: 0,
39+
flexShrink: 1,
40+
flexGrow: 1,
41+
}}
42+
>
43+
<box
44+
style={{
45+
flexDirection: 'row',
46+
alignSelf: 'flex-start',
47+
backgroundColor: isCollapsed
48+
? theme.agentResponseCount
49+
: theme.agentPrefix,
50+
paddingLeft: 1,
51+
paddingRight: 1,
52+
}}
53+
onMouseDown={onToggle}
54+
>
55+
<text wrap={false}>
56+
<span fg={theme.agentToggleText}>
57+
{isCollapsed ? '▸' : '▾'}{' '}
58+
</span>
59+
</text>
60+
<box style={{ flexShrink: 1 }}>
61+
<text wrap>
62+
<span
63+
fg={theme.agentToggleText}
64+
attributes={TextAttributes.BOLD}
65+
>
66+
{name}
67+
</span>
68+
</text>
69+
</box>
70+
</box>
71+
<box style={{ flexShrink: 1, marginBottom: 0 }}>
72+
{isStreaming && isCollapsed && streamingPreview && (
73+
<text
74+
wrap
75+
fg={theme.agentText}
76+
attributes={TextAttributes.ITALIC}
77+
>
78+
{streamingPreview}
79+
</text>
80+
)}
81+
{!isStreaming && isCollapsed && finishedPreview && (
82+
<text
83+
wrap
84+
fg={theme.agentResponseCount}
85+
attributes={TextAttributes.ITALIC}
86+
>
87+
{finishedPreview}
88+
</text>
89+
)}
90+
{!isCollapsed && content && (
91+
<text wrap fg={theme.agentContentText}>
92+
{content}
93+
</text>
94+
)}
95+
</box>
96+
</box>
97+
</box>
98+
)
99+
}

0 commit comments

Comments
 (0)