Files
mattermost-mobile/app/components/team_icon/team_icon.js
Christian Hoff 98fee5e473 PLT-7567: Integration of Team Icons (#1470)
* PLT-7567: Integration of team icons in
channel drawer teams, switch team button, team selection, os share extenions

* PLT-7567: adopt updated eslint changes

* PLT-7567: Component for team icon display, refactoring

* PLT-7567: removed redundant styles

* PLT-7567: redux connected component for team icon, error handling
2018-03-06 20:39:24 +00:00

97 lines
2.5 KiB
JavaScript

// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
import PropTypes from 'prop-types';
import {
Text,
Image,
View,
} from 'react-native';
import {makeStyleSheetFromTheme} from 'app/utils/theme';
import {Client4} from 'mattermost-redux/client';
export default class TeamIcon extends React.PureComponent {
static propTypes = {
teamId: PropTypes.string.isRequired, // eslint-disable-line react/no-unused-prop-types
styleContainer: PropTypes.any,
styleText: PropTypes.any,
styleImage: PropTypes.any,
team: PropTypes.object.isRequired,
theme: PropTypes.object.isRequired,
};
state = {
imageError: false,
};
componentWillReceiveProps() {
this.setState({imageError: false});
}
render() {
const {
team,
theme,
styleContainer,
styleText,
styleImage,
} = this.props;
const styles = getStyleSheet(theme);
let teamIconContent;
if (team.last_team_icon_update && !this.state.imageError) {
const teamIconUrl = Client4.getTeamIconUrl(team.id, team.last_team_icon_update);
teamIconContent = (
<Image
style={[styles.image, styleImage]}
source={{uri: teamIconUrl}}
onError={() => this.setState({imageError: true})}
/>
);
} else {
teamIconContent = (
<Text style={[styles.text, styleText]}>
{team.display_name.substr(0, 2).toUpperCase()}
</Text>
);
}
return (
<View style={[styles.container, styleContainer]}>
{teamIconContent}
</View>
);
}
}
const getStyleSheet = makeStyleSheetFromTheme((theme) => {
return {
container: {
width: 30,
height: 30,
borderRadius: 2,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: theme.sidebarText,
},
text: {
color: theme.sidebarBg,
fontFamily: 'OpenSans',
fontWeight: '600',
fontSize: 15,
},
image: {
borderRadius: 2,
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
},
};
});