2018-06-05 01:17:02 +00:00
|
|
|
import React from 'react';
|
2019-05-21 12:12:15 +00:00
|
|
|
import {
|
2019-06-11 14:01:40 +00:00
|
|
|
View, Linking, ScrollView, AsyncStorage, SafeAreaView, Switch
|
2019-05-21 12:12:15 +00:00
|
|
|
} from 'react-native';
|
2019-06-11 14:01:40 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2018-06-13 01:33:00 +00:00
|
|
|
import { connect } from 'react-redux';
|
2018-06-05 01:17:02 +00:00
|
|
|
|
2019-05-21 12:12:15 +00:00
|
|
|
import { toggleMarkdown as toggleMarkdownAction } from '../../actions/markdown';
|
2019-06-11 14:01:40 +00:00
|
|
|
import { COLOR_DANGER, COLOR_SUCCESS } from '../../constants/colors';
|
2019-03-12 16:23:06 +00:00
|
|
|
import { DrawerButton } from '../../containers/HeaderButton';
|
|
|
|
import StatusBar from '../../containers/StatusBar';
|
2019-06-11 14:01:40 +00:00
|
|
|
import ListItem from '../../containers/ListItem';
|
|
|
|
import { DisclosureImage } from '../../containers/DisclosureIndicator';
|
|
|
|
import Separator from '../../containers/Separator';
|
|
|
|
import I18n from '../../i18n';
|
|
|
|
import { MARKDOWN_KEY } from '../../lib/rocketchat';
|
|
|
|
import { getReadableVersion, getDeviceModel, isAndroid } from '../../utils/deviceInfo';
|
|
|
|
import openLink from '../../utils/openLink';
|
|
|
|
import scrollPersistTaps from '../../utils/scrollPersistTaps';
|
|
|
|
import { showErrorAlert } from '../../utils/info';
|
|
|
|
import styles from './styles';
|
|
|
|
import sharedStyles from '../Styles';
|
2019-05-21 12:12:15 +00:00
|
|
|
|
2019-06-11 14:01:40 +00:00
|
|
|
const LICENSE_LINK = 'https://github.com/RocketChat/Rocket.Chat.ReactNative/blob/develop/LICENSE';
|
|
|
|
const SectionSeparator = React.memo(() => <View style={styles.sectionSeparatorBorder} />);
|
|
|
|
const SWITCH_TRACK_COLOR = {
|
|
|
|
false: isAndroid ? COLOR_DANGER : null,
|
|
|
|
true: COLOR_SUCCESS
|
|
|
|
};
|
2018-06-05 01:17:02 +00:00
|
|
|
|
2018-06-13 01:33:00 +00:00
|
|
|
@connect(state => ({
|
2019-06-11 14:01:40 +00:00
|
|
|
server: state.server,
|
2019-05-21 12:12:15 +00:00
|
|
|
useMarkdown: state.markdown.useMarkdown
|
2018-06-13 01:33:00 +00:00
|
|
|
}), dispatch => ({
|
2019-05-21 12:12:15 +00:00
|
|
|
toggleMarkdown: params => dispatch(toggleMarkdownAction(params))
|
2018-06-13 01:33:00 +00:00
|
|
|
}))
|
2019-05-28 13:03:08 +00:00
|
|
|
export default class SettingsView extends React.Component {
|
2019-03-12 16:23:06 +00:00
|
|
|
static navigationOptions = ({ navigation }) => ({
|
|
|
|
headerLeft: <DrawerButton navigation={navigation} />,
|
|
|
|
title: I18n.t('Settings')
|
2019-06-11 14:01:40 +00:00
|
|
|
});
|
2018-10-23 21:39:48 +00:00
|
|
|
|
2018-06-13 01:33:00 +00:00
|
|
|
static propTypes = {
|
2019-06-11 14:01:40 +00:00
|
|
|
navigation: PropTypes.object,
|
|
|
|
server: PropTypes.object,
|
2019-05-21 12:12:15 +00:00
|
|
|
useMarkdown: PropTypes.bool,
|
|
|
|
toggleMarkdown: PropTypes.func
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
2018-06-13 01:33:00 +00:00
|
|
|
|
2019-06-11 14:01:40 +00:00
|
|
|
toggleMarkdown = (value) => {
|
|
|
|
AsyncStorage.setItem(MARKDOWN_KEY, JSON.stringify(value));
|
|
|
|
const { toggleMarkdown } = this.props;
|
|
|
|
toggleMarkdown(value);
|
2018-08-01 19:35:06 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:01:40 +00:00
|
|
|
navigateToRoom = (room) => {
|
|
|
|
const { navigation } = this.props;
|
|
|
|
navigation.navigate(room);
|
2018-06-13 01:33:00 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:01:40 +00:00
|
|
|
sendEmail = async() => {
|
|
|
|
const subject = encodeURI('React Native App Support');
|
|
|
|
const email = encodeURI('support@rocket.chat');
|
|
|
|
const description = encodeURI(`
|
|
|
|
version: ${ getReadableVersion }
|
|
|
|
device: ${ getDeviceModel }
|
|
|
|
`);
|
2018-06-13 01:33:00 +00:00
|
|
|
try {
|
2019-06-11 14:01:40 +00:00
|
|
|
await Linking.openURL(`mailto:${ email }?subject=${ subject }&body=${ description }`);
|
2018-06-13 01:33:00 +00:00
|
|
|
} catch (e) {
|
2019-06-11 14:01:40 +00:00
|
|
|
showErrorAlert(I18n.t('error-email-send-failed', { message: 'support@rocket.chat' }));
|
2018-06-13 01:33:00 +00:00
|
|
|
}
|
2018-06-05 01:17:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:01:40 +00:00
|
|
|
onPressLicense = () => openLink(LICENSE_LINK)
|
|
|
|
|
|
|
|
renderDisclosure = () => <DisclosureImage />
|
|
|
|
|
|
|
|
renderMarkdownSwitch = () => {
|
|
|
|
const { useMarkdown } = this.props;
|
|
|
|
return (
|
|
|
|
<Switch
|
|
|
|
value={useMarkdown}
|
|
|
|
trackColor={SWITCH_TRACK_COLOR}
|
|
|
|
onValueChange={this.toggleMarkdown}
|
|
|
|
/>
|
|
|
|
);
|
2019-05-21 12:12:15 +00:00
|
|
|
}
|
|
|
|
|
2018-06-05 01:17:02 +00:00
|
|
|
render() {
|
2019-06-11 14:01:40 +00:00
|
|
|
const { server } = this.props;
|
2018-06-05 01:17:02 +00:00
|
|
|
return (
|
2019-06-11 14:01:40 +00:00
|
|
|
<SafeAreaView style={sharedStyles.listSafeArea} testID='settings-view'>
|
2019-03-12 16:23:06 +00:00
|
|
|
<StatusBar />
|
2018-06-13 01:33:00 +00:00
|
|
|
<ScrollView
|
|
|
|
{...scrollPersistTaps}
|
2019-06-11 14:01:40 +00:00
|
|
|
contentContainerStyle={sharedStyles.listContentContainer}
|
|
|
|
showsVerticalScrollIndicator={false}
|
|
|
|
testID='settings-view-list'
|
2018-06-13 01:33:00 +00:00
|
|
|
>
|
2019-06-11 14:01:40 +00:00
|
|
|
<ListItem
|
|
|
|
title={I18n.t('Contact_us')}
|
|
|
|
onPress={this.sendEmail}
|
|
|
|
showActionIndicator
|
|
|
|
testID='settings-view-contact'
|
|
|
|
right={this.renderDisclosure}
|
|
|
|
/>
|
|
|
|
<Separator />
|
|
|
|
<ListItem
|
|
|
|
title={I18n.t('Language')}
|
|
|
|
onPress={() => this.navigateToRoom('LanguageView')}
|
|
|
|
showActionIndicator
|
|
|
|
testID='settings-view-language'
|
|
|
|
right={this.renderDisclosure}
|
|
|
|
/>
|
|
|
|
<Separator />
|
|
|
|
<ListItem
|
|
|
|
title={I18n.t('Theme')}
|
|
|
|
showActionIndicator
|
|
|
|
disabled
|
|
|
|
testID='settings-view-theme'
|
|
|
|
/>
|
|
|
|
<Separator />
|
|
|
|
<ListItem
|
|
|
|
title={I18n.t('Share_this_app')}
|
|
|
|
showActionIndicator
|
|
|
|
disabled
|
|
|
|
testID='settings-view-share-app'
|
|
|
|
/>
|
|
|
|
|
|
|
|
<SectionSeparator />
|
|
|
|
|
|
|
|
<ListItem
|
|
|
|
title={I18n.t('License')}
|
|
|
|
onPress={this.onPressLicense}
|
|
|
|
showActionIndicator
|
|
|
|
testID='settings-view-license'
|
|
|
|
right={this.renderDisclosure}
|
|
|
|
/>
|
|
|
|
<Separator />
|
|
|
|
<ListItem title={I18n.t('Version_no', { version: getReadableVersion })} testID='settings-view-version' />
|
|
|
|
<Separator />
|
|
|
|
<ListItem
|
|
|
|
title={I18n.t('Server_version', { version: server.version })}
|
|
|
|
subtitle={`${ server.server.split('//')[1] }`}
|
|
|
|
testID='settings-view-server-version'
|
|
|
|
/>
|
|
|
|
|
|
|
|
<SectionSeparator />
|
|
|
|
|
|
|
|
<ListItem
|
|
|
|
title={I18n.t('Enable_markdown')}
|
|
|
|
testID='settings-view-markdown'
|
|
|
|
right={() => this.renderMarkdownSwitch()}
|
|
|
|
/>
|
2018-06-13 01:33:00 +00:00
|
|
|
</ScrollView>
|
2019-06-11 14:01:40 +00:00
|
|
|
</SafeAreaView>
|
2018-06-05 01:17:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|