Skip to content

Commit

Permalink
fix: Show loading indicator while browser is starting when recording
Browse files Browse the repository at this point in the history
  • Loading branch information
e-fisher committed Oct 30, 2024
1 parent 440d032 commit 77db851
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/views/Recorder/Recorder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import TextSpinner from '@/components/TextSpinner/TextSpinner'
import { DEFAULT_GROUP_NAME } from '@/constants'
import { ButtonWithTooltip } from '@/components/ButtonWithTooltip'
import { EmptyState } from './EmptyState'
import { EmptyMessage } from '@/components/EmptyMessage'

const INITIAL_GROUPS: Group[] = [
{
Expand Down Expand Up @@ -60,8 +61,6 @@ export function Recorder() {
resetProxyData()
setRecorderState('starting')
await startRecording(url)

setRecorderState('recording')
} catch (error) {
setRecorderState('idle')
showToast({
Expand All @@ -74,6 +73,14 @@ export function Recorder() {
[resetProxyData, showToast]
)

// Set the state to 'recording' when the first data arrives.
// This allows us to show loading indicator while browser loads.
useEffect(() => {
if (recorderState === 'starting' && proxyData.length > 0) {
setRecorderState('recording')
}
}, [recorderState, proxyData.length])

const validateAndSaveHarFile = useCallback(async () => {
try {
setRecorderState('saving')
Expand Down Expand Up @@ -163,6 +170,16 @@ export function Recorder() {
})
}, [validateAndSaveHarFile, showToast, navigate])

const noDataElement = useMemo(() => {
if (recorderState === 'idle') {
return <EmptyState isLoading={isLoading} onStart={handleStartRecording} />
}

if (recorderState === 'starting') {
return <EmptyMessage message="Requests will appear here" />
}
}, [recorderState, isLoading, handleStartRecording])

return (
<View
title="Recorder"
Expand All @@ -187,14 +204,7 @@ export function Recorder() {
<div css={{ flexGrow: 0, minHeight: 0 }}>
<RequestsSection
proxyData={debouncedProxyData}
noDataElement={
recorderState === 'idle' && (
<EmptyState
isLoading={isLoading}
onStart={handleStartRecording}
/>
)
}
noDataElement={noDataElement}
selectedRequestId={selectedRequest?.id}
autoScroll
groups={groups}
Expand Down

0 comments on commit 77db851

Please sign in to comment.