import React, { useContext, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Paper, Grid, CircularProgress, Box, Alert, Typography, useTheme, AlertTitle, } from '@mui/material'; import { useParams } from 'react-router-dom'; import Onboarding from './Onboarding'; import Welcome from './Welcome'; import RobotProfile from './RobotProfile'; import { TorIcon } from '../../components/Icons'; import { AppContext, type UseAppStoreType } from '../../contexts/AppContext'; import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext'; import RecoveryDialog from '../../components/Dialogs/Recovery'; const RobotPage = (): React.JSX.Element => { const { torStatus, windowSize, settings, page, client } = useContext(AppContext); const { garage, slotUpdatedAt } = useContext(GarageContext); const { t } = useTranslation(); const params = useParams(); const urlToken = settings.selfhostedClient ? params.token : null; const width = Math.min(windowSize.width * 0.8, 28); const maxHeight = windowSize.height * 0.85 - 3; const theme = useTheme(); const [inputToken, setInputToken] = useState(''); const [view, setView] = useState<'welcome' | 'onboarding' | 'profile'>( garage.currentSlot !== null ? 'profile' : 'welcome', ); useEffect(() => { const token = urlToken ?? garage.currentSlot; if (token !== undefined && token !== null && page === 'garage') { setInputToken(token.replace(/\s+/g, '')); } }, [torStatus, page, slotUpdatedAt]); if (settings.useProxy && client === 'mobile' && !(torStatus === 'ON')) { return ( {t('Connecting to Tor')} {t('Connection encrypted and anonymized using Tor.')} {t( 'This ensures maximum privacy, however you might feel the app behaves slow. If connection is lost, restart the app.', )} ); } else { return ( {view === 'welcome' ? ( ) : null} {view === 'onboarding' ? ( ) : null} {view === 'profile' ? ( ) : null} ); } }; export default RobotPage;