Skip to content

Commit

Permalink
fix(ui): stop button display after loading (#2427)
Browse files Browse the repository at this point in the history
* fix(ui): stop button display after loading

* decrease delay time of show stop

* update
  • Loading branch information
wwayne authored Jun 17, 2024
1 parent 22318d9 commit 92c55c3
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions ee/tabby-ui/app/(home)/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import remarkGfm from 'remark-gfm'
import remarkMath from 'remark-math'

import { useEnableSearch } from '@/lib/experiment-flags'
import { useLatest } from '@/lib/hooks/use-latest'
import { useIsChatEnabled } from '@/lib/hooks/use-server-info'
import { useTabbyAnswer } from '@/lib/hooks/use-tabby-answer'
import fetcher from '@/lib/tabby/fetcher'
Expand Down Expand Up @@ -113,6 +114,8 @@ export function SearchRenderer({}, ref: ForwardedRef<SearchRef>) {
fetcher: tabbyFetcher
})

const isLoadingRef = useLatest(isLoading)

useImperativeHandle(
ref,
() => {
Expand Down Expand Up @@ -171,9 +174,11 @@ export function SearchRenderer({}, ref: ForwardedRef<SearchRef>) {
}, [error])

// Delay showing the stop button
let showStopTimeoutId: number
useEffect(() => {
if (isLoading) {
setTimeout(() => {
if (isLoadingRef.current) {
showStopTimeoutId = window.setTimeout(() => {
if (!isLoadingRef.current) return
setShowStop(true)

// Scroll to the bottom
Expand All @@ -187,12 +192,16 @@ export function SearchRenderer({}, ref: ForwardedRef<SearchRef>) {
})
}
}
}, 1500)
}, 300)
}

if (!isLoading) {
if (!isLoadingRef.current) {
setShowStop(false)
}

return () => {
window.clearTimeout(showStopTimeoutId)
}
}, [isLoading])

const onSubmitSearch = (question: string) => {
Expand Down

0 comments on commit 92c55c3

Please sign in to comment.