2019-07-18 17:44:02 +00:00
|
|
|
import React from 'react';
|
|
|
|
import {
|
|
|
|
FlatList, StyleSheet, View
|
|
|
|
} from 'react-native';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
import I18n from '../i18n';
|
|
|
|
import StatusBar from '../containers/StatusBar';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../constants/colors';
|
2019-07-18 17:44:02 +00:00
|
|
|
import ServerItem, { ROW_HEIGHT } from '../presentation/ServerItem';
|
|
|
|
import sharedStyles from './Styles';
|
2019-07-29 16:33:28 +00:00
|
|
|
import RocketChat from '../lib/rocketchat';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { withTheme } from '../theme';
|
2020-06-15 14:00:46 +00:00
|
|
|
import SafeAreaView from '../containers/SafeAreaView';
|
2019-07-18 17:44:02 +00:00
|
|
|
|
|
|
|
const getItemLayout = (data, index) => ({ length: ROW_HEIGHT, offset: ROW_HEIGHT * index, index });
|
|
|
|
const keyExtractor = item => item.id;
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
list: {
|
|
|
|
marginVertical: 32,
|
|
|
|
...sharedStyles.separatorVertical
|
|
|
|
},
|
|
|
|
separator: {
|
|
|
|
...sharedStyles.separatorBottom,
|
|
|
|
marginLeft: 48
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-08-07 13:51:34 +00:00
|
|
|
class SelectServerView extends React.Component {
|
2020-06-15 14:00:46 +00:00
|
|
|
static navigationOptions = {
|
2019-07-18 17:44:02 +00:00
|
|
|
title: I18n.t('Select_Server')
|
2020-06-15 14:00:46 +00:00
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
|
|
|
|
static propTypes = {
|
2019-09-16 20:26:32 +00:00
|
|
|
server: PropTypes.string,
|
2020-06-15 14:00:46 +00:00
|
|
|
route: PropTypes.object,
|
2019-12-04 16:39:53 +00:00
|
|
|
navigation: PropTypes.object,
|
|
|
|
theme: PropTypes.string
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2020-06-15 14:00:46 +00:00
|
|
|
const { route } = this.props;
|
|
|
|
const servers = route.params?.servers ?? [];
|
2019-07-18 17:44:02 +00:00
|
|
|
const filteredServers = servers.filter(server => server.roomsUpdatedAt);
|
|
|
|
this.state = {
|
|
|
|
servers: filteredServers
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-07-29 16:33:28 +00:00
|
|
|
select = async(server) => {
|
2019-07-18 17:44:02 +00:00
|
|
|
const {
|
2020-06-15 14:00:46 +00:00
|
|
|
server: currentServer, navigation
|
2019-07-18 17:44:02 +00:00
|
|
|
} = this.props;
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
navigation.navigate('ShareListView');
|
2019-07-18 17:44:02 +00:00
|
|
|
if (currentServer !== server) {
|
2019-07-29 16:33:28 +00:00
|
|
|
await RocketChat.shareExtensionInit(server);
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderItem = ({ item }) => {
|
2019-12-04 16:39:53 +00:00
|
|
|
const { server, theme } = this.props;
|
2019-07-18 17:44:02 +00:00
|
|
|
return (
|
|
|
|
<ServerItem
|
|
|
|
server={server}
|
|
|
|
onPress={() => this.select(item.id)}
|
|
|
|
item={item}
|
|
|
|
hasCheck
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-07-18 17:44:02 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
renderSeparator = () => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
return <View style={[styles.separator, { borderColor: themes[theme].separatorColor }]} />;
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const { servers } = this.state;
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
2019-07-18 17:44:02 +00:00
|
|
|
return (
|
2020-06-15 14:00:46 +00:00
|
|
|
<SafeAreaView theme={theme}>
|
2019-12-04 16:39:53 +00:00
|
|
|
<StatusBar theme={theme} />
|
|
|
|
<View style={[styles.list, { borderColor: themes[theme].separatorColor }]}>
|
2019-07-18 17:44:02 +00:00
|
|
|
<FlatList
|
|
|
|
data={servers}
|
|
|
|
keyExtractor={keyExtractor}
|
|
|
|
renderItem={this.renderItem}
|
|
|
|
getItemLayout={getItemLayout}
|
2019-12-04 16:39:53 +00:00
|
|
|
contentContainerStyle={{ backgroundColor: themes[theme].backgroundColor }}
|
2019-07-18 17:44:02 +00:00
|
|
|
ItemSeparatorComponent={this.renderSeparator}
|
|
|
|
enableEmptySections
|
|
|
|
removeClippedSubviews
|
|
|
|
keyboardShouldPersistTaps='always'
|
|
|
|
windowSize={7}
|
|
|
|
bounces={false}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
|
|
|
const mapStateToProps = (({ share }) => ({
|
|
|
|
server: share.server
|
|
|
|
}));
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
export default connect(mapStateToProps)(withTheme(SelectServerView));
|