diff --git a/pages/upload.tsx b/pages/upload.tsx index 9e8ba060e48..d9b174a2ed1 100644 --- a/pages/upload.tsx +++ b/pages/upload.tsx @@ -1,9 +1,10 @@ -import React, { useEffect } from "react"; +import React, { useEffect, useState } from "react"; +import { RecordingTarget, getRecordingTarget } from "replay-next/src/suspense/BuildIdCache"; import LoadingScreen from "ui/components/shared/LoadingScreen"; import { BlankViewportWrapper } from "ui/components/shared/Viewport"; import UploadScreen from "ui/components/UploadScreen"; -import { useGetRecording, useGetRecordingId } from "ui/hooks/recordings"; +import { useGetRecording, useGetRecordingId, useInitializeRecording } from "ui/hooks/recordings"; import { useGetUserSettings } from "ui/hooks/settings"; import { useGetNonPendingWorkspaces } from "ui/hooks/workspaces"; @@ -12,7 +13,9 @@ function UploadScreenWrapper({ onUpload }: { onUpload: () => void }) { const { recording } = useGetRecording(recordingId); // Make sure to get the user's settings and workspaces before showing the upload screen. const { userSettings, loading: userSettingsLoading } = useGetUserSettings(); - const { workspaces, loading: pendingWorkspacesLoading } = useGetNonPendingWorkspaces(); + const { workspaces, loading: workspacesLoading } = useGetNonPendingWorkspaces(); + const initializeRecording = useInitializeRecording(); + const [initializing, setInitializing] = useState(false); useEffect(() => { if (recording?.isInitialized) { @@ -20,7 +23,34 @@ function UploadScreenWrapper({ onUpload }: { onUpload: () => void }) { } }); - if (userSettingsLoading || pendingWorkspacesLoading) { + useEffect(() => { + async function initialize() { + await initializeRecording({ + variables: { recordingId, title: recording?.title || "Untitled", workspaceId: null }, + }); + onUpload(); + } + if ( + recording?.isInitialized === false && + !initializing && + !workspacesLoading && + workspaces.length === 0 && + getRecordingTarget(recording.buildId ?? "unknown") !== RecordingTarget.gecko + ) { + setInitializing(true); + initialize(); + } + }, [ + initializeRecording, + initializing, + onUpload, + recording, + recordingId, + workspacesLoading, + workspaces, + ]); + + if (userSettingsLoading || workspacesLoading || initializing) { return ; }