Skip to content

Commit 774b1f0

Browse files
123vivekrgitmate-bot
authored andcommitted
loadable.jsx: Make model for showing error
Shows a modal with error message. Fixes #127
1 parent 5ce504b commit 774b1f0

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

src/components/loadable.jsx

+23-14
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,23 @@ const STATUS = {
1010
};
1111

1212
class Loadable extends Component {
13-
static defaultProps = {
14-
renderError: (err) => {
13+
14+
state = {status: STATUS.INITIAL, value: null, show: false};
15+
16+
handleClose = () => {
17+
this.setState({ show: false });
18+
}
19+
20+
handleShow = () => {
21+
this.setState({ show: true });
22+
}
23+
24+
renderError = (err) => {
1525
console.error(err);
1626
// If it is a permissions error then it might be a rate limit
1727
if (err.status === 403) {
1828
return (
19-
<BS.Modal show >
29+
<BS.Modal show={ this.state.show } >
2030
<BS.Modal.Header>
2131
<BS.Modal.Title><h2>Insufficient Permissions </h2>(or rate limit exceeded)</BS.Modal.Title>
2232
</BS.Modal.Header>
@@ -32,7 +42,7 @@ class Loadable extends Component {
3242
</code>
3343
<br />
3444
<br />
35-
<Button bsStyle="danger">Ok</Button>
45+
<Button bsStyle="danger" onClick={ this.handleClose }>Ok</Button>
3646
</div>
3747
</BS.Modal.Body>
3848
</BS.Modal>
@@ -43,7 +53,7 @@ class Loadable extends Component {
4353
);
4454
} else {
4555
return (
46-
<BS.Modal show >
56+
<BS.Modal show={ this.state.show } >
4757
<BS.Modal.Header>
4858
</BS.Modal.Header>
4959
<BS.Modal.Body >
@@ -58,16 +68,13 @@ class Loadable extends Component {
5868
</code>
5969
<br />
6070
<br />
61-
<Button bsStyle="danger">Ok</Button>
71+
<Button bsStyle="danger" onClick={ this.handleClose }>Ok</Button>
6272
</div>
6373
</BS.Modal.Body>
6474
</BS.Modal>
6575
);
6676
}
67-
}
68-
};
69-
70-
state = {status: STATUS.INITIAL, value: null, show: false};
77+
};
7178

7279
componentDidMount() {
7380
const { promise } = this.props;
@@ -84,11 +91,13 @@ class Loadable extends Component {
8491
onResolve = (value) => {
8592
// TODO: Find out why this is being called multiple times
8693
this.setState({status: STATUS.RESOLVED, value});
94+
// window.alert(value)
8795
};
8896

8997
onError = (value) => {
9098
// TODO: Find out why this is being called multiple times
9199
if (this.state.status !== STATUS.ERROR) {
100+
// window.alert(value)
92101
this.setState({status: STATUS.ERROR, value});
93102
}
94103
};
@@ -105,16 +114,16 @@ class Loadable extends Component {
105114

106115
render() {
107116
const { status, value } = this.state;
108-
let {renderLoading, renderLoaded, renderError} = this.props;
109-
117+
let { renderLoading, renderLoaded } = this.props;
110118
renderLoading = renderLoading || this.renderLoading;
111119

112120
if (status === STATUS.INITIAL) {
113-
return renderLoading();
121+
return this.renderLoading();
114122
} else if (status === STATUS.RESOLVED) {
115123
return renderLoaded(value);
116124
} else {
117-
return renderError(value);
125+
this.handleShow();
126+
return this.renderError(value);
118127
}
119128
}
120129
}

0 commit comments

Comments
 (0)