mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at samuel/fancy-queue 73 lines 2.3 kB view raw
1import React from 'react' 2import {View} from 'react-native' 3import RNPickerSelect, {PickerSelectProps} from 'react-native-picker-select' 4import {useQueryClient} from '@tanstack/react-query' 5 6import {sanitizeAppLanguageSetting} from '#/locale/helpers' 7import {APP_LANGUAGES} from '#/locale/languages' 8import {useLanguagePrefs, useLanguagePrefsApi} from '#/state/preferences' 9import {resetPostsFeedQueries} from '#/state/queries/post-feed' 10import {atoms as a, useTheme, ViewStyleProp} from '#/alf' 11import {ChevronBottom_Stroke2_Corner0_Rounded as ChevronDown} from '#/components/icons/Chevron' 12 13export function AppLanguageDropdown(_props: ViewStyleProp) { 14 const t = useTheme() 15 16 const queryClient = useQueryClient() 17 const langPrefs = useLanguagePrefs() 18 const setLangPrefs = useLanguagePrefsApi() 19 const sanitizedLang = sanitizeAppLanguageSetting(langPrefs.appLanguage) 20 21 const onChangeAppLanguage = React.useCallback( 22 (value: Parameters<PickerSelectProps['onValueChange']>[0]) => { 23 if (!value) return 24 if (sanitizedLang !== value) { 25 setLangPrefs.setAppLanguage(sanitizeAppLanguageSetting(value)) 26 } 27 28 // reset feeds to refetch content 29 resetPostsFeedQueries(queryClient) 30 }, 31 [sanitizedLang, setLangPrefs, queryClient], 32 ) 33 34 return ( 35 <View style={a.relative}> 36 <RNPickerSelect 37 placeholder={{}} 38 value={sanitizedLang} 39 onValueChange={onChangeAppLanguage} 40 items={APP_LANGUAGES.filter(l => Boolean(l.code2)).map(l => ({ 41 label: l.name, 42 value: l.code2, 43 key: l.code2, 44 }))} 45 useNativeAndroidPickerStyle={false} 46 style={{ 47 inputAndroid: { 48 color: t.atoms.text_contrast_medium.color, 49 fontSize: 16, 50 paddingRight: 12 + 4, 51 }, 52 inputIOS: { 53 color: t.atoms.text.color, 54 fontSize: 16, 55 paddingRight: 12 + 4, 56 }, 57 }} 58 /> 59 60 <View 61 style={[ 62 a.absolute, 63 a.inset_0, 64 {left: 'auto'}, 65 {pointerEvents: 'none'}, 66 a.align_center, 67 a.justify_center, 68 ]}> 69 <ChevronDown fill={t.atoms.text.color} size="xs" /> 70 </View> 71 </View> 72 ) 73}