[FIX] The auto translate toggle don't save right state (#2142)

Signed-off-by: Ezequiel De Oliveira <ezequiel1de1oliveira@gmail.com>

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Ezequiel de Oliveira 2020-06-17 16:22:22 -03:00 committed by GitHub
parent 8da50c2d73
commit 5e488972de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -57,6 +57,10 @@ export const merge = (subscription, room) => {
subscription.name = subscription.fname;
}
if (!subscription.autoTranslate) {
subscription.autoTranslate = false;
}
subscription.blocker = !!subscription.blocker;
subscription.blocked = !!subscription.blocked;
return subscription;

View File

@ -59,6 +59,7 @@ class AutoTranslateView extends React.Component {
constructor(props) {
super(props);
this.mounted = false;
this.rid = props.route.params?.rid;
const room = props.route.params?.room;
@ -66,7 +67,15 @@ class AutoTranslateView extends React.Component {
this.roomObservable = room.observe();
this.subscription = this.roomObservable
.subscribe((changes) => {
this.room = changes;
if (this.mounted) {
const { selectedLanguage, enableAutoTranslate } = this.state;
if (selectedLanguage !== changes.autoTranslateLanguage) {
this.setState({ selectedLanguage: changes.autoTranslateLanguage });
}
if (enableAutoTranslate !== changes.autoTranslate) {
this.setState({ enableAutoTranslate: changes.autoTranslate });
}
}
});
}
this.state = {
@ -77,6 +86,7 @@ class AutoTranslateView extends React.Component {
}
async componentDidMount() {
this.mounted = true;
try {
const languages = await RocketChat.getSupportedLanguagesAutoTranslate();
this.setState({ languages });