[APP-735] Post language improvements (#982)

* Fix composer character-counter bouncing around UI elements

* Fix composer toolbar padding when keyboard is dismissed on iOS

* Use the full name of the language in the composer footer

* Add headings to the DropdownButton

* Update the composer language control to use a simpler dropdown

* Fix lint

* Add translate link to Post component used in notifications

* Fix lint
This commit is contained in:
Paul Frazee 2023-07-06 20:28:10 -05:00 committed by GitHub
parent f05c2f06d6
commit e14c9783e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 189 additions and 28 deletions

View file

@ -1,4 +1,4 @@
import React, {useEffect, useState} from 'react'
import React, {useEffect, useState, useMemo} from 'react'
import {
ActivityIndicator,
Linking,
@ -29,7 +29,7 @@ import {UserAvatar} from '../util/UserAvatar'
import {useStores} from 'state/index'
import {s, colors} from 'lib/styles'
import {usePalette} from 'lib/hooks/usePalette'
import {getTranslatorLink} from '../../../locale/helpers'
import {getTranslatorLink, isPostInLanguage} from '../../../locale/helpers'
export const Post = observer(function Post({
uri,
@ -134,6 +134,16 @@ const PostLoaded = observer(
const urip = new AtUri(record.reply.parent?.uri || record.reply.root.uri)
replyAuthorDid = urip.hostname
}
const primaryLanguage = store.preferences.contentLanguages[0] || 'en'
const translatorUrl = getTranslatorLink(primaryLanguage, record?.text || '')
const needsTranslation = useMemo(
() =>
store.preferences.contentLanguages.length > 0 &&
!isPostInLanguage(item.post, store.preferences.contentLanguages),
[item.post, store.preferences.contentLanguages],
)
const onPressReply = React.useCallback(() => {
store.shell.openComposer({
replyTo: {
@ -166,9 +176,6 @@ const PostLoaded = observer(
Toast.show('Copied to clipboard')
}, [record])
const primaryLanguage = store.preferences.contentLanguages[0] || 'en'
const translatorUrl = getTranslatorLink(primaryLanguage, record?.text || '')
const onOpenTranslate = React.useCallback(() => {
Linking.openURL(translatorUrl)
}, [translatorUrl])
@ -263,6 +270,15 @@ const PostLoaded = observer(
<ImageHider moderation={item.moderation.list} style={s.mb10}>
<PostEmbeds embed={item.post.embed} style={s.mb10} />
</ImageHider>
{needsTranslation && (
<View style={[pal.borderDark, styles.translateLink]}>
<Link href={translatorUrl} title="Translate">
<Text type="sm" style={pal.link}>
Translate this post
</Text>
</Link>
</View>
)}
</ContentHider>
<PostCtrls
itemUri={itemUri}
@ -320,6 +336,9 @@ const styles = StyleSheet.create({
flexWrap: 'wrap',
paddingBottom: 8,
},
translateLink: {
marginBottom: 12,
},
replyLine: {
position: 'absolute',
left: 36,