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

View File

@ -1,48 +1,82 @@
import React from 'react'; import React, { useEffect, useState } from 'react';
import { Switch } from 'react-native';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { useSelector } from 'react-redux';
import I18n from '../../i18n'; import I18n from '../../i18n';
import { import log, {
logEvent, events logEvent, events
} from '../../utils/log'; } from '../../utils/log';
import SafeAreaView from '../../containers/SafeAreaView'; import SafeAreaView from '../../containers/SafeAreaView';
import StatusBar from '../../containers/StatusBar'; import StatusBar from '../../containers/StatusBar';
import * as List from '../../containers/List'; 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 = () => ({
title: I18n.t('Preferences')
});
static propTypes = { const UserPreferencesView = ({ navigation }) => {
navigation: PropTypes.object const user = useSelector(state => getUserSelector(state));
} const [enableParser, setEnableParser] = useState(user.enableMessageParserEarlyAdoption);
navigateToScreen = (screen, params) => { useEffect(() => {
navigation.setOptions({
title: I18n.t('Preferences')
});
}, []);
const navigateToScreen = (screen, params) => {
logEvent(events[`SE_GO_${ screen.replace('View', '').toUpperCase() }`]); logEvent(events[`SE_GO_${ screen.replace('View', '').toUpperCase() }`]);
const { navigation } = this.props;
navigation.navigate(screen, params); navigation.navigate(screen, params);
} };
render() { const toggleMessageParser = async(value) => {
return ( try {
<SafeAreaView testID='preferences-view'> await RocketChat.saveUserPreferences({ id: user.id, enableMessageParserEarlyAdoption: value });
<StatusBar /> setEnableParser(value);
<List.Container> } catch (e) {
<List.Section> log(e);
<List.Separator /> }
<List.Item };
title='Notifications'
onPress={() => this.navigateToScreen('UserNotificationPrefView')} const renderMessageParserSwitch = () => (
showActionIndicator <Switch
testID='preferences-view-notifications' value={enableParser}
/> trackColor={SWITCH_TRACK_COLOR}
<List.Separator /> onValueChange={toggleMessageParser}
</List.Section> />
</List.Container> );
</SafeAreaView>
); return (
} <SafeAreaView testID='preferences-view'>
} <StatusBar />
<List.Container>
<List.Section>
<List.Separator />
<List.Item
title='Notifications'
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; export default UserPreferencesView;

View File

@ -1,13 +1,7 @@
// import 'react-native-gesture-handler'; import 'react-native-gesture-handler';
// import 'react-native-console-time-polyfill'; import 'react-native-console-time-polyfill';
// import { AppRegistry } from 'react-native'; import { AppRegistry } from 'react-native';
// import { name as appName, share as shareName } from './app.json'; 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';
if (__DEV__) { if (__DEV__) {
require('./app/ReactotronConfig'); require('./app/ReactotronConfig');
@ -22,3 +16,9 @@ if (__DEV__) {
console.error = () => {}; console.error = () => {};
console.info = () => {}; 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';