2020-07-01 21:10:48 +00:00
|
|
|
/**
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
2021-03-19 15:08:48 +00:00
|
|
|
import { Button, Icon, ListItem, ThemeContext } from 'react-native-elements';
|
2021-01-06 16:17:22 +00:00
|
|
|
import React, { useContext } from 'react';
|
|
|
|
import { StyleSheet, View } from 'react-native';
|
2020-07-01 21:10:48 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2020-07-13 16:30:38 +00:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2020-07-01 21:10:48 +00:00
|
|
|
|
|
|
|
import { getIconName } from '../utils/Icons';
|
|
|
|
|
2021-02-26 23:58:29 +00:00
|
|
|
const ServerListItem = ({ item, index, activeServer, onDelete, onPress }) => {
|
2020-07-22 03:37:43 +00:00
|
|
|
const { t } = useTranslation();
|
2021-01-06 16:17:22 +00:00
|
|
|
const { theme } = useContext(ThemeContext);
|
2020-07-13 16:30:38 +00:00
|
|
|
|
2020-07-22 03:37:43 +00:00
|
|
|
const title = item?.name;
|
|
|
|
const version = item?.info?.Version || t('common.unknown');
|
|
|
|
const subtitle = `${t('settings.version', { version })}\n${item.urlString}`;
|
2020-07-01 21:10:48 +00:00
|
|
|
|
2020-07-22 03:37:43 +00:00
|
|
|
return (
|
|
|
|
<ListItem
|
2021-03-19 15:08:48 +00:00
|
|
|
testID='server-list-item'
|
2020-12-08 15:39:35 +00:00
|
|
|
topDivider={index === 0}
|
|
|
|
bottomDivider
|
|
|
|
onPress={() => onPress(index)}
|
|
|
|
>
|
|
|
|
{(
|
2020-07-22 03:37:43 +00:00
|
|
|
index === activeServer ? (
|
|
|
|
<Icon
|
2021-03-19 15:08:48 +00:00
|
|
|
testID='active-icon'
|
2020-07-22 03:37:43 +00:00
|
|
|
name={getIconName('checkmark')}
|
|
|
|
type='ionicon'
|
|
|
|
size={24}
|
|
|
|
containerStyle={styles.leftElement}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<View style={styles.leftElement} />
|
|
|
|
)
|
|
|
|
)}
|
2020-12-08 15:39:35 +00:00
|
|
|
<ListItem.Content>
|
2021-03-19 15:08:48 +00:00
|
|
|
<ListItem.Title
|
|
|
|
testID='title'
|
|
|
|
style={styles.title}
|
|
|
|
>
|
|
|
|
{title}
|
|
|
|
</ListItem.Title>
|
|
|
|
<ListItem.Subtitle
|
|
|
|
testID='subtitle'
|
|
|
|
>
|
|
|
|
{subtitle}
|
|
|
|
</ListItem.Subtitle>
|
2020-12-08 15:39:35 +00:00
|
|
|
</ListItem.Content>
|
|
|
|
<Button
|
2021-03-19 15:08:48 +00:00
|
|
|
testID='delete-button'
|
2020-12-08 15:39:35 +00:00
|
|
|
type='clear'
|
|
|
|
icon={{
|
|
|
|
name: getIconName('trash'),
|
|
|
|
type: 'ionicon',
|
2021-01-06 16:17:22 +00:00
|
|
|
iconStyle: {
|
|
|
|
color: theme.colors.error
|
|
|
|
}
|
2020-12-08 15:39:35 +00:00
|
|
|
}}
|
|
|
|
onPress={() => onDelete(index)}
|
|
|
|
/>
|
|
|
|
</ListItem>
|
2020-07-22 03:37:43 +00:00
|
|
|
);
|
2020-07-01 21:10:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ServerListItem.propTypes = {
|
2020-07-22 03:37:43 +00:00
|
|
|
item: PropTypes.object.isRequired,
|
|
|
|
index: PropTypes.number.isRequired,
|
|
|
|
activeServer: PropTypes.number.isRequired,
|
|
|
|
onDelete: PropTypes.func.isRequired,
|
|
|
|
onPress: PropTypes.func.isRequired
|
2020-07-01 21:10:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2020-07-22 03:37:43 +00:00
|
|
|
title: {
|
|
|
|
marginBottom: 2
|
|
|
|
},
|
|
|
|
leftElement: {
|
|
|
|
width: 12
|
|
|
|
}
|
2020-07-01 21:10:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export default ServerListItem;
|