Minor tweaks

This commit is contained in:
Gerzon Z 2021-08-21 03:01:14 -04:00
parent d4c3322c32
commit 06b3da0b7a
3 changed files with 81 additions and 76 deletions

View File

@ -1,8 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import {
View, ScrollView, Keyboard, Switch
} from 'react-native';
import { View, ScrollView, Keyboard } from 'react-native';
import { connect } from 'react-redux';
import prompt from 'react-native-prompt-android';
import SHA256 from 'js-sha256';
@ -21,7 +19,6 @@ import { LISTENER } from '../../containers/Toast';
import EventEmitter from '../../utils/events';
import RocketChat from '../../lib/rocketchat';
import RCTextInput from '../../containers/TextInput';
import * as List from '../../containers/List';
import log, { logEvent, events } from '../../utils/log';
import I18n from '../../i18n';
import Button from '../../containers/Button';
@ -30,7 +27,7 @@ import { setUser as setUserAction } from '../../actions/login';
import { CustomIcon } from '../../lib/Icons';
import * as HeaderButton from '../../containers/HeaderButton';
import StatusBar from '../../containers/StatusBar';
import { SWITCH_TRACK_COLOR, themes } from '../../constants/colors';
import { themes } from '../../constants/colors';
import { withTheme } from '../../theme';
import { getUserSelector } from '../../selectors/login';
import SafeAreaView from '../../containers/SafeAreaView';
@ -64,7 +61,6 @@ class ProfileView extends React.Component {
state = {
saving: false,
enableMessageParser: false,
name: null,
username: null,
email: null,
@ -113,7 +109,7 @@ class ProfileView extends React.Component {
init = (user) => {
const { user: userProps } = this.props;
const {
name, username, emails, customFields, enableMessageParserEarlyAdoption
name, username, emails, customFields
} = user || userProps;
this.setState({
@ -124,14 +120,13 @@ class ProfileView extends React.Component {
currentPassword: null,
avatarUrl: null,
avatar: {},
customFields: customFields || {},
enableMessageParser: enableMessageParserEarlyAdoption || false
customFields: customFields || {}
});
}
formIsChanged = () => {
const {
name, username, email, newPassword, avatar, customFields, enableMessageParser
name, username, email, newPassword, avatar, customFields
} = this.state;
const { user } = this.props;
let customFieldsChanged = false;
@ -147,7 +142,6 @@ class ProfileView extends React.Component {
return !(user.name === name
&& user.username === username
&& user.enableMessageParserEarlyAdoption === enableMessageParser
&& !newPassword
&& (user.emails && user.emails[0].address === email)
&& !avatar.data
@ -429,22 +423,6 @@ class ProfileView extends React.Component {
}
}
renderMessageParserSwitch = () => {
const { enableMessageParser } = this.state;
return (
<Switch
value={enableMessageParser}
trackColor={SWITCH_TRACK_COLOR}
onValueChange={this.toggleEnableMessageParser}
/>
);
}
toggleEnableMessageParser = (value) => {
// logEvent(events.RI_EDIT_TOGGLE_SYSTEM_MSG);
this.setState({ enableMessageParser: value });
}
logoutOtherLocations = () => {
logEvent(events.PL_OTHER_LOCATIONS);
showConfirmationAlert({
@ -560,13 +538,6 @@ class ProfileView extends React.Component {
testID='profile-view-new-password'
theme={theme}
/>
<List.Separator />
<List.Item
title='Enable_Message_Parser'
testID='profile-view-enable-message-parser'
right={() => this.renderMessageParserSwitch()}
/>
<List.Separator />
{this.renderCustomFields()}
<RCTextInput
editable={Accounts_AllowUserAvatarChange}

View File

@ -1,30 +1,52 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import { Switch } from 'react-native';
import PropTypes from 'prop-types';
import { useSelector } from 'react-redux';
import I18n from '../../i18n';
import {
import log, {
logEvent, events
} from '../../utils/log';
import SafeAreaView from '../../containers/SafeAreaView';
import StatusBar from '../../containers/StatusBar';
import * as List from '../../containers/List';
import { SWITCH_TRACK_COLOR } from '../../constants/colors';
import { getUserSelector } from '../../selectors/login';
import RocketChat from '../../lib/rocketchat';
class UserPreferencesView extends React.Component {
static navigationOptions = () => ({
const UserPreferencesView = ({ navigation }) => {
const user = useSelector(state => getUserSelector(state));
const [enableParser, setEnableParser] = useState(user.enableMessageParserEarlyAdoption);
useEffect(() => {
navigation.setOptions({
title: I18n.t('Preferences')
});
}, []);
static propTypes = {
navigation: PropTypes.object
}
navigateToScreen = (screen, params) => {
const navigateToScreen = (screen, params) => {
logEvent(events[`SE_GO_${ screen.replace('View', '').toUpperCase() }`]);
const { navigation } = this.props;
navigation.navigate(screen, params);
}
};
const toggleMessageParser = async(value) => {
try {
await RocketChat.saveUserPreferences({ id: user.id, enableMessageParserEarlyAdoption: value });
setEnableParser(value);
} catch (e) {
log(e);
}
};
const renderMessageParserSwitch = () => (
<Switch
value={enableParser}
trackColor={SWITCH_TRACK_COLOR}
onValueChange={toggleMessageParser}
/>
);
render() {
return (
<SafeAreaView testID='preferences-view'>
<StatusBar />
@ -33,16 +55,28 @@ class UserPreferencesView extends React.Component {
<List.Separator />
<List.Item
title='Notifications'
onPress={() => this.navigateToScreen('UserNotificationPrefView')}
onPress={() => navigateToScreen('UserNotificationPrefView')}
showActionIndicator
testID='preferences-view-notifications'
/>
<List.Separator />
</List.Section>
<List.Section>
<List.Separator />
<List.Item
title='Enable_Message_Parser'
testID='preferences-view-enable-message-parser'
right={() => renderMessageParserSwitch()}
/>
<List.Separator />
</List.Section>
</List.Container>
</SafeAreaView>
);
}
}
};
UserPreferencesView.propTypes = {
navigation: PropTypes.object
};
export default UserPreferencesView;

View File

@ -1,13 +1,7 @@
// import 'react-native-gesture-handler';
// import 'react-native-console-time-polyfill';
// import { AppRegistry } from 'react-native';
// import { name as appName, share as shareName } from './app.json';
// AppRegistry.registerComponent(appName, () => require('./app/index').default);
// AppRegistry.registerComponent(shareName, () => require('./app/share').default);
// For storybook, comment everything above and uncomment below
import './storybook';
import 'react-native-gesture-handler';
import 'react-native-console-time-polyfill';
import { AppRegistry } from 'react-native';
import { name as appName, share as shareName } from './app.json';
if (__DEV__) {
require('./app/ReactotronConfig');
@ -22,3 +16,9 @@ if (__DEV__) {
console.error = () => {};
console.info = () => {};
}
AppRegistry.registerComponent(appName, () => require('./app/index').default);
AppRegistry.registerComponent(shareName, () => require('./app/share').default);
// For storybook, comment everything above and uncomment below
// import './storybook';