forked from facebook/create-react-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRuntimeErrorContainer.js
77 lines (70 loc) · 2.19 KB
/
RuntimeErrorContainer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/* @flow */
import React, { PureComponent } from 'react';
import ErrorOverlay from '../components/ErrorOverlay';
import CloseButton from '../components/CloseButton';
import NavigationBar from '../components/NavigationBar';
import RuntimeError from './RuntimeError';
import Footer from '../components/Footer';
class RuntimeErrorContainer extends PureComponent {
state = {
currentIndex: 0,
};
previous = () => {
this.setState((state, props) => ({
currentIndex:
state.currentIndex > 0
? state.currentIndex - 1
: props.errorRecords.length - 1,
}));
};
next = () => {
this.setState((state, props) => ({
currentIndex:
state.currentIndex < props.errorRecords.length - 1
? state.currentIndex + 1
: 0,
}));
};
shortcutHandler = (key: string) => {
if (key === 'Escape') {
this.props.close();
} else if (key === 'ArrowLeft') {
this.previous();
} else if (key === 'ArrowRight') {
this.next();
}
};
render() {
const { errorRecords, close } = this.props;
const totalErrors = errorRecords.length;
return (
<ErrorOverlay shortcutHandler={this.shortcutHandler}>
<CloseButton close={close} />
{totalErrors > 1 &&
<NavigationBar
currentError={this.state.currentIndex + 1}
totalErrors={totalErrors}
previous={this.previous}
next={this.next}
/>}
<RuntimeError
errorRecord={errorRecords[this.state.currentIndex]}
launchEditorEndpoint={this.props.launchEditorEndpoint}
/>
<Footer
line1="This screen is visible only in development. It will not appear if the app crashes in production."
line2="Open your browser’s developer console to further inspect this error."
/>
</ErrorOverlay>
);
}
}
export default RuntimeErrorContainer;