Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Show loading indicator while browser is starting when recording #289

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading