mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 06:28:51 +00:00
feat(phone/error-handling): add top level error boundary for reload
This commit is contained in:
1 parent
908a393451
commit
3b7326dac8
3 files changed
+88
-16
No files matched your search
+19
-16
@@ -32,6 +32,7 @@ import PhoneWrapper from './PhoneWrapper';
|
||||
|
||||
import dayjs from 'dayjs';
|
||||
import DefaultConfig from '../../config.json';
|
||||
import { TopLevelErrorComponent } from './ui/components/TopLevelErrorComponent';
|
||||
|
||||
function Phone() {
|
||||
const { t, i18n } = useTranslation();
|
||||
@@ -78,22 +79,24 @@ function Phone() {
|
||||
|
||||
return (
|
||||
<div>
|
||||
<WindowSnackbar />
|
||||
<PhoneWrapper>
|
||||
<NotificationBar />
|
||||
<div className="PhoneAppContainer">
|
||||
<>
|
||||
<Route exact path="/" component={HomeApp} />
|
||||
{callModal && <Route exact path="/call" component={CallModal} />}
|
||||
{apps.map((App) => (
|
||||
<App.Route key={App.id} />
|
||||
))}
|
||||
</>
|
||||
<NotificationAlert />
|
||||
<PhoneSnackbar />
|
||||
</div>
|
||||
<Navigation />
|
||||
</PhoneWrapper>
|
||||
<TopLevelErrorComponent>
|
||||
<WindowSnackbar />
|
||||
<PhoneWrapper>
|
||||
<NotificationBar />
|
||||
<div className="PhoneAppContainer">
|
||||
<>
|
||||
<Route exact path="/" component={HomeApp} />
|
||||
{callModal && <Route exact path="/call" component={CallModal} />}
|
||||
{apps.map((App) => (
|
||||
<App.Route key={App.id} />
|
||||
))}
|
||||
</>
|
||||
<NotificationAlert />
|
||||
<PhoneSnackbar />
|
||||
</div>
|
||||
<Navigation />
|
||||
</PhoneWrapper>
|
||||
</TopLevelErrorComponent>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
{
|
||||
"translation": {
|
||||
"MISC": {
|
||||
"TOP_LEVEL_ERR_TITLE": "Fatal Error",
|
||||
"TOP_LEVEL_ERR_ACTION": "Reload",
|
||||
"TOP_LEVEL_ERR_MSG": "NPWD has encountered an error it was unable to recover from. You will need to reload the NUI window. The error is shown below for developer reference."
|
||||
},
|
||||
"DATE_FORMAT": "MM/DD/YYYY",
|
||||
"DATE_TIME_FORMAT": "MM/DD/YYYY hh:mm A",
|
||||
"CALLS": {
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
Button,
|
||||
Dialog,
|
||||
DialogActions,
|
||||
DialogContent,
|
||||
DialogContentText,
|
||||
DialogTitle,
|
||||
} from '@material-ui/core';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
interface TopLevelErrorCompProps {
|
||||
hasError: boolean;
|
||||
errorMsg: string;
|
||||
}
|
||||
|
||||
interface ErrorDialogCompProps {
|
||||
isOpen: boolean;
|
||||
errorMsg: string;
|
||||
}
|
||||
|
||||
const ErrorDialogComp: React.FC<ErrorDialogCompProps> = ({ isOpen, errorMsg }) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handleReloadClick = () => window.location.reload();
|
||||
|
||||
return (
|
||||
<Dialog open={isOpen}>
|
||||
<DialogTitle>{t('MISC.TOP_LEVEL_ERR_TITLE')}</DialogTitle>
|
||||
<DialogContent>
|
||||
<DialogContentText>
|
||||
{t('MISC.TOP_LEVEL_ERR_MSG')}
|
||||
<br />
|
||||
<br />
|
||||
<code style={{ color: 'red' }}>{errorMsg}</code>
|
||||
</DialogContentText>
|
||||
<DialogActions>
|
||||
<Button color="primary" onClick={handleReloadClick}>
|
||||
{t('MISC.TOP_LEVEL_ERR_ACTION')}
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
export class TopLevelErrorComponent extends React.Component<any, TopLevelErrorCompProps> {
|
||||
public state = {
|
||||
hasError: false,
|
||||
errorMsg: '',
|
||||
};
|
||||
|
||||
static getDerivedStateFromError(error: Error) {
|
||||
return { hasError: true, errorMsg: error.message };
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.hasError) {
|
||||
return <ErrorDialogComp isOpen={this.state.hasError} errorMsg={this.state.errorMsg} />;
|
||||
}
|
||||
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user