Skip to content

Commit

Permalink
streaming response stash
Browse files Browse the repository at this point in the history
  • Loading branch information
saifullah-talukder committed Jun 20, 2024
1 parent 0e70001 commit 001a497
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions frontend/src/components/search/search-input.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use client'

import { maxSearchInputHeight } from '@/constants/style'
import { useSearchStore } from '@/stores/search/search-store'
import classNames from 'classnames'
import { ChangeEvent, HTMLAttributes, KeyboardEvent, useRef } from 'react'
import PaperPlaneIcon from '../icons/paper-plane'
Expand All @@ -10,18 +9,15 @@ import { Textarea } from '../lib/form'

type SearchInputProps = HTMLAttributes<HTMLDivElement> & {
handleSearch: () => void
searchQuery: string
setSearchQuery: (query: string) => void
}

export default function SearchInput(props: SearchInputProps) {
const textAreaRef = useRef<HTMLTextAreaElement | null>(null)

const {
state: { searchQuery },
setSearchState,
} = useSearchStore()

const handleChange = (event: ChangeEvent<HTMLTextAreaElement>) => {
setSearchState('searchQuery', event.target.value)
props.setSearchQuery(event.target.value)

const target = event.target as HTMLTextAreaElement
if (textAreaRef?.current?.style) {
Expand All @@ -31,7 +27,7 @@ export default function SearchInput(props: SearchInputProps) {
}

const handleSubmit = () => {
if (searchQuery.length > 0) {
if (props.searchQuery.length > 0) {
props.handleSearch()
}
}
Expand All @@ -56,22 +52,22 @@ export default function SearchInput(props: SearchInputProps) {
className={classNames(
'h-16 pl-6 pr-16 rounded-2xl border-none focus-visible:ring-0 bg-background-light/80 dark:bg-background-dark/80 text-typography-light dark:text-typography-dark placeholder:text-typography-light/40 dark:placeholder:text-typography-dark/40 text-sm xl:text-base',
{
'py-5': textAreaRef?.current?.style.height !== `${maxSearchInputHeight}px` || searchQuery.length === 0,
'py-5': textAreaRef?.current?.style.height !== `${maxSearchInputHeight}px` || props.searchQuery.length === 0,
'py-3': textAreaRef?.current?.style.height === `${maxSearchInputHeight}px`,
}
)}
placeholder="What can I do for you today?"
value={searchQuery}
value={props.searchQuery}
onChange={handleChange}
onKeyDown={handleKeyDown}
button={
<IconButton
className={classNames(
'absolute right-6 h-10 w-12 border border-background-dark/30 dark:border-background-light/30 transition-all duration-700 rounded-[10px]',
{
'cursor-auto': searchQuery.length === 0,
'bg-primary/75': searchQuery.length !== 0,
'top-6': textAreaRef?.current?.style.height === '64px' || searchQuery.length === 0,
'cursor-auto': props.searchQuery.length === 0,
'bg-primary/75': props.searchQuery.length !== 0,
'top-6': textAreaRef?.current?.style.height === '64px' || props.searchQuery.length === 0,
'bottom-5': textAreaRef?.current?.style.height !== '64px',
'right-8': textAreaRef?.current?.style.height === `${maxSearchInputHeight}px`,
}
Expand Down

0 comments on commit 001a497

Please sign in to comment.