Skip to content

Commit c963e25

Browse files
committed
refactor(cli): extract InputModeBanner as parent component to PendingImagesBanner
- Create new InputModeBanner component in its own file - Move usageBannerShowTime state management into InputModeBanner - Always render PendingImagesBanner alongside mode banners - Simplify ChatInputBar by removing conditional banner rendering
1 parent 0c42bbe commit c963e25

File tree

2 files changed

+38
-39
lines changed

2 files changed

+38
-39
lines changed

cli/src/components/chat-input-bar.tsx

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import React from 'react'
22

33
import { AgentModeToggle } from './agent-mode-toggle'
44
import { FeedbackContainer } from './feedback-container'
5+
import { InputModeBanner } from './input-mode-banner'
56
import { MultipleChoiceForm } from './ask-user'
67
import { MultilineInput, type MultilineInputHandle } from './multiline-input'
7-
import { PendingImagesBanner } from './pending-images-banner'
8-
import { ReferralBanner } from './referral-banner'
98
import { SuggestionMenu, type SuggestionItem } from './suggestion-menu'
10-
import { UsageBanner } from './usage-banner'
119
import { useChatStore } from '../state/chat-store'
1210
import { useAskUserBridge } from '../hooks/use-ask-user-bridge'
1311

@@ -21,23 +19,6 @@ import type { InputMode } from '../utils/input-modes'
2119

2220
type Theme = ReturnType<typeof useTheme>
2321

24-
const InputModeBanner = ({
25-
inputMode,
26-
usageBannerShowTime,
27-
}: {
28-
inputMode: InputMode
29-
usageBannerShowTime: number
30-
}) => {
31-
switch (inputMode) {
32-
case 'usage':
33-
return <UsageBanner showTime={usageBannerShowTime} />
34-
case 'referral':
35-
return <ReferralBanner />
36-
default:
37-
return null
38-
}
39-
}
40-
4122
interface ChatInputBarProps {
4223
// Input state
4324
inputValue: string
@@ -110,17 +91,6 @@ export const ChatInputBar = ({
11091
}: ChatInputBarProps) => {
11192
const inputMode = useChatStore((state) => state.inputMode)
11293
const setInputMode = useChatStore((state) => state.setInputMode)
113-
const hasPendingImages = useChatStore((state) => state.pendingImages.length > 0)
114-
115-
const [usageBannerShowTime, setUsageBannerShowTime] = React.useState(() =>
116-
Date.now(),
117-
)
118-
119-
React.useEffect(() => {
120-
if (inputMode === 'usage') {
121-
setUsageBannerShowTime(Date.now())
122-
}
123-
}, [inputMode])
12494

12595
const modeConfig = getInputModeConfig(inputMode)
12696
const askUserState = useChatStore((state) => state.askUserState)
@@ -391,14 +361,7 @@ export const ChatInputBar = ({
391361
</box>
392362
</box>
393363
</box>
394-
{hasPendingImages ? (
395-
<PendingImagesBanner />
396-
) : (
397-
<InputModeBanner
398-
inputMode={inputMode}
399-
usageBannerShowTime={usageBannerShowTime}
400-
/>
401-
)}
364+
<InputModeBanner />
402365
</>
403366
)
404367
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react'
2+
3+
import { PendingImagesBanner } from './pending-images-banner'
4+
import { ReferralBanner } from './referral-banner'
5+
import { UsageBanner } from './usage-banner'
6+
import { useChatStore } from '../state/chat-store'
7+
8+
/**
9+
* Banner component that shows contextual information below the input box.
10+
* Shows mode-specific banners based on the current input mode.
11+
*/
12+
export const InputModeBanner = () => {
13+
const inputMode = useChatStore((state) => state.inputMode)
14+
15+
const [usageBannerShowTime, setUsageBannerShowTime] = React.useState(() =>
16+
Date.now(),
17+
)
18+
19+
React.useEffect(() => {
20+
if (inputMode === 'usage') {
21+
setUsageBannerShowTime(Date.now())
22+
}
23+
}, [inputMode])
24+
25+
switch (inputMode) {
26+
case 'default':
27+
case 'image':
28+
return <PendingImagesBanner />
29+
case 'usage':
30+
return <UsageBanner showTime={usageBannerShowTime} />
31+
case 'referral':
32+
return <ReferralBanner />
33+
default:
34+
return null
35+
}
36+
}

0 commit comments

Comments
 (0)