-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add error-boundary & error-indicator components #16
Changes from 5 commits
a27e147
63dab50
de31ad2
5465271
c1f9c95
39468bc
6d444e5
9709326
9597d8a
73e0160
f268f89
80a4c9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as React from 'react'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo, rename component to error-boundary There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
|
||
import ErrorIndicator from '../error-indicator/error-indicator'; | ||
|
||
interface ErrorBoundryState { | ||
hasError: boolean; | ||
} | ||
|
||
export default class ErrorBoundry extends React.Component<{}, ErrorBoundryState> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't use default export. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed defaults exports from ErrorBoundry and ErrorIndicator components |
||
|
||
state: ErrorBoundryState = { | ||
hasError: false, | ||
}; | ||
|
||
componentDidCatch(): void { | ||
this.setState({ | ||
hasError: true, | ||
}); | ||
} | ||
|
||
render(): React.ReactNode | React.FC { | ||
if (this.state.hasError) { | ||
return <ErrorIndicator />; | ||
} | ||
return this.props.children; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ErrorBoundry from './error-boundry'; | ||
|
||
export {ErrorBoundry}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
.error-indicator { | ||
background-color: rgba(0,0,0,0.6); | ||
display: flex; | ||
flex-direction: row; | ||
user-select: none; | ||
width: 100%; | ||
} | ||
|
||
.error-indicator__text{ | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
position: absolute; | ||
left: 10%; | ||
top: 20%; | ||
width: 50%; | ||
color: #1b2664; | ||
|
||
} | ||
|
||
.error-indicator__title { | ||
color: #F2E14C; | ||
font-family: 'Exo', sans-serif; | ||
font-size:6rem; | ||
font-weight: bold; | ||
letter-spacing: 2px; | ||
margin-bottom: 1rem; | ||
} | ||
|
||
.error-indicator__subtitle { | ||
color: white; | ||
font-family: 'Exo', sans-serif; | ||
font-size: 1.2rem; | ||
text-align: left; | ||
letter-spacing: 2px; | ||
margin-bottom: 1rem; | ||
} | ||
@media only screen and (max-width: 600px) { | ||
.error-indicator__text{ | ||
left: 5%; | ||
top: 20%; | ||
width: 50%; | ||
color: #1b2664; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React, { memo } from 'react'; | ||
|
||
import './error-indicator.css'; | ||
import icon from './error-indicator.svg'; | ||
|
||
const sectionStyle = { | ||
height: '100%', | ||
backgroundImage: `url(${icon})`, | ||
backgroundRepeat: 'no-repeat', | ||
backgroundSize: 'cover', | ||
backgroundPosition: 'center', | ||
}; | ||
|
||
const ErrorIndicator: React.FC = memo(() => { | ||
return ( | ||
<div className="error-indicator" style={sectionStyle}> | ||
<div className="error-indicator__text"> | ||
<span className="error-indicator__title">УПС!</span> | ||
<span className="error-indicator__subtitle">что-то пошло не так</span> | ||
<span className="error-indicator__subtitle">(но мы уже отправили парня из поддержки починить это)</span> | ||
</div> | ||
</div> | ||
); | ||
}); | ||
|
||
export default ErrorIndicator; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ErrorIndicator from './error-indicator'; | ||
|
||
export {ErrorIndicator}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need this changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not, but following the "react" best practice, empty tags should be self-closing. Also, I have deleted unnecessary spaces at the end of the string.