mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-05 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
+72
No files matched your search
@@ -32,6 +32,7 @@ import PhoneWrapper from './PhoneWrapper';
|
|||||||
|
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import DefaultConfig from '../../config.json';
|
import DefaultConfig from '../../config.json';
|
||||||
|
import { TopLevelErrorComponent } from './ui/components/TopLevelErrorComponent';
|
||||||
|
|
||||||
function Phone() {
|
function Phone() {
|
||||||
const { t, i18n } = useTranslation();
|
const { t, i18n } = useTranslation();
|
||||||
@@ -78,6 +79,7 @@ function Phone() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
<TopLevelErrorComponent>
|
||||||
<WindowSnackbar />
|
<WindowSnackbar />
|
||||||
<PhoneWrapper>
|
<PhoneWrapper>
|
||||||
<NotificationBar />
|
<NotificationBar />
|
||||||
@@ -94,6 +96,7 @@ function Phone() {
|
|||||||
</div>
|
</div>
|
||||||
<Navigation />
|
<Navigation />
|
||||||
</PhoneWrapper>
|
</PhoneWrapper>
|
||||||
|
</TopLevelErrorComponent>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
{
|
{
|
||||||
"translation": {
|
"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_FORMAT": "MM/DD/YYYY",
|
||||||
"DATE_TIME_FORMAT": "MM/DD/YYYY hh:mm A",
|
"DATE_TIME_FORMAT": "MM/DD/YYYY hh:mm A",
|
||||||
"CALLS": {
|
"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