Skip to content

Commit

Permalink
Merge pull request #1863 from MahtabBukhari/follow_up_search_bar
Browse files Browse the repository at this point in the history
update changes in follow-up search bar
  • Loading branch information
Rassl authored Jul 23, 2024
2 parents 26bc539 + 56d10c4 commit aaad39d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/components/App/SideBar/AiSearch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ 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' })
const { fetchData, setAbortRequests } = useDataStore((s) => s)
const { setBudget } = useUserStore((s) => s)
const { reset } = form

const isLoading = useHasAiChatsResponse()

const handleSubmit = form.handleSubmit(({ search }) => {
if (search.trim() === '') {
return
Expand All @@ -26,14 +30,18 @@ export const AiSearch = () => {
<AiSearchWrapper>
<FormProvider {...form}>
<Search>
<SearchBar onSubmit={handleSubmit} placeholder="Ask follow-up" />
<SearchBar loading={isLoading} onSubmit={handleSubmit} placeholder="Ask follow-up" />
<InputButton
data-testid="search-ai_action_icon"
onClick={() => {
if (isLoading) {
return
}

handleSubmit()
}}
>
<SearchIcon />
{!isLoading ? <SearchIcon /> : <ClipLoader color={colors.lightGray} data-testid="loader" size="20" />}
</InputButton>
</Search>
</FormProvider>
Expand Down
1 change: 0 additions & 1 deletion src/components/SearchBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() === '') {
Expand Down
7 changes: 7 additions & 0 deletions src/stores/useAiSummaryStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ export const useAiSummaryStore = create<AiSummaryStore>()(
)

export const useHasAiChats = () => useAiSummaryStore((s) => !isEmpty(s.aiSummaryAnswers))

export const useHasAiChatsResponse = () =>
useAiSummaryStore((s) => {
const answers = s.aiSummaryAnswers

return Object.values(answers).at(-1)?.answerLoading
})

0 comments on commit aaad39d

Please sign in to comment.