Skip to content

Commit

Permalink
Merge pull request #1526 from RoboSats/better-robot-recovery-tool
Browse files Browse the repository at this point in the history
Better Robot recovery tool
  • Loading branch information
KoalaSat authored Oct 18, 2024
2 parents 7bf1d51 + a79d3c2 commit 25f45be
Show file tree
Hide file tree
Showing 36 changed files with 758 additions and 756 deletions.
4 changes: 2 additions & 2 deletions desktopApp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ function createWindow(): void {
});

// Load the index.html file from the app directory
mainWindow.loadURL(`file://${path.resolve(__dirname, 'index.html#/robot')}`, {
mainWindow.loadURL(`file://${path.resolve(__dirname, 'index.html#/garage')}`, {
extraHeaders: "pragma: no-cache\n" // Prevent caching of the loaded file
});

// Handle failed load attempts by reloading the file
mainWindow.webContents.on("did-fail-load", () => {
console.log("Failed to load the page, retrying...");
mainWindow.loadURL(`file://${__dirname}/index.html#/robot`);
mainWindow.loadURL(`file://${__dirname}/index.html#/garage`);
});

// Uncomment the following line to open the DevTools
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/basic/BookPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const BookPage = (): JSX.Element => {
setOpenNoRobot(false);
}}
onClickGenerateRobot={() => {
navigate('/robot');
navigate('/garage');
}}
/>
{openMaker ? (
Expand All @@ -99,7 +99,7 @@ const BookPage = (): JSX.Element => {
<Box sx={{ maxWidth: '18em', padding: '0.5em' }}>
<MakerForm
onClickGenerateRobot={() => {
navigate('/robot');
navigate('/garage');
}}
/>
</Box>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/basic/MainDialogs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface OpenDialogs {
client: boolean;
update: boolean;
profile: boolean;
recovery: boolean;
}

const MainDialogs = (): JSX.Element => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/basic/MakerPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const MakerPage = (): JSX.Element => {
setOpenNoRobot(false);
}}
onClickGenerateRobot={() => {
navigate('/robot');
navigate('/garage');
}}
/>
<Grid item>
Expand Down Expand Up @@ -112,7 +112,7 @@ const MakerPage = (): JSX.Element => {
}}
submitButtonLabel={matches.length > 0 && !showMatches ? 'Submit' : 'Create order'}
onClickGenerateRobot={() => {
navigate('/robot');
navigate('/garage');
}}
/>
</Paper>
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/basic/NavBar/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ const NavBar = (): JSX.Element => {
// change tab (page) into the current route
const pathPage: Page | string = location.pathname.split('/')[1];
if (pathPage === 'index.html') {
navigate('/robot');
setPage('robot');
navigate('/garage');
setPage('garage');
}
if (isPage(pathPage)) {
setPage(pathPage);
Expand Down Expand Up @@ -113,7 +113,7 @@ const NavBar = (): JSX.Element => {
<Tab
sx={{ ...tabSx, minWidth: '2.5em', width: '2.5em', maxWidth: '4em' }}
value='none'
disabled={slot?.nickname === null}
disabled={!slot?.nickname}
onClick={() => {
setOpen({ ...closeAll, profile: !open.profile });
}}
Expand All @@ -131,9 +131,9 @@ const NavBar = (): JSX.Element => {
/>

<Tab
label={smallBar ? undefined : t('Robot')}
label={smallBar ? undefined : t('Garage')}
sx={{ ...tabSx, minWidth: '1em' }}
value='robot'
value='garage'
icon={<SmartToy />}
iconPosition='start'
/>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/basic/NavBar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import NavBar from './NavBar';

export type Page = 'robot' | 'order' | 'create' | 'offers' | 'settings' | 'none';
export type Page = 'garage' | 'order' | 'create' | 'offers' | 'settings' | 'none';
export default NavBar;

export function isPage(page: string): page is Page {
return ['robot', 'order', 'create', 'offers', 'settings', 'none'].includes(page);
return ['garage', 'order', 'create', 'offers', 'settings', 'none'].includes(page);
}
4 changes: 2 additions & 2 deletions frontend/src/basic/OrderPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const OrderPage = (): JSX.Element => {
};

const startAgain = (): void => {
navigate('/robot');
navigate('/garage');
};

const orderDetailsSpace = currentOrder ? (
Expand All @@ -78,7 +78,7 @@ const OrderPage = (): JSX.Element => {
currentOrder={currentOrder}
onClickCoordinator={onClickCoordinator}
onClickGenerateRobot={() => {
navigate('/robot');
navigate('/garage');
}}
/>
) : (
Expand Down
15 changes: 4 additions & 11 deletions frontend/src/basic/RobotPage/Onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,24 @@ import { genBase62Token } from '../../utils';
import { NewTabIcon } from '../../components/Icons';
import { AppContext, type UseAppStoreType } from '../../contexts/AppContext';
import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext';
import { UseFederationStoreType, FederationContext } from '../../contexts/FederationContext';

interface OnboardingProps {
setView: (state: 'welcome' | 'onboarding' | 'recovery' | 'profile') => void;
robot: Robot;
setRobot: (state: Robot) => void;
inputToken: string;
setInputToken: (state: string) => void;
getGenerateRobot: (token: string) => void;
badToken: string;
baseUrl: string;
}

const Onboarding = ({
setView,
inputToken,
setInputToken,
badToken,
getGenerateRobot,
}: OnboardingProps): JSX.Element => {
const Onboarding = ({ setView, inputToken, setInputToken }: OnboardingProps): JSX.Element => {
const { t } = useTranslation();
const navigate = useNavigate();

const { setPage } = useContext<UseAppStoreType>(AppContext);
const { garage } = useContext<UseGarageStoreType>(GarageContext);
const { federation } = useContext<UseFederationStoreType>(FederationContext);

const [step, setStep] = useState<'1' | '2' | '3'>('1');
const [generatedToken, setGeneratedToken] = useState<boolean>(false);
Expand Down Expand Up @@ -105,7 +99,6 @@ const Onboarding = ({
autoFocusTarget='copyButton'
inputToken={inputToken}
setInputToken={setInputToken}
badToken={badToken}
onPressEnter={() => null}
/>
</Grid>
Expand All @@ -123,7 +116,7 @@ const Onboarding = ({
<Button
onClick={() => {
setStep('2');
getGenerateRobot(inputToken);
garage.createRobot(federation, inputToken);
}}
variant='contained'
size='large'
Expand Down
66 changes: 0 additions & 66 deletions frontend/src/basic/RobotPage/Recovery.tsx

This file was deleted.

61 changes: 28 additions & 33 deletions frontend/src/basic/RobotPage/RobotProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,36 @@ import {
MenuItem,
Box,
useTheme,
Tooltip,
type SelectChangeEvent,
} from '@mui/material';
import { Bolt, Add, DeleteSweep, Logout, Download } from '@mui/icons-material';
import { Key } from '@mui/icons-material';
import { Bolt, Add, DeleteSweep, Download } from '@mui/icons-material';
import RobotAvatar from '../../components/RobotAvatar';
import TokenInput from './TokenInput';
import { type Slot, type Robot } from '../../models';
import { AppContext, type UseAppStoreType } from '../../contexts/AppContext';
import { genBase62Token } from '../../utils';
import { LoadingButton } from '@mui/lab';
import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext';
import { FederationContext, UseFederationStoreType } from '../../contexts/FederationContext';
import { UseFederationStoreType, FederationContext } from '../../contexts/FederationContext';

interface RobotProfileProps {
robot: Robot;
setRobot: (state: Robot) => void;
setView: (state: 'welcome' | 'onboarding' | 'recovery' | 'profile') => void;
getGenerateRobot: (token: string, slot?: number) => void;
inputToken: string;
logoutRobot: () => void;
setInputToken: (state: string) => void;
width: number;
baseUrl: string;
}

const RobotProfile = ({
inputToken,
getGenerateRobot,
setInputToken,
logoutRobot,
setView,
width,
}: RobotProfileProps): JSX.Element => {
const { windowSize, client } = useContext<UseAppStoreType>(AppContext);
const { windowSize, client, setOpen } = useContext<UseAppStoreType>(AppContext);
const { garage, slotUpdatedAt } = useContext<UseGarageStoreType>(GarageContext);
const { federation } = useContext<UseFederationStoreType>(FederationContext);

Expand All @@ -62,7 +58,9 @@ const RobotProfile = ({
}, [slotUpdatedAt, loading]);

const handleAddRobot = (): void => {
getGenerateRobot(genBase62Token(36));
const token = genBase62Token(36);
garage.createRobot(federation, token);
setInputToken(token);
setLoading(true);
};

Expand Down Expand Up @@ -218,26 +216,7 @@ const RobotProfile = ({
alignItems='stretch'
sx={{ width: '100%' }}
>
<Grid
item
xs={2}
sx={{ display: 'flex', justifyContent: 'stretch', alignItems: 'stretch' }}
>
<Tooltip enterTouchDelay={0} enterDelay={300} enterNextDelay={1000} title={t('Logout')}>
<Button
sx={{ minWidth: '2em', width: '100%' }}
color='primary'
variant='outlined'
onClick={() => {
logoutRobot();
setView('welcome');
}}
>
<Logout />
</Button>
</Tooltip>
</Grid>
<Grid item xs={10}>
<Grid item xs={12}>
<TokenInput
inputToken={inputToken}
editable={false}
Expand Down Expand Up @@ -332,13 +311,29 @@ const RobotProfile = ({
<Button
color='primary'
onClick={() => {
garage.delete();
logoutRobot();
setView('welcome');
garage.deleteSlot();
if (Object.keys(garage.slots).length < 1) setView('welcome');
}}
>
<DeleteSweep /> <div style={{ width: '0.5em' }} />
{t('Delete Garage')}
{t('Delete Robot')}
</Button>
</Grid>
</Grid>
<Grid item container direction='row' alignItems='center' justifyContent='space-evenly'>
<Grid item>
<Button
size='small'
color='secondary'
variant='contained'
onClick={() => {
setOpen((open) => {
return { ...open, recovery: true };
});
}}
>
<Key /> <div style={{ width: '0.5em' }} />
{t('Recovery')}
</Button>
</Grid>
</Grid>
Expand Down
Loading

0 comments on commit 25f45be

Please sign in to comment.