An ATproto social media client -- with an independent Appview.

clean up language before suggesting (#9006)

authored by samuel.fm and committed by

GitHub bbc55eb0 3e2c181c

+11 -1
+11 -1
src/view/com/composer/select-language/SuggestedLanguage.tsx
··· 1 1 import {useEffect, useState} from 'react' 2 2 import {View} from 'react-native' 3 + import {parseLanguage} from '@atproto/api' 3 4 import {msg, Trans} from '@lingui/macro' 4 5 import {useLingui} from '@lingui/react' 5 6 import lande from 'lande' ··· 21 22 22 23 export function SuggestedLanguage({ 23 24 text, 24 - replyToLanguage, 25 + replyToLanguage: replyToLanguageProp, 25 26 }: { 26 27 text: string 27 28 replyToLanguage?: string 28 29 }) { 30 + const replyToLanguage = cleanUpLanguage(replyToLanguageProp) 29 31 const [suggestedLanguage, setSuggestedLanguage] = useState< 30 32 string | undefined 31 33 >(text.length === 0 ? replyToLanguage : undefined) ··· 125 127 } 126 128 return code3ToCode2Strict(lang) 127 129 } 130 + 131 + function cleanUpLanguage(text: string | undefined): string | undefined { 132 + if (!text) { 133 + return undefined 134 + } 135 + 136 + return parseLanguage(text)?.language 137 + }