forked from Ivasoft/mattermost-mobile
* Add error boundry around latex to avoid crash * Do not update channel display name when displayName is empty * Show Muted unread channel as muted unless it has mentions * Video size to wrapperWidth if thumbnail is not available * Hide Threads button in channel list when only unreads filter if it does not have any unreads or mentions * Ensure channel_item muted state is bolded when unread * Bump network default retry to 3 attempts * Sort only unreads by last root post if CRT is enabled * Default canPost to true if permission is not found * rename to ErrorBoundary (typo fix) * simplify filterAndSortMyChannels * Fix channel name collision with mention badges
59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React from 'react';
|
|
import {Text} from 'react-native';
|
|
|
|
import {makeStyleSheetFromTheme} from '@utils/theme';
|
|
import {typography} from '@utils/typography';
|
|
|
|
type State = {
|
|
hasError: boolean;
|
|
}
|
|
|
|
type Props = {
|
|
children: JSX.Element;
|
|
error: string;
|
|
theme: Theme;
|
|
}
|
|
|
|
const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => ({
|
|
error: {
|
|
color: theme.errorTextColor,
|
|
flexDirection: 'row',
|
|
flexWrap: 'wrap',
|
|
fontStyle: 'italic',
|
|
...typography('Body', 100),
|
|
},
|
|
}));
|
|
|
|
class ErrorBoundary extends React.PureComponent<Props, State, any> {
|
|
constructor(props: Props) {
|
|
super(props);
|
|
this.state = {hasError: false};
|
|
}
|
|
|
|
componentDidCatch() {
|
|
this.setState({hasError: true});
|
|
}
|
|
|
|
render() {
|
|
// eslint-disable-next-line react/prop-types
|
|
const {children, error, theme} = this.props;
|
|
const {hasError} = this.state;
|
|
const style = getStyleSheet(theme);
|
|
|
|
if (hasError) {
|
|
return (
|
|
<Text style={style.error}>
|
|
{error}
|
|
</Text>
|
|
);
|
|
}
|
|
|
|
return children;
|
|
}
|
|
}
|
|
|
|
export default ErrorBoundary;
|