2020-05-01 06:50:27 +01:00
import { FormattedMessage } from 'react-intl'
import {
source _url ,
version ,
} from '../initial_state'
import {
APP _NAME ,
DEFAULT _REL ,
} from '../constants'
import Button from './button'
import DotTextSeperator from './dot_text_seperator'
import Divider from './divider'
import Icon from './icon'
import Text from './text'
2020-04-30 05:34:50 +01:00
2019-08-07 06:02:36 +01:00
export default class ErrorBoundary extends PureComponent {
static propTypes = {
children : PropTypes . node ,
2020-02-29 15:42:47 +00:00
}
2019-08-07 06:02:36 +01:00
state = {
hasError : false ,
stackTrace : undefined ,
componentStack : undefined ,
2020-05-01 06:50:27 +01:00
copied : false ,
2019-08-07 06:02:36 +01:00
}
componentDidCatch ( error , info ) {
this . setState ( {
hasError : true ,
stackTrace : error . stack ,
componentStack : info && info . componentStack ,
2020-05-01 06:50:27 +01:00
copied : false ,
2020-02-29 15:42:47 +00:00
} )
2019-08-07 06:02:36 +01:00
}
2020-05-01 06:50:27 +01:00
handleCopyStackTrace = ( ) => {
const { stackTrace } = this . state ;
const textarea = document . createElement ( 'textarea' ) ;
textarea . textContent = stackTrace ;
textarea . style . position = 'fixed' ;
document . body . appendChild ( textarea ) ;
try {
textarea . select ( ) ;
document . execCommand ( 'copy' ) ;
} catch ( e ) {
//
}
document . body . removeChild ( textarea ) ;
this . setState ( { copied : true } ) ;
setTimeout ( ( ) => this . setState ( { copied : false } ) , 700 ) ;
}
2019-08-07 06:02:36 +01:00
render ( ) {
2020-05-01 06:50:27 +01:00
const { hasError , copied } = this . state
2020-02-29 15:42:47 +00:00
if ( ! hasError ) return this . props . children
2019-08-07 06:02:36 +01:00
return (
2020-05-01 06:50:27 +01:00
< div className = { [ _s . default , _s . heightMin100VH , _s . width100PC , _s . alignItemsCenter , _s . justifyContentCenter ] . join ( ' ' ) } >
2020-05-14 22:47:33 +01:00
< div className = { [ _s . default , _s . heightMin53PX , _s . bgBrand , _s . alignItemsCenter , _s . z3 , _s . top0 , _s . right0 , _s . left0 , _s . posFixed ] . join ( ' ' ) } >
< div className = { [ _s . default , _s . flexRow , _s . saveAreaInsetPT , _s . saveAreaInsetPL , _s . saveAreaInsetPR , _s . width1255PX ] . join ( ' ' ) } >
2020-05-01 06:50:27 +01:00
< div className = { [ _s . default , _s . flexRow ] . join ( ' ' ) } >
< h1 className = { [ _s . default , _s . mr15 ] . join ( ' ' ) } >
< Button href = '/' isText aria - label = 'Gab' className = { [ _s . default , _s . justifyContentCenter , _s . noSelect , _s . noUnderline , _s . height53PX , _s . cursorPointer , _s . px10 , _s . mr15 ] . join ( ' ' ) } >
2020-05-09 03:17:19 +01:00
< Icon id = 'logo' className = { _s . fillWhite } / >
2020-05-01 06:50:27 +01:00
< / B u t t o n >
< / h 1 >
< / d i v >
< / d i v >
< / d i v >
< div className = { [ _s . default , _s . maxWidth640PX , _s . px15 , _s . py10 ] . join ( ' ' ) } >
< Icon id = 'warning' size = '28px' className = { [ _s . default , _s . fillSecondary , _s . mb15 ] . join ( ' ' ) } / >
< Text size = 'medium' className = { _s . pt15 } >
< FormattedMessage
id = 'error.unexpected_crash.explanation'
defaultMessage = 'Due to a bug in our code or a browser compatibility issue, this page or feature could not be displayed correctly.'
/ >
< / T e x t >
< Text size = 'medium' className = { _s . mt10 } >
< FormattedMessage
id = 'error.unexpected_crash.next_steps'
defaultMessage = 'Try refreshing the page or trying the action again. If that does not help, you may still be able to use Gab Social through a different browser or native app.'
/ >
< / T e x t >
< div className = { [ _s . default , _s . py10 , _s . my10 ] . join ( ' ' ) } >
< Text >
{ APP _NAME } ( { version } )
< / T e x t >
< div className = { [ _s . default , _s . flexRow , _s . mt10 , _s . alignItemsCenter ] . join ( ' ' ) } >
< Button
isText
href = { source _url }
rel = { DEFAULT _REL }
target = '_blank'
backgroundColor = 'tertiary'
color = 'primary'
radiusSmall
className = { [ _s . py2 , _s . px10 ] . join ( ' ' ) }
>
< Text color = 'inherit' >
< FormattedMessage
id = 'errors.unexpected_crash.report_issue'
defaultMessage = 'Report issue'
/ >
< / T e x t >
< / B u t t o n >
< DotTextSeperator / >
< Button
isText
backgroundColor = 'tertiary'
color = 'primary'
onClick = { this . handleCopyStackTrace }
radiusSmall
className = { [ _s . ml5 , _s . py2 , _s . px10 ] . join ( ' ' ) }
>
< Text color = 'inherit' >
< FormattedMessage
id = 'errors.unexpected_crash.copy_stacktrace'
defaultMessage = 'Copy stacktrace to clipboard'
/ >
< / T e x t >
< / B u t t o n >
< / d i v >
< / d i v >
< Divider / >
< div className = { [ _s . default , _s . flexRow ] . join ( ' ' ) } >
< Button href = '/home' >
< Text align = 'center' color = 'inherit' >
< FormattedMessage
id = 'return_home'
defaultMessage = 'Return Home'
/ >
< / T e x t >
< / B u t t o n >
< / d i v >
2019-08-07 06:02:36 +01:00
< / d i v >
< / d i v >
2020-02-29 15:42:47 +00:00
)
2019-08-07 06:02:36 +01:00
}
}