summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
authorHaishan <[email protected]>2018-12-23 23:36:17 +0800
committerHaishan <[email protected]>2018-12-23 23:36:17 +0800
commit38e5b480c0ae4af53bf734d65595fbdbf72dd2c1 (patch)
treea94c01744d046629f8e80ba244ac556ce8cdd039 /src/components
parenta72115067a8aee5dce75ad34a280a2588ac24c0e (diff)
feat: add a customized ErrorBoundaryFallback
Diffstat (limited to 'src/components')
-rw-r--r--src/components/ErrorBoundary.js5
-rw-r--r--src/components/ErrorBoundaryFallback.js27
-rw-r--r--src/components/ErrorBoundaryFallback.module.scss30
3 files changed, 60 insertions, 2 deletions
diff --git a/src/components/ErrorBoundary.js b/src/components/ErrorBoundary.js
index a44ca92..892f524 100644
--- a/src/components/ErrorBoundary.js
+++ b/src/components/ErrorBoundary.js
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { getSentry } from '../misc/sentry';
+import ErrorBoundaryFallback from 'c/ErrorBoundaryFallback';
// XXX this is no Hook equivalents for componentDidCatch
// we have to use class for now
@@ -42,9 +43,9 @@ class ErrorBoundary extends Component {
render() {
if (this.state.error) {
//render fallback UI
- return <a onClick={this.showReportDialog}>Report feedback</a>;
+ // return <a onClick={this.showReportDialog}>Report feedback</a>;
+ return <ErrorBoundaryFallback />;
} else {
- //when there's not an error, render children untouched
return this.props.children;
}
}
diff --git a/src/components/ErrorBoundaryFallback.js b/src/components/ErrorBoundaryFallback.js
new file mode 100644
index 0000000..5f15f4f
--- /dev/null
+++ b/src/components/ErrorBoundaryFallback.js
@@ -0,0 +1,27 @@
+import React from 'react';
+import Icon from 'c/Icon';
+import yacd from 's/yacd.svg';
+import github from 's/github.svg';
+
+import s0 from './ErrorBoundaryFallback.module.scss';
+const yacdRepoIssueUrl = 'https://github.com/haishanh/yacd/issues';
+
+function ErrorBoundaryFallback() {
+ return (
+ <div className={s0.root}>
+ <div className={s0.yacd}>
+ <Icon id={yacd.id} width={150} height={150} />
+ </div>
+ <h1>Oops, something went wrong!</h1>
+ <p>
+ If you think this is a bug, reporting this at{' '}
+ <a className={s0.link} href={yacdRepoIssueUrl}>
+ <Icon id={github.id} width={16} height={16} />
+ haishanh/yacd
+ </a>
+ </p>
+ </div>
+ );
+}
+
+export default ErrorBoundaryFallback;
diff --git a/src/components/ErrorBoundaryFallback.module.scss b/src/components/ErrorBoundaryFallback.module.scss
new file mode 100644
index 0000000..5deae74
--- /dev/null
+++ b/src/components/ErrorBoundaryFallback.module.scss
@@ -0,0 +1,30 @@
+.root {
+ position: fixed;
+ top: 0;
+ bottom: 0;
+ left: 0;
+ right: 0;
+ overflow: hidden;
+
+ padding: 20px;
+ background: var(--color-background);
+ color: var(--color-text);
+ text-align: center;
+}
+
+.yacd {
+ color: #2a477a;
+ opacity: 0.6;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ padding: 40px;
+}
+
+.link {
+ color: var(--color-text-secondary);
+ &:hover,
+ &:active {
+ color: #387cec;
+ }
+}