fix RadioButtonGroup's on change values

This commit is contained in:
Saturnino Abril 2018-07-10 15:50:06 +08:00
parent 3002ba2315
commit cd50ca72eb
4 changed files with 51 additions and 37 deletions

View file

@ -57,6 +57,7 @@ export default class NotificationSettingsMentionsBase extends PureComponent {
const newState = {
...notifyProps,
comments,
newReplyValue: comments,
usernameMention: usernameMentionIndex > -1,
mention_keys: mentionKeys.join(','),
showKeywordsModal: false,
@ -64,7 +65,6 @@ export default class NotificationSettingsMentionsBase extends PureComponent {
};
this.keywords = newState.mention_keys;
this.replyValue = comments;
return newState;
};

View file

@ -27,8 +27,10 @@ class NotificationSettingsMentionsAndroid extends NotificationSettingsMentionsBa
};
cancelReplyNotification = () => {
this.setState({showReplyModal: false});
this.replyValue = this.state.comments;
this.setState({
newReplyValue: this.state.comments,
showReplyModal: false,
});
};
onKeywordsChangeText = (value) => {
@ -36,7 +38,7 @@ class NotificationSettingsMentionsAndroid extends NotificationSettingsMentionsBa
};
onReplyChanged = (value) => {
this.replyValue = value;
this.setState({newReplyValue: value});
};
renderKeywordsModal(style) {
@ -113,6 +115,7 @@ class NotificationSettingsMentionsAndroid extends NotificationSettingsMentionsBa
renderReplyModal(style) {
const {intl} = this.props;
const {newReplyValue} = this.state;
const options = [{
label: intl.formatMessage({
@ -120,21 +123,21 @@ class NotificationSettingsMentionsAndroid extends NotificationSettingsMentionsBa
defaultMessage: 'Threads that I start or participate in',
}),
value: 'any',
checked: this.state.comments === 'any',
checked: newReplyValue === 'any',
}, {
label: intl.formatMessage({
id: 'mobile.account_notifications.threads_start',
defaultMessage: 'Threads that I start',
}),
value: 'root',
checked: this.state.comments === 'root',
checked: newReplyValue === 'root',
}, {
label: intl.formatMessage({
id: 'mobile.account_notifications.threads_mentions',
defaultMessage: 'Mentions in threads',
}),
value: 'never',
checked: this.state.comments === 'never',
checked: newReplyValue === 'never',
}];
return (
@ -243,7 +246,7 @@ class NotificationSettingsMentionsAndroid extends NotificationSettingsMentionsBa
saveReplyNotification = () => {
this.setState({showReplyModal: false});
this.setReplyNotifications(this.replyValue);
this.setReplyNotifications(this.state.newReplyValue);
};
showKeywordsModal = () => {

View file

@ -23,30 +23,37 @@ import NotificationSettingsMobileBase from './notification_settings_mobile_base'
class NotificationSettingsMobileAndroid extends NotificationSettingsMobileBase {
cancelMobilePushModal = () => {
this.setState({showMobilePushModal: false});
this.push = this.state.push;
this.setState({
newPush: this.state.push,
showMobilePushModal: false,
});
};
cancelMobilePushStatusModal = () => {
this.setState({showMobilePushStatusModal: false});
this.pushStatus = this.state.push_status;
this.setState({
newPushStatus: this.state.push_status,
showMobilePushStatusModal: false,
});
};
cancelMobileSoundsModal = () => {
this.setState({showMobileSoundsModal: false});
this.sound = this.state.selectedUri;
this.setState({
newSound: this.state.selectedUri,
showMobileSoundsModal: false,
});
};
onMobilePushChanged = (value) => {
this.push = value;
this.setState({newPush: value});
};
onMobilePushStatusChanged = (value) => {
this.pushStatus = value;
this.setState({newPushStatus: value});
};
onMobileSoundChanged = (value) => {
this.sound = value;
this.setState({newSound: value});
if (value && value !== 'none') {
NotificationPreferences.play(value);
}
@ -83,6 +90,7 @@ class NotificationSettingsMobileAndroid extends NotificationSettingsMobileBase {
renderMobilePushModal(style) {
const {config, intl} = this.props;
const pushNotificationsEnabled = config.SendPushNotifications === 'true';
const {newPush} = this.state;
const options = [{
label: intl.formatMessage({
@ -90,21 +98,21 @@ class NotificationSettingsMobileAndroid extends NotificationSettingsMobileBase {
defaultMessage: 'For all activity',
}),
value: 'all',
checked: this.state.push === 'all',
checked: newPush === 'all',
}, {
label: intl.formatMessage({
id: 'user.settings.notifications.onlyMentions',
defaultMessage: 'Only for mentions and direct messages',
}),
value: 'mention',
checked: this.state.push === 'mention',
checked: newPush === 'mention',
}, {
label: intl.formatMessage({
id: 'user.settings.notifications.never',
defaultMessage: 'Never',
}),
value: 'none',
checked: this.state.push === 'none',
checked: newPush === 'none',
}];
return (
@ -177,6 +185,7 @@ class NotificationSettingsMobileAndroid extends NotificationSettingsMobileBase {
renderMobilePushStatusModal(style) {
const {intl} = this.props;
const {newPushStatus} = this.state;
const options = [{
label: intl.formatMessage({
@ -184,21 +193,21 @@ class NotificationSettingsMobileAndroid extends NotificationSettingsMobileBase {
defaultMessage: 'Online, away or offline',
}),
value: 'online',
checked: this.state.push_status === 'online',
checked: newPushStatus === 'online',
}, {
label: intl.formatMessage({
id: 'user.settings.push_notification.away',
defaultMessage: 'Away or offline',
}),
value: 'away',
checked: this.state.push_status === 'away',
checked: newPushStatus === 'away',
}, {
label: intl.formatMessage({
id: 'user.settings.push_notification.offline',
defaultMessage: 'Offline',
}),
value: 'offline',
checked: this.state.push_status === 'offline',
checked: newPushStatus === 'offline',
}];
return (
@ -257,7 +266,7 @@ class NotificationSettingsMobileAndroid extends NotificationSettingsMobileBase {
}
renderMobileSoundsModal(style) {
const {defaultSound, selectedUri} = this.state;
const {defaultSound, newSound} = this.state;
const {intl, notificationPreferences} = this.props;
const {defaultUri, sounds} = notificationPreferences;
const soundsArray = [{
@ -266,14 +275,14 @@ class NotificationSettingsMobileAndroid extends NotificationSettingsMobileBase {
defaultMessage: 'Default ({sound})',
}, {sound: defaultSound}),
value: defaultUri,
checked: selectedUri === null,
checked: newSound === null,
}, {
label: intl.formatMessage({
id: 'mobile.notification_settings_mobile.no_sound',
defaultMessage: 'None',
}),
value: 'none',
checked: selectedUri === 'none',
checked: newSound === 'none',
}];
if (sounds && sounds.length) {
@ -281,7 +290,7 @@ class NotificationSettingsMobileAndroid extends NotificationSettingsMobileBase {
return {
label: s.name,
value: s.uri,
checked: s.uri === selectedUri,
checked: s.uri === newSound,
};
});
soundsArray.push(...filteredSounds);
@ -559,31 +568,31 @@ class NotificationSettingsMobileAndroid extends NotificationSettingsMobileBase {
saveMobilePushModal = () => {
this.setState({showMobilePushModal: false});
this.setMobilePush(this.push);
this.setMobilePush(this.state.newPush);
};
saveMobilePushStatusModal = () => {
this.setState({showMobilePushStatusModal: false});
this.setMobilePushStatus(this.pushStatus);
this.setMobilePushStatus(this.state.newPushStatus);
};
saveMobileSoundsModal = () => {
const {defaultSound} = this.state;
const {defaultSound, newSound} = this.state;
const {intl, notificationPreferences} = this.props;
const {defaultUri, sounds} = notificationPreferences;
let sound;
let selectedUri = null;
if (this.sound === defaultUri) {
if (newSound === defaultUri) {
sound = defaultSound;
} else if (this.sound === 'none') {
selectedUri = this.sound;
} else if (newSound === 'none') {
selectedUri = 'none';
sound = intl.formatMessage({
id: 'mobile.notification_settings_mobile.no_sound',
defaultMessage: 'None',
});
} else {
selectedUri = this.sound;
selectedUri = newSound;
const selected = sounds.find((s) => s.uri === selectedUri);
sound = selected ? selected.name : 'none';
}

View file

@ -25,16 +25,18 @@ export default class NotificationSettingsMobileBase extends PureComponent {
const {currentUser} = props;
const notifyProps = getNotificationProps(currentUser);
const notifyPreferences = this.getNotificationPreferences(props);
this.state = {
...notifyProps,
...this.getNotificationPreferences(props),
...notifyPreferences,
newPush: notifyProps.push,
newPushStatus: notifyProps.push_status,
newSound: notifyPreferences.sound,
showMobilePushModal: false,
showMobilePushStatusModal: false,
showMobileSoundsModal: false,
};
this.push = this.state.push;
this.pushStatus = this.state.push_status;
props.navigator.setOnNavigatorEvent(this.onNavigatorEvent);
}