REF: Language settings to TSX

This commit is contained in:
Marcos Rodriguez Velez 2023-10-20 20:29:12 -04:00
parent 6c85265e6c
commit ddf155b996
No known key found for this signature in database
GPG Key ID: 6030B2F48CCE86D7

View File

@ -1,7 +1,6 @@
import React, { useState, useEffect, useContext } from 'react';
import { FlatList, StyleSheet } from 'react-native';
import { useNavigation, useTheme } from '@react-navigation/native';
import navigationStyle from '../../components/navigationStyle';
import { BlueListItem } from '../../BlueComponents';
import loc, { saveLanguage } from '../../loc';
@ -15,9 +14,9 @@ const styles = StyleSheet.create({
},
});
const Language = () => {
const Language: React.FC = () => {
const { setLanguage, language } = useContext(BlueStorageContext);
const [selectedLanguage, setSelectedLanguage] = useState(loc.getLanguage());
const [selectedLanguage, setSelectedLanguage] = useState<string>(loc.getLanguage());
const { setOptions } = useNavigation();
const { colors } = useTheme();
const stylesHook = StyleSheet.create({
@ -31,37 +30,31 @@ const Language = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [language]);
const renderItem = item => {
const renderItem = ({ item }: { item: { label: string; value: string; isRTL: boolean } }) => {
return (
<BlueListItem
// @ts-ignore: Fix later
onPress={() => {
const currentLanguage = AvailableLanguages.find(l => l.value === selectedLanguage);
saveLanguage(item.item.value).then(() => {
setSelectedLanguage(item.item.value);
saveLanguage(item.value).then(() => {
setSelectedLanguage(item.value);
setLanguage();
if (currentLanguage.isRTL || item.item.isRTL) {
if (currentLanguage && (currentLanguage.isRTL || item.isRTL)) {
alert(loc.settings.language_isRTL);
}
});
}}
title={item.item.label}
checkmark={selectedLanguage === item.item.value}
title={item.label}
checkmark={selectedLanguage === item.value}
/>
);
};
return (
<FlatList
style={[styles.flex, stylesHook.flex]}
keyExtractor={(_item, index) => `${index}`}
data={AvailableLanguages}
renderItem={renderItem}
initialNumToRender={25}
contentInsetAdjustmentBehavior="automatic"
/>
<View />
);
};
// @ts-ignore: Fix later
Language.navigationOptions = navigationStyle({}, opts => ({ ...opts, title: loc.settings.language }));
export default Language;