Skip to content

Commit b740076

Browse files
committed
refactor: consolidate duplicate JSX in ternary expressions
Simplifies ternary expressions by extracting duplicate JSX elements and consolidating conditional logic.
1 parent c75b8df commit b740076

File tree

3 files changed

+19
-31
lines changed

3 files changed

+19
-31
lines changed

cli/src/chat.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,21 +1207,21 @@ export const App = ({
12071207
}}
12081208
>
12091209
<text wrap={false}>
1210-
{hasStatus ? statusIndicatorNode : null}
1211-
{hasStatus && (exitWarning || shouldShowQueuePreview) ? ' ' : ''}
1212-
{exitWarning ? (
1210+
{hasStatus && statusIndicatorNode}
1211+
{hasStatus && (exitWarning || shouldShowQueuePreview) && ' '}
1212+
{exitWarning && (
12131213
<span fg={theme.statusSecondary}>{exitWarning}</span>
1214-
) : null}
1215-
{exitWarning && shouldShowQueuePreview ? ' ' : ''}
1216-
{shouldShowQueuePreview ? (
1214+
)}
1215+
{exitWarning && shouldShowQueuePreview && ' '}
1216+
{shouldShowQueuePreview && (
12171217
<span fg={theme.statusSecondary} bg={theme.inputFocusedBg}>
12181218
{' '}
12191219
{formatQueuedPreview(
12201220
queuedMessages,
12211221
Math.max(30, terminalWidth - 25),
12221222
)}{' '}
12231223
</span>
1224-
) : null}
1224+
)}
12251225
</text>
12261226
</box>
12271227
)}

cli/src/components/branch-item.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,24 +170,14 @@ export const BranchItem = ({
170170
</text>
171171
</box>
172172
<box style={{ flexShrink: 1, marginBottom: 0 }}>
173-
{isStreaming && isCollapsed && streamingPreview && (
173+
{isCollapsed && (isStreaming ? streamingPreview : finishedPreview) && (
174174
<text
175-
key="streaming-preview"
175+
key={isStreaming ? 'streaming-preview' : 'finished-preview'}
176176
wrap
177-
fg={theme.agentText}
177+
fg={isStreaming ? theme.agentText : theme.agentResponseCount}
178178
attributes={TextAttributes.ITALIC}
179179
>
180-
{streamingPreview}
181-
</text>
182-
)}
183-
{!isStreaming && isCollapsed && finishedPreview && (
184-
<text
185-
key="finished-preview"
186-
wrap
187-
fg={theme.agentResponseCount}
188-
attributes={TextAttributes.ITALIC}
189-
>
190-
{finishedPreview}
180+
{isStreaming ? streamingPreview : finishedPreview}
191181
</text>
192182
)}
193183
{!isCollapsed && (

cli/src/components/terminal-link.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,6 @@ export const TerminalLink: React.FC<TerminalLinkProps> = ({
5555
return <span fg={displayColor}>{text}</span>
5656
}
5757

58-
const renderLine = (line: string, index: number) => {
59-
const coloredText = <span fg={displayColor}>{line}</span>
60-
return (
61-
<text key={index} wrap={lineWrap}>
62-
{shouldUnderline ? <u>{coloredText}</u> : coloredText}
63-
</text>
64-
)
65-
}
66-
6758
return (
6859
<box
6960
style={{
@@ -77,7 +68,14 @@ export const TerminalLink: React.FC<TerminalLinkProps> = ({
7768
onMouseOut={() => setIsHovered(false)}
7869
onMouseDown={handleActivate}
7970
>
80-
{displayLines.map(renderLine)}
71+
{displayLines.map((line: string, index: number) => {
72+
const coloredText = <span fg={displayColor}>{line}</span>
73+
return (
74+
<text key={index} wrap={lineWrap}>
75+
{shouldUnderline ? <u>{coloredText}</u> : coloredText}
76+
</text>
77+
)
78+
})}
8179
</box>
8280
)
8381
}

0 commit comments

Comments
 (0)