Skip to content

Commit

Permalink
Revert "Merge pull request #1162 from tomivm/fix/download-Language"
Browse files Browse the repository at this point in the history
This reverts commit 36e9673.
  • Loading branch information
martinbedouret committed Mar 31, 2022
1 parent 36e9673 commit d637c0b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/components/Settings/Language/Language.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class Language extends React.Component {

const isDownloadable = avaliableAndDownloadablesLangs.filter(
downloadableLang => {
return downloadableLang.lang === lang;
return downloadableLang.langCode === lang.slice(0, 2);
}
)[0];

Expand Down
54 changes: 18 additions & 36 deletions src/components/Settings/Language/Language.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,18 @@ export class LanguageContainer extends Component {
firstClick
};
setDownloadingLang(downloadingLangState);
try {
await this.handleSetTtsEngine(ttsName); //after tts change it fires a remounting
} catch {
//if tts hasn't any voice SetTtsEngine throw an error and the user would be alerted that should open the tts app
this.setState({
downloadingLangError: {
ttsError: false,
langError: true
},
downloadLangLoading: false
});
}
};

onErrorDialogAcepted = () => {
Expand Down Expand Up @@ -403,7 +415,7 @@ export class LanguageContainer extends Component {

const {
setDownloadingLang,

localLangs,
ttsEngines,
ttsEngine,
history,
Expand All @@ -430,9 +442,9 @@ export class LanguageContainer extends Component {
langError: true
}
});
return;
}
}
const localLangs = this.props.localLangs;
if (!localLangs.includes(selectedLang)) {
this.setState({
downloadingLangError: {
Expand All @@ -446,14 +458,7 @@ export class LanguageContainer extends Component {
isdownloading: false
};
setDownloadingLang(downloadingLangState);
this.setState({
downloadingLangError: {
ttsError: false,
langError: false
},
selectedLang: selectedLang
});
this.refreshLanguageList();
this.setState({ selectedLang: selectedLang });
if (isDiferentTts) return;
await this.handleSubmit(selectedLang);
showNotification(
Expand All @@ -462,7 +467,9 @@ export class LanguageContainer extends Component {
history.push('/settings');
};

refreshLanguageList = () => {
componentDidMount = async () => {
const { isdownloading } = this.props.downloadingLang;

this.setState({
downloadablesLangs: isAndroid()
? this.prepareDownloadablesLenguages()
Expand All @@ -472,35 +479,11 @@ export class LanguageContainer extends Component {
downloadablesOnly: []
}
});
};

refreshDownloadLanguage = async () => {
const { isdownloading } = this.props.downloadingLang;

this.refreshLanguageList();

if (isdownloading) await this.lookDownloadingLang();
this.setState({ downloadLangLoading: false });
};

componentDidMount = async () => {
if (this.props.langsFetched) this.refreshDownloadLanguage();
};

componentDidUpdate = async prevProps => {
const isdownloading = this.props.downloadingLang?.isdownloading;
const langsFetched = this.props.langsFetched;

if (!prevProps.langsFetched && langsFetched) {
this.setState({ downloadLangLoading: true });
await this.refreshDownloadLanguage();
}
if (!isdownloading) return;
if (prevProps.downloadingLang.isdownloading === false) {
await this.refreshDownloadLanguage();
}
};

render() {
const { lang, langs, localLangs, ttsEngines, ttsEngine } = this.props;

Expand Down Expand Up @@ -556,7 +539,6 @@ export class LanguageContainer extends Component {

const mapStateToProps = state => ({
lang: state.language.lang,
langsFetched: state.language.langsFetched,
langs: state.language.langs,
localLangs: state.language.localLangs,
ttsEngines: state.speech.ttsEngines,
Expand Down
4 changes: 1 addition & 3 deletions src/providers/LanguageProvider/LanguageProvider.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const initialState = {
dir: 'ltr',
langs: [],
localLangs: [],
langsFetched: false,
downloadingLang: { isdownloading: false }
};

Expand Down Expand Up @@ -45,8 +44,7 @@ function languageProviderReducer(state = initialState, action) {
return {
...state,
langs: action.langs.sort(),
localLangs: action.localLangs || [],
langsFetched: true
localLangs: action.localLangs || []
};
case SET_DOWNLOADING_LANG:
return { ...state, downloadingLang: action.downloadingLangData };
Expand Down
15 changes: 4 additions & 11 deletions src/providers/SpeechProvider/SpeechProvider.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,19 @@ export function receiveTtsEngine(ttsEngineName) {
}

export function getTtsEngines() {
const ttsEngines = tts?.getTtsEngines();
const ttsEngines = tts.getTtsEngines();
return {
type: RECEIVE_TTS_ENGINES,
ttsEngines
};
}

export function setTtsEngine(selectedTtsEngineName) {
export function setTtsEngine(ttsEngineName) {
return async dispatch => {
dispatch(requestTtsEngine());
try {
const engineAvailable = tts
.getTtsEngines()
.map(tts => tts.name)
.includes(selectedTtsEngineName);
const engineName = engineAvailable
? selectedTtsEngineName
: tts.getTtsDefaultEngine().name;
const voices = await tts.setTtsEngine(engineName);
dispatch(receiveTtsEngine(engineName));
const voices = await tts.setTtsEngine(ttsEngineName);
dispatch(receiveTtsEngine(ttsEngineName));
if (!voices.length) {
throw new Error('TTS engine does not have a language.');
}
Expand Down
13 changes: 3 additions & 10 deletions src/reducers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { persistCombineReducers, persistReducer } from 'redux-persist';
import { persistCombineReducers } from 'redux-persist';

import appReducer from './components/App/App.reducer';
import languageProviderReducer from './providers/LanguageProvider/LanguageProvider.reducer';
Expand All @@ -11,20 +11,13 @@ import storage from 'redux-persist/lib/storage';

const config = {
key: 'root',
storage,
blacklist: ['language']
};

const languagePersistConfig = {
key: 'language',
storage: storage,
blacklist: ['langsFetched']
storage
};

export default function createReducer() {
return persistCombineReducers(config, {
app: appReducer,
language: persistReducer(languagePersistConfig, languageProviderReducer),
language: languageProviderReducer,
speech: speechProviderReducer,
board: boardReducer,
communicator: communicatorReducer,
Expand Down

0 comments on commit d637c0b

Please sign in to comment.