diff --git a/src/components/App/SideBar/AiSearch/index.tsx b/src/components/App/SideBar/AiSearch/index.tsx index 1a58a8290..a5dd99cb7 100644 --- a/src/components/App/SideBar/AiSearch/index.tsx +++ b/src/components/App/SideBar/AiSearch/index.tsx @@ -6,6 +6,8 @@ import { Flex } from '~/components/common/Flex' import { useDataStore } from '~/stores/useDataStore' import { useUserStore } from '~/stores/useUserStore' import { colors } from '~/utils' +import { useHasAiChatsResponse } from '~/stores/useAiSummaryStore' +import { ClipLoader } from 'react-spinners' export const AiSearch = () => { const form = useForm<{ search: string }>({ mode: 'onChange' }) @@ -13,6 +15,8 @@ export const AiSearch = () => { const { setBudget } = useUserStore((s) => s) const { reset } = form + const isLoading = useHasAiChatsResponse() + const handleSubmit = form.handleSubmit(({ search }) => { if (search.trim() === '') { return @@ -26,14 +30,18 @@ export const AiSearch = () => { - + { + if (isLoading) { + return + } + handleSubmit() }} > - + {!isLoading ? : } diff --git a/src/components/SearchBar/index.tsx b/src/components/SearchBar/index.tsx index 086ea7e45..317204140 100644 --- a/src/components/SearchBar/index.tsx +++ b/src/components/SearchBar/index.tsx @@ -70,7 +70,6 @@ export const SearchBar = ({ loading, placeholder = 'Search', onSubmit }: Props) {...register('search')} disabled={loading} id="main-search" - loading={loading} onKeyPress={(event) => { if (event.key === 'Enter') { if (typing.trim() === '') { diff --git a/src/stores/useAiSummaryStore/index.ts b/src/stores/useAiSummaryStore/index.ts index 7d2a583df..566e77171 100644 --- a/src/stores/useAiSummaryStore/index.ts +++ b/src/stores/useAiSummaryStore/index.ts @@ -56,3 +56,10 @@ export const useAiSummaryStore = create()( ) export const useHasAiChats = () => useAiSummaryStore((s) => !isEmpty(s.aiSummaryAnswers)) + +export const useHasAiChatsResponse = () => + useAiSummaryStore((s) => { + const answers = s.aiSummaryAnswers + + return Object.values(answers).at(-1)?.answerLoading + })