2018-08-31 16:46:33 +00:00
|
|
|
import React from 'react';
|
2022-02-25 18:59:39 +00:00
|
|
|
import { StyleSheet, Text, TextInputProps, TouchableOpacity, TouchableOpacityProps, View } from 'react-native';
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2019-02-07 16:13:21 +00:00
|
|
|
import I18n from '../../../i18n';
|
2019-03-29 19:36:07 +00:00
|
|
|
import sharedStyles from '../../Styles';
|
2022-05-02 19:21:15 +00:00
|
|
|
import { CustomIcon } from '../../../containers/CustomIcon';
|
2022-03-17 19:25:31 +00:00
|
|
|
import { useTheme } from '../../../theme';
|
2022-07-06 13:23:02 +00:00
|
|
|
import SearchHeader from '../../../containers/SearchHeader';
|
2023-10-19 13:38:57 +00:00
|
|
|
import { useAppSelector } from '../../../lib/hooks';
|
2019-02-07 16:13:21 +00:00
|
|
|
|
2018-08-31 16:46:33 +00:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
2022-07-06 13:23:02 +00:00
|
|
|
justifyContent: 'center'
|
2018-08-31 16:46:33 +00:00
|
|
|
},
|
|
|
|
button: {
|
|
|
|
flexDirection: 'row',
|
2020-07-06 20:56:28 +00:00
|
|
|
alignItems: 'center'
|
2018-08-31 16:46:33 +00:00
|
|
|
},
|
2020-07-06 20:56:28 +00:00
|
|
|
title: {
|
2022-06-01 19:46:37 +00:00
|
|
|
flexShrink: 1,
|
2023-09-08 13:51:12 +00:00
|
|
|
fontSize: 16,
|
2020-07-06 20:56:28 +00:00
|
|
|
...sharedStyles.textSemibold
|
2019-02-07 16:13:21 +00:00
|
|
|
},
|
2020-07-06 20:56:28 +00:00
|
|
|
subtitle: {
|
2023-09-08 13:51:12 +00:00
|
|
|
fontSize: 14,
|
2019-03-29 19:36:07 +00:00
|
|
|
...sharedStyles.textRegular
|
2019-02-07 16:13:21 +00:00
|
|
|
},
|
2018-08-31 16:46:33 +00:00
|
|
|
upsideDown: {
|
|
|
|
transform: [{ scaleY: -1 }]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
interface IRoomHeader {
|
|
|
|
connecting: boolean;
|
|
|
|
connected: boolean;
|
|
|
|
isFetching: boolean;
|
|
|
|
serverName: string;
|
|
|
|
server: string;
|
|
|
|
showServerDropdown: boolean;
|
|
|
|
showSearchHeader: boolean;
|
|
|
|
onSearchChangeText: TextInputProps['onChangeText'];
|
|
|
|
onPress: TouchableOpacityProps['onPress'];
|
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const Header = React.memo(
|
|
|
|
({
|
|
|
|
connecting,
|
|
|
|
connected,
|
|
|
|
isFetching,
|
2022-02-25 18:59:39 +00:00
|
|
|
serverName = 'Rocket.Chat',
|
2021-09-13 20:41:05 +00:00
|
|
|
server,
|
|
|
|
showServerDropdown,
|
|
|
|
showSearchHeader,
|
|
|
|
onSearchChangeText,
|
|
|
|
onPress
|
2022-02-25 18:59:39 +00:00
|
|
|
}: IRoomHeader) => {
|
2023-10-19 13:38:57 +00:00
|
|
|
const { status: supportedVersionsStatus } = useAppSelector(state => state.supportedVersions);
|
2022-07-06 13:23:02 +00:00
|
|
|
const { colors } = useTheme();
|
2020-07-06 20:56:28 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
if (showSearchHeader) {
|
2022-07-06 13:23:02 +00:00
|
|
|
return <SearchHeader onSearchChangeText={onSearchChangeText} testID='rooms-list-view-search-input' />;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
let subtitle;
|
2023-10-19 13:38:57 +00:00
|
|
|
if (supportedVersionsStatus === 'expired') {
|
|
|
|
subtitle = 'Cannot connect';
|
|
|
|
} else if (connecting) {
|
2021-09-13 20:41:05 +00:00
|
|
|
subtitle = I18n.t('Connecting');
|
|
|
|
} else if (isFetching) {
|
|
|
|
subtitle = I18n.t('Updating');
|
|
|
|
} else if (!connected) {
|
|
|
|
subtitle = I18n.t('Waiting_for_network');
|
|
|
|
} else {
|
|
|
|
subtitle = server?.replace(/(^\w+:|^)\/\//, '');
|
|
|
|
}
|
2018-10-23 21:39:48 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
2021-09-13 20:41:05 +00:00
|
|
|
<TouchableOpacity onPress={onPress} testID='rooms-list-header-server-dropdown-button'>
|
|
|
|
<View style={styles.button}>
|
2023-09-08 13:51:12 +00:00
|
|
|
<Text style={[styles.title, { color: colors.headerTitleColor }]} numberOfLines={1}>
|
2021-09-13 20:41:05 +00:00
|
|
|
{serverName}
|
|
|
|
</Text>
|
|
|
|
<CustomIcon
|
|
|
|
name='chevron-down'
|
2022-07-06 13:23:02 +00:00
|
|
|
color={colors.headerTintColor}
|
2021-09-13 20:41:05 +00:00
|
|
|
style={[showServerDropdown && styles.upsideDown]}
|
|
|
|
size={18}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
{subtitle ? (
|
|
|
|
<Text
|
|
|
|
testID='rooms-list-header-server-subtitle'
|
2023-09-08 13:51:12 +00:00
|
|
|
style={[styles.subtitle, { color: colors.auxiliaryText }]}
|
2022-08-08 21:02:08 +00:00
|
|
|
numberOfLines={1}
|
|
|
|
>
|
2021-09-13 20:41:05 +00:00
|
|
|
{subtitle}
|
|
|
|
</Text>
|
|
|
|
) : null}
|
|
|
|
</TouchableOpacity>
|
2018-08-31 16:46:33 +00:00
|
|
|
</View>
|
2018-10-23 21:39:48 +00:00
|
|
|
);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
);
|
2018-08-31 16:46:33 +00:00
|
|
|
|
|
|
|
export default Header;
|