From 845c453bc50958e45600d1646c453c4a30ab9d72 Mon Sep 17 00:00:00 2001 From: MahtabBukhari Date: Thu, 18 Jul 2024 18:17:12 +0500 Subject: [PATCH 1/2] fix(follow-up): update changes in follow-up search bar --- src/components/App/SideBar/AiSearch/index.tsx | 16 ++++++++++++++-- src/components/SearchBar/index.tsx | 1 - src/stores/useAiSummaryStore/index.ts | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/components/App/SideBar/AiSearch/index.tsx b/src/components/App/SideBar/AiSearch/index.tsx index 69cdf6f8f..1638d8f2e 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,7 +15,13 @@ export const AiSearch = () => { const { setBudget } = useUserStore((s) => s) const { reset } = form + const isLoading = useHasAiChatsResponse() + const handleSubmit = form.handleSubmit(({ search }) => { + if (search.trim() === '') { + return + } + fetchData(setBudget, setAbortRequests, search) reset({ search: '' }) }) @@ -22,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..a1363a85d 100644 --- a/src/stores/useAiSummaryStore/index.ts +++ b/src/stores/useAiSummaryStore/index.ts @@ -56,3 +56,21 @@ export const useAiSummaryStore = create()( ) export const useHasAiChats = () => useAiSummaryStore((s) => !isEmpty(s.aiSummaryAnswers)) + +export const useHasAiChatsResponse = () => + useAiSummaryStore((s) => { + const answers = s.aiSummaryAnswers + + if (isEmpty(answers)) { + return false + } + + const allKeys = Object.keys(answers) + const hasAnswers = allKeys.every((key) => !!answers[key]?.answer) + + if (!hasAnswers) { + return false + } + + return true + }) From 514bdc333e284dfd9831790a18c0f8be87a2e105 Mon Sep 17 00:00:00 2001 From: MahtabBukhari Date: Fri, 19 Jul 2024 06:05:37 +0500 Subject: [PATCH 2/2] fix(update-follow-up): fixed ask follow-up search --- src/components/App/SideBar/AiSearch/index.tsx | 6 +++--- src/stores/useAiSummaryStore/index.ts | 13 +------------ 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/components/App/SideBar/AiSearch/index.tsx b/src/components/App/SideBar/AiSearch/index.tsx index 1638d8f2e..a5dd99cb7 100644 --- a/src/components/App/SideBar/AiSearch/index.tsx +++ b/src/components/App/SideBar/AiSearch/index.tsx @@ -30,18 +30,18 @@ export const AiSearch = () => { - + { - if (!isLoading) { + if (isLoading) { return } handleSubmit() }} > - {isLoading ? : } + {!isLoading ? : } diff --git a/src/stores/useAiSummaryStore/index.ts b/src/stores/useAiSummaryStore/index.ts index a1363a85d..566e77171 100644 --- a/src/stores/useAiSummaryStore/index.ts +++ b/src/stores/useAiSummaryStore/index.ts @@ -61,16 +61,5 @@ export const useHasAiChatsResponse = () => useAiSummaryStore((s) => { const answers = s.aiSummaryAnswers - if (isEmpty(answers)) { - return false - } - - const allKeys = Object.keys(answers) - const hasAnswers = allKeys.every((key) => !!answers[key]?.answer) - - if (!hasAnswers) { - return false - } - - return true + return Object.values(answers).at(-1)?.answerLoading })