Rocket.Chat.ReactNative/app/presentation/ServerItem/index.js

60 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-07-18 17:44:02 +00:00
import React from 'react';
import PropTypes from 'prop-types';
import { View, Text } from 'react-native';
import FastImage from '@rocket.chat/react-native-fast-image';
2019-07-18 17:44:02 +00:00
2019-12-04 16:39:53 +00:00
import Touch from '../../utils/touch';
2019-07-18 17:44:02 +00:00
import Check from '../../containers/Check';
import styles, { ROW_HEIGHT } from './styles';
2019-12-04 16:39:53 +00:00
import { themes } from '../../constants/colors';
2019-07-18 17:44:02 +00:00
export { ROW_HEIGHT };
const ServerItem = React.memo(({
2019-12-04 16:39:53 +00:00
server, item, onPress, hasCheck, theme
2019-07-18 17:44:02 +00:00
}) => (
2019-12-04 16:39:53 +00:00
<Touch
onPress={onPress}
style={[styles.serverItem, { backgroundColor: themes[theme].backgroundColor }]}
testID={`rooms-list-header-server-${ item.id }`}
theme={theme}
>
2019-07-18 17:44:02 +00:00
<View style={styles.serverItemContainer}>
{item.iconURL
? (
<FastImage
source={{
uri: item.iconURL,
priority: FastImage.priority.high
}}
defaultSource={{ uri: 'logo' }}
style={styles.serverIcon}
onError={() => console.log('err_loading_server_icon')}
2019-07-18 17:44:02 +00:00
/>
)
: (
<FastImage
source={{ uri: 'logo' }}
style={styles.serverIcon}
/>
)
}
<View style={styles.serverTextContainer}>
2019-12-04 16:39:53 +00:00
<Text style={[styles.serverName, { color: themes[theme].titleText }]}>{item.name || item.id}</Text>
<Text style={[styles.serverUrl, { color: themes[theme].auxiliaryText }]}>{item.id}</Text>
2019-07-18 17:44:02 +00:00
</View>
2019-12-04 16:39:53 +00:00
{item.id === server && hasCheck ? <Check theme={theme} /> : null}
2019-07-18 17:44:02 +00:00
</View>
2019-12-04 16:39:53 +00:00
</Touch>
2019-07-18 17:44:02 +00:00
));
ServerItem.propTypes = {
onPress: PropTypes.func.isRequired,
item: PropTypes.object.isRequired,
hasCheck: PropTypes.bool,
2019-12-04 16:39:53 +00:00
server: PropTypes.string,
theme: PropTypes.string
2019-07-18 17:44:02 +00:00
};
export default ServerItem;