Skip to content

Commit fba5e79

Browse files
committed
Let you change setting for pause/spend credits for when subscription runs out
1 parent a52d403 commit fba5e79

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

cli/src/chat.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,8 +1254,9 @@ export const Chat = ({
12541254

12551255
// Auto-show subscription limit banner when rate limit becomes active
12561256
const subscriptionLimitShownRef = useRef(false)
1257+
const subscriptionRateLimit = subscriptionData?.hasSubscription ? subscriptionData.rateLimit : undefined
12571258
useEffect(() => {
1258-
const isLimited = subscriptionData?.rateLimit?.limited === true
1259+
const isLimited = subscriptionRateLimit?.limited === true
12591260
if (isLimited && !subscriptionLimitShownRef.current) {
12601261
subscriptionLimitShownRef.current = true
12611262
// Skip showing the banner if user prefers to always fall back to a-la-carte
@@ -1268,7 +1269,7 @@ export const Chat = ({
12681269
useChatStore.getState().setInputMode('default')
12691270
}
12701271
}
1271-
}, [subscriptionData?.rateLimit?.limited])
1272+
}, [subscriptionRateLimit?.limited])
12721273

12731274
const inputBoxTitle = useMemo(() => {
12741275
const segments: string[] = []

cli/src/components/usage-banner.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isClaudeOAuthValid } from '@codebuff/sdk'
22
import open from 'open'
3-
import React, { useEffect, useMemo } from 'react'
3+
import React, { useEffect, useMemo, useState } from 'react'
44

55
import { BottomBanner } from './bottom-banner'
66
import { Button } from './button'
@@ -11,6 +11,7 @@ import { useSubscriptionQuery } from '../hooks/use-subscription-query'
1111
import { useTheme } from '../hooks/use-theme'
1212
import { usageQueryKeys, useUsageQuery } from '../hooks/use-usage-query'
1313
import { WEBSITE_URL } from '../login/constants'
14+
import { getAlwaysUseALaCarte, setAlwaysUseALaCarte } from '../utils/settings'
1415
import { useChatStore } from '../state/chat-store'
1516
import { formatResetTime, formatResetTimeLong } from '../utils/time-format'
1617
import {
@@ -216,6 +217,13 @@ const SubscriptionUsageSection: React.FC<SubscriptionUsageSectionProps> = ({
216217
isLoading,
217218
}) => {
218219
const theme = useTheme()
220+
const [useALaCarte, setUseALaCarte] = useState(() => getAlwaysUseALaCarte())
221+
222+
const handleToggleALaCarte = () => {
223+
const newValue = !useALaCarte
224+
setUseALaCarte(newValue)
225+
setAlwaysUseALaCarte(newValue)
226+
}
219227

220228
const blockPercent = useMemo(() => {
221229
if (rateLimit?.blockLimit == null || rateLimit.blockUsed == null) return 100
@@ -258,6 +266,17 @@ const SubscriptionUsageSection: React.FC<SubscriptionUsageSectionProps> = ({
258266
</box>
259267
</box>
260268
) : null}
269+
<box style={{ flexDirection: 'row', alignItems: 'center', gap: 1, marginTop: 1 }}>
270+
<text style={{ fg: theme.muted }}>When limit reached:</text>
271+
<text style={{ fg: theme.muted }}>
272+
{useALaCarte ? 'spend credits' : 'pause'}
273+
</text>
274+
<Button onClick={handleToggleALaCarte}>
275+
<text style={{ fg: theme.muted }}>
276+
[{useALaCarte ? 'switch to pause' : 'switch to spend credits'}]
277+
</text>
278+
</Button>
279+
</box>
261280
</box>
262281
)
263282
}

0 commit comments

Comments
 (0)