-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
152 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
client/src/components/error-boundary/error-boundary.component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from 'react'; | ||
|
||
import {ErrorImageContainer, ErrorImageOverlay, ErrorImageText } from './error-boundary.styles'; | ||
|
||
class ErrorBoundary extends React.Component { | ||
constructor(){ | ||
super(); | ||
|
||
this.state = { | ||
hasErrored: false | ||
} | ||
} | ||
|
||
static getDerivedStateFromError(error){ | ||
return { hasErrored: true} | ||
|
||
} | ||
|
||
componentDidCatch(error, info){ | ||
console.log(error); | ||
} | ||
|
||
render(){ | ||
if(this.state.hasErrored){ | ||
return ( | ||
<ErrorImageOverlay> | ||
<ErrorImageContainer imageUrl='https://i.imgur.com/A040Lxr.png' /> | ||
<ErrorImageText>Sorry this page is broken</ErrorImageText> | ||
</ErrorImageOverlay> | ||
) | ||
} | ||
return this.props.children; | ||
} | ||
} | ||
|
||
export default ErrorBoundary; |
24 changes: 24 additions & 0 deletions
24
client/src/components/error-boundary/error-boundary.styles.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const ErrorImageOverlay = styled.div` | ||
height: 60vh; | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
`; | ||
|
||
export const ErrorImageContainer = styled.div` | ||
display: inline-block; | ||
background-image: ${({ imageUrl }) => `url(${imageUrl})`}; | ||
background-size: cover; | ||
background-position: center; | ||
width: 40vh; | ||
height: 40vh; | ||
`; | ||
|
||
export const ErrorImageText = styled.h2` | ||
font-size: 28px; | ||
color: #2f8e89; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
|
||
import {SpinnerContainer, SpinnerOverlay} from './spinner.styles'; | ||
|
||
export const Spinner = () => ( | ||
<SpinnerOverlay> | ||
<SpinnerContainer /> | ||
</SpinnerOverlay> | ||
) | ||
export default Spinner; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const SpinnerOverlay = styled.div` | ||
height: 60vh; | ||
width: 100%; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
`; | ||
|
||
export const SpinnerContainer = styled.div` | ||
display: inline-block; | ||
width: 50px; | ||
height: 50px; | ||
border: 3px solid rgba(195, 195, 195, 0.6); | ||
border-radius: 50%; | ||
border-top-color: #636767; | ||
animation: spin 1s ease-in-out infinite; | ||
-webkit-animation: spin 1s ease-in-out infinite; | ||
@keyframes spin { | ||
to { | ||
-webkit-transform: rotate(360deg); | ||
} | ||
} | ||
@-webkit-keyframes spin { | ||
to { | ||
-webkit-transform: rotate(360deg); | ||
} | ||
} | ||
`; |
18 changes: 5 additions & 13 deletions
18
client/src/components/with-spinner/with-spinner.component.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,9 @@ | ||
import React from 'react'; | ||
|
||
import {SpinnerContainer, SpinnerOverlay} from './with-spinner.styles'; | ||
import {Spinner} from '../spinner/spinner.component'; | ||
|
||
const WithSpinner = WrappedDocument => ({isLoading, ...otherProps}) => { | ||
return isLoading ? (<Spinner/>) : (<WrappedDocument {...otherProps} />) | ||
}; | ||
|
||
const WithSpinner = WrappedDocument => { | ||
const Spinner = ({isLoading, ...otherProps}) => { | ||
return isLoading ? ( | ||
<SpinnerOverlay> | ||
<SpinnerContainer /> | ||
</SpinnerOverlay> | ||
) : ( | ||
<WrappedDocument {...otherProps} /> | ||
) | ||
} | ||
return Spinner; | ||
} | ||
export default WithSpinner; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters