ui: prevent topic clicks when rate limited in kai

This commit is contained in:
nick-delirium 2025-05-30 17:13:36 +02:00
parent 66b3708cce
commit 6129b088f1
No known key found for this signature in database
GPG key ID: 93ABD695DF5FDBA0
3 changed files with 21 additions and 7 deletions

View file

@ -19,6 +19,7 @@ function KaiChat() {
const setTitle = kaiStore.setTitle; const setTitle = kaiStore.setTitle;
const userId = userStore.account.id; const userId = userStore.account.id;
const userName = userStore.account.name; const userName = userStore.account.name;
const limited = kaiStore.usage.percent >= 100;
const { activeSiteId } = projectsStore; const { activeSiteId } = projectsStore;
const [section, setSection] = React.useState<'intro' | 'chat'>('intro'); const [section, setSection] = React.useState<'intro' | 'chat'>('intro');
const [threadId, setThreadId] = React.useState<string | null>(null); const [threadId, setThreadId] = React.useState<string | null>(null);
@ -148,6 +149,7 @@ function KaiChat() {
onAsk={onCreate} onAsk={onCreate}
projectId={activeSiteId} projectId={activeSiteId}
userName={userName} userName={userName}
limited={limited}
/> />
</div> </div>
<div <div

View file

@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { Lightbulb, MoveRight } from 'lucide-react'; import cn from 'classnames';
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import { kaiService } from 'App/services'; import { kaiService } from 'App/services';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@ -9,11 +9,13 @@ function Ideas({
projectId, projectId,
threadId = null, threadId = null,
inChat, inChat,
limited,
}: { }: {
onClick: (query: string) => void; onClick: (query: string) => void;
projectId: string; projectId: string;
threadId?: string | null; threadId?: string | null;
inChat?: boolean; inChat?: boolean;
limited?: boolean;
}) { }) {
const { t } = useTranslation(); const { t } = useTranslation();
const { data: suggestedPromptIdeas = [], isPending } = useQuery({ const { data: suggestedPromptIdeas = [], isPending } = useQuery({
@ -46,7 +48,12 @@ function Ideas({
) : ( ) : (
<div className="flex gap-2 flex-wrap"> <div className="flex gap-2 flex-wrap">
{ideas.map((title) => ( {ideas.map((title) => (
<IdeaItem key={title} onClick={onClick} title={title} /> <IdeaItem
limited={limited}
key={title}
onClick={onClick}
title={title}
/>
))} ))}
</div> </div>
)} )}
@ -57,16 +64,19 @@ function Ideas({
function IdeaItem({ function IdeaItem({
title, title,
onClick, onClick,
limited,
}: { }: {
title: string; title: string;
onClick: (query: string) => void; onClick: (query: string) => void;
limited?: boolean;
}) { }) {
return ( return (
<div <div
onClick={() => onClick(title)} onClick={() => (limited ? null : onClick(title))}
className={ className={cn(
'cursor-pointer text-gray-dark hover:text-black rounded-full px-4 py-2 shadow border' 'cursor-pointer text-gray-dark hover:text-black rounded-full px-4 py-2 shadow border',
} limited ? 'bg-gray-lightest cursor-not-allowed' : 'bg-white',
)}
> >
{title} {title}
</div> </div>

View file

@ -7,11 +7,13 @@ function IntroSection({
onCancel, onCancel,
userName, userName,
projectId, projectId,
limited,
}: { }: {
onAsk: (query: string) => void; onAsk: (query: string) => void;
projectId: string; projectId: string;
onCancel: () => void; onCancel: () => void;
userName: string; userName: string;
limited?: boolean;
}) { }) {
const isLoading = false; const isLoading = false;
return ( return (
@ -27,7 +29,7 @@ function IntroSection({
isArea isArea
/> />
<div className={'absolute top-full flex flex-col gap-2 mt-4'}> <div className={'absolute top-full flex flex-col gap-2 mt-4'}>
<Ideas onClick={(query) => onAsk(query)} projectId={projectId} /> <Ideas limited={limited} onClick={(query) => onAsk(query)} projectId={projectId} />
</div> </div>
</div> </div>
</> </>