feat(client/debug): Phone restart command (#145)

Trigger a UI restart by entering the command `phone:restart` in the F8 console.
This commit is contained in:
Taso authored and GitHub committed 2021-03-06 10:38:10 -05:00
1 parent 531a341ffd
commit 605f957f9a
3 files changed
+53 -11

No files matched your search

@@ -0,0 +1,42 @@
import React, { useState } from 'react';
import { Snackbar, Typography } from '@material-ui/core';
import { useNuiEvent } from '../../os/nui-events/hooks/useNuiEvent';
import { Alert } from './Alert';
import { makeStyles } from '@material-ui/core/styles';
const useStyles = makeStyles({
root: {
position: 'absolute',
width: 'auto',
bottom: 20,
},
});
// NOTE: Will make this more generic at some point for error handling as well
const WindowSnackbar = () => {
const [open, setOpen] = useState<boolean>(false);
const [message, setMessage] = useState<string>('');
const [severity, setSeverity] = useState<'info' | 'error' | 'success'>('info');
const classes = useStyles();
useNuiEvent('PHONE', 'startRestart', () => {
setMessage('Restarting UI');
setOpen(true);
setSeverity('error');
setTimeout(() => window.location.reload(), 3000);
});
const handleClose = () => {
setOpen(false);
};
return (
<Snackbar open={open} onClose={handleClose} className={classes.root}>
<Alert severity={severity}>
<Typography variant="body1">Phone - {message}</Typography>
</Alert>
</Snackbar>
);
};
export default WindowSnackbar;