From 38e5b480c0ae4af53bf734d65595fbdbf72dd2c1 Mon Sep 17 00:00:00 2001 From: Haishan Date: Sun, 23 Dec 2018 23:36:17 +0800 Subject: feat: add a customized ErrorBoundaryFallback --- src/components/ErrorBoundary.js | 5 ++-- src/components/ErrorBoundaryFallback.js | 27 +++++++++++++++++++++ src/components/ErrorBoundaryFallback.module.scss | 30 ++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 src/components/ErrorBoundaryFallback.js create mode 100644 src/components/ErrorBoundaryFallback.module.scss (limited to 'src/components') 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 Report feedback; + // return Report feedback; + return ; } 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 ( +
+
+ +
+

Oops, something went wrong!

+

+ If you think this is a bug, reporting this at{' '} + + + haishanh/yacd + +

+
+ ); +} + +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; + } +} -- cgit v1.3.1