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 { SafeAreaView } from 'react-navigation';
|
|
|
|
|
|
|
|
import I18n from '../i18n';
|
|
|
|
import database from '../lib/realm';
|
|
|
|
import StatusBar from '../containers/StatusBar';
|
2019-07-29 16:33:28 +00:00
|
|
|
import { COLOR_BACKGROUND_CONTAINER } from '../constants/colors';
|
|
|
|
import Navigation from '../lib/ShareNavigation';
|
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-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({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
backgroundColor: COLOR_BACKGROUND_CONTAINER
|
|
|
|
},
|
|
|
|
list: {
|
|
|
|
marginVertical: 32,
|
|
|
|
...sharedStyles.separatorVertical
|
|
|
|
},
|
|
|
|
separator: {
|
|
|
|
...sharedStyles.separatorBottom,
|
|
|
|
marginLeft: 48
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-08-07 13:51:34 +00:00
|
|
|
class SelectServerView extends React.Component {
|
2019-07-18 17:44:02 +00:00
|
|
|
static navigationOptions = () => ({
|
|
|
|
title: I18n.t('Select_Server')
|
|
|
|
})
|
|
|
|
|
|
|
|
static propTypes = {
|
2019-07-29 16:33:28 +00:00
|
|
|
server: PropTypes.string
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
const { serversDB } = database.databases;
|
|
|
|
const servers = serversDB.objects('servers');
|
|
|
|
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 {
|
2019-07-29 16:33:28 +00:00
|
|
|
server: currentServer
|
2019-07-18 17:44:02 +00:00
|
|
|
} = this.props;
|
|
|
|
|
2019-07-29 16:33:28 +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 }) => {
|
|
|
|
const { server } = this.props;
|
|
|
|
return (
|
|
|
|
<ServerItem
|
|
|
|
server={server}
|
|
|
|
onPress={() => this.select(item.id)}
|
|
|
|
item={item}
|
|
|
|
hasCheck
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderSeparator = () => <View style={styles.separator} />;
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { servers } = this.state;
|
|
|
|
return (
|
|
|
|
<SafeAreaView
|
|
|
|
style={styles.container}
|
2019-08-07 13:51:34 +00:00
|
|
|
forceInset={{ vertical: 'never' }}
|
2019-07-18 17:44:02 +00:00
|
|
|
>
|
|
|
|
<StatusBar />
|
|
|
|
<View style={styles.list}>
|
|
|
|
<FlatList
|
|
|
|
data={servers}
|
|
|
|
keyExtractor={keyExtractor}
|
|
|
|
renderItem={this.renderItem}
|
|
|
|
getItemLayout={getItemLayout}
|
|
|
|
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
|
|
|
|
}));
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(SelectServerView);
|