Skip to content

Commit

Permalink
Bypass UploadScreen if the user has no workspaces (#10532)
Browse files Browse the repository at this point in the history
  • Loading branch information
hbenl authored May 15, 2024
1 parent 5e6cbbd commit aeea3bd
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions pages/upload.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -12,15 +13,44 @@ 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) {
window.onbeforeunload = null;
}
});

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 <LoadingScreen message="Loading..." />;
}

Expand Down

0 comments on commit aeea3bd

Please sign in to comment.