feat: check state and navigate to recording
This commit is contained in:
@@ -16,10 +16,11 @@ import { NotFoundPage } from '../components/dashboard/NotFound';
|
|||||||
|
|
||||||
export const PageWrapper = () => {
|
export const PageWrapper = () => {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
const [isRecordingMode, setIsRecordingMode] = useState(false);
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const { browserId, setBrowserId, notification, recordingName, setRecordingName, recordingId, setRecordingId } = useGlobalInfoStore();
|
const { browserId, setBrowserId, notification, recordingName, setRecordingName, recordingId, setRecordingId, setRecordingUrl } = useGlobalInfoStore();
|
||||||
|
|
||||||
const handleEditRecording = (recordingId: string, fileName: string) => {
|
const handleEditRecording = (recordingId: string, fileName: string) => {
|
||||||
setRecordingName(fileName);
|
setRecordingName(fileName);
|
||||||
@@ -35,23 +36,62 @@ export const PageWrapper = () => {
|
|||||||
return notification.isOpen;
|
return notification.isOpen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current tab's state from session storage
|
||||||
|
*/
|
||||||
|
const getTabState = (key: string): string | null => {
|
||||||
|
try {
|
||||||
|
const value = window.sessionStorage.getItem(key);
|
||||||
|
return value;
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const isRecordingInProgress = async () => {
|
const tabMode = getTabState('tabMode');
|
||||||
const id = await getActiveBrowserId();
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
if (id) {
|
const sessionParam = urlParams.get('session');
|
||||||
setBrowserId(id);
|
const storedSessionId = getTabState('recordingSessionId');
|
||||||
|
const storedRecordingUrl = getTabState('recordingUrl');
|
||||||
|
|
||||||
|
if (location.pathname === '/recording-setup' && sessionParam && sessionParam === storedSessionId) {
|
||||||
|
setBrowserId('new-recording');
|
||||||
|
setRecordingName('');
|
||||||
|
setRecordingId('');
|
||||||
|
|
||||||
|
if (storedRecordingUrl) {
|
||||||
|
setRecordingUrl(storedRecordingUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
navigate('/recording');
|
||||||
|
}
|
||||||
|
else if (location.pathname === '/recording' ||
|
||||||
|
(getTabState('nextTabIsRecording') === 'true' && sessionParam === storedSessionId)) {
|
||||||
|
setIsRecordingMode(true);
|
||||||
|
|
||||||
|
if (location.pathname !== '/recording') {
|
||||||
navigate('/recording');
|
navigate('/recording');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.sessionStorage.removeItem('nextTabIsRecording');
|
||||||
|
} else if (tabMode === 'main') {
|
||||||
|
console.log('Tab is in main application mode');
|
||||||
|
} else {
|
||||||
|
const id = getTabState('browserId');
|
||||||
|
if (id === 'new-recording' || location.pathname === '/recording') {
|
||||||
|
setIsRecordingMode(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
isRecordingInProgress();
|
}, [location.pathname, navigate, setBrowserId, setRecordingId, setRecordingName, setRecordingUrl]);
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<AuthProvider>
|
<AuthProvider>
|
||||||
<SocketProvider>
|
<SocketProvider>
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
{!browserId && <NavBar recordingName={recordingName} isRecording={!!browserId} />}
|
{/* {!browserId && location.pathname !== '/recording' && <NavBar recordingName={recordingName} isRecording={!!browserId} />} */}
|
||||||
|
{location.pathname !== '/recording' && <NavBar recordingName={recordingName} isRecording={false} />}
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route element={<UserRoute />}>
|
<Route element={<UserRoute />}>
|
||||||
<Route path="/" element={<Navigate to="/robots" replace />} />
|
<Route path="/" element={<Navigate to="/robots" replace />} />
|
||||||
|
|||||||
Reference in New Issue
Block a user